Skip to content

Upgrade OkHttp from 4.12.0 to 5.4.0 - #2140

Draft
Ramses Sanchez-Hernandez (ramsessanchez) wants to merge 2 commits into
mainfrom
upgrade-okhttp5
Draft

Ramses Sanchez-Hernandez (ramsessanchez) wants to merge 2 commits into
mainfrom
upgrade-okhttp5

Conversation

@ramsessanchez

@ramsessanchez Ramses Sanchez-Hernandez (ramsessanchez) commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

fixes #1984

Overview

Upgrades the OkHttp dependency from 4.12.0 to 5.4.0 for the components/http/okHttp module.

Changes

  • gradle/libs.versions.toml — bump okhttp to 5.4.0. The shared version.ref covers okhttp, logging-interceptor, and mockwebserver. The legacy com.squareup.okhttp3:mockwebserver artifact still ships in 5.x, so no package/artifact rename is needed.
  • RedirectHandler.java — okhttp3.internal.http.StatusLine no longer exposes HTTP_PERM_REDIRECT / HTTP_TEMP_REDIRECT in OkHttp 5. Replaced the removed internal imports with local 308 / 307 constants. This is the only production-source break.
  • OkHttpRequestAdapterTest.java — OkHttp 5 makes Response.Builder.body non-null, so .body(null) now throws NullPointerException. Removed those calls. Because a built success response now always carries a non-null (empty) body, the stream no-content test was split:
    • sendStreamReturnsNullOnNoContent — 204/304 still return null (via shouldReturnNull).
    • sendStreamReturnsEmptyStreamOnEmptyBody — 200-203 with an empty body yield a non-null empty stream, matching real OkHttp network behavior.

Notes

  • No production behavior change. The old null-body path was only reachable via synthetic mocks; real network responses always carry a non-null body. Production code is unchanged apart from the redirect constants.
  • okhttp3.* core packages are unchanged (no rename to an okhttp package).

Testing

  • ./gradlew :components:http:okHttp:test — 108 tests pass.
  • ./gradlew :components:bundle:test — pass (bundles okHttp).
  • The single unrelated failure in serialization:json (writesSampleObjectValueWithUntypedProperties) is pre-existing on main and independent of this change.

- Bump okhttp version in gradle/libs.versions.toml (covers okhttp,
  logging-interceptor and mockwebserver via the shared version ref).
- RedirectHandler: replace removed okhttp3.internal.http.StatusLine
  constants (HTTP_PERM_REDIRECT/HTTP_TEMP_REDIRECT) with local 308/307
  constants, as that internal class is no longer exposed in OkHttp 5.
- OkHttpRequestAdapterTest: OkHttp 5 Response.Builder.body is non-null,
  so drop .body(null) calls. Split the stream no-content test: 204/304
  still return null; 200-203 with an empty body now yield a non-null
  empty stream (matching real OkHttp behavior, production code unchanged).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0b74528e-656e-4569-bb55-b833bbf51344
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicting changes, the author must resolve the conflicts before this pull request can be merged.

@github-actions

Copy link
Copy Markdown
Contributor

Conflicts have been resolved. A maintainer will take a look shortly.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicting changes, the author must resolve the conflicts before this pull request can be merged.

This branch has not been deployed

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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

upgrade to okhttp 5

1 participant