Skip to content

feat(gax): allow non-JSON HttpContent and absolute target URLs in HttpRequest Formatter and Runnable - #14085

Draft
whowes wants to merge 1 commit into
mainfrom
whowes/http-content-support
Draft

feat(gax): allow non-JSON HttpContent and absolute target URLs in HttpRequest Formatter and Runnable#14085
whowes wants to merge 1 commit into
mainfrom
whowes/http-content-support

Conversation

@whowes

@whowes whowes commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

GAX HTTP infrastructure currently assumes that

  • request content is always JSON
  • request URLs are always based on the client context associated with the service stub

This PR relaxes those assumptions to allow non-JSON content and arbitrary URLs, which will be needed for resumable upload support.

gemini-code-assist[bot]

This comment was marked as outdated.

@whowes
whowes force-pushed the whowes/http-content-support branch 3 times, most recently from 1215616 to 52795b5 Compare August 17, 2026 23:04
@whowes whowes added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 18, 2026
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 18, 2026
@whowes
whowes force-pushed the whowes/http-content-support branch 2 times, most recently from b84604b to 0554402 Compare August 18, 2026 22:52
@whowes whowes changed the title feat(gax): allow non-JSON HttpContent in HttpRequestFormatter and HttpRequestRunnable feat(gax): allow non-JSON HttpContent and absolute target URLs in HttpRequest Formatter and Runnable Aug 18, 2026
@whowes

whowes commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors HTTP request body handling by introducing a default getHttpContent method in HttpRequestFormatter and updating HttpRequestRunnable to use it, which simplifies request creation and adds support for non-JSON payloads and absolute URLs. Corresponding unit tests were also added. The review feedback suggests improving absolute URL detection robustness by using case-insensitive regionMatches and optimizing performance by reusing a shared, lazily initialized JsonObjectParser instead of instantiating one for every request.

GenericUrl url = new GenericUrl(normalizedEndpoint + requestFormatter.getPath(request));
String path = requestFormatter.getPath(request);
GenericUrl url;
if (path.startsWith("http://") || path.startsWith("https://")) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To make the absolute URL detection robust against uppercase schemes (e.g., HTTP:// or HTTPS://) without allocating new string objects, consider using regionMatches with case-insensitivity enabled.

Suggested change
if (path.startsWith("http://") || path.startsWith("https://")) {
if (path.regionMatches(true, 0, "http://", 0, 7) || path.regionMatches(true, 0, "https://", 0, 8)) {

}

httpRequest.setParser(new JsonObjectParser(jsonFactory));
httpRequest.setParser(new JsonObjectParser(GsonFactory.getDefaultInstance()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To avoid allocating a new JsonObjectParser instance on every HTTP request, consider using a lazily initialized instance. Since JsonObjectParser is thread-safe, sharing a single instance is safe and improves performance. Lazy initialization is preferred over eager initialization for resource-intensive objects to avoid unnecessary performance and memory overhead if they are not guaranteed to be used in all execution paths.

Suggested change
httpRequest.setParser(new JsonObjectParser(GsonFactory.getDefaultInstance()));
httpRequest.setParser(getJsonObjectParser());
References
  1. Prefer lazy initialization over eager initialization for resource-intensive objects (such as CharsetEncoder) if they are not guaranteed to be used in all execution paths, to avoid unnecessary performance and memory overhead.

@whowes
whowes force-pushed the whowes/http-content-support branch from 0554402 to d2308bd Compare August 18, 2026 23:39
@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed for 'gapic-generator-java-root'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants