Skip to content

Conversation

@oguzkocer
Copy link
Contributor

@oguzkocer oguzkocer commented Nov 28, 2025

Summary

Migrate remaining HttpURLConnection usages to OkHttp for consistency with the rest of the codebase. Using the shared OkHttpClient provides unified configuration, better connection pooling, and consistent timeout/auth handling.

Changes

  • VideoLoader: Use OkHttp HEAD request to fetch video Content-Length header
  • TempAttachmentsUtil: Use OkHttp for downloading video attachments in support tickets
  • WPWebViewClient: Use OkHttp for intercepting private site image requests in WebViews
  • ReaderWebView: Use OkHttp for intercepting private post image requests in Reader

Test Instructions

  • Private site images: View a post with images on a private site in Reader - images should load correctly
  • Post preview: Preview a post with images on a private site - images should load correctly
  • Support video attachment: Contact Support → attach a video → submit ticket - video should attach successfully
  • Media library thumbnails: My Site → More → Media - verify video thumbnails display correctly (requires at least one video < 10MB)

Replace direct HttpURLConnection usage with the shared OkHttpClient for
better connection pooling and consistency with the rest of the codebase.

Changes:
- Inject `@Named("regular") OkHttpClient` via Dagger
- Use HEAD request instead of GET for efficiency (only need Content-Length)
- Simplify content length retrieval using OkHttp's response API
Replace direct HttpURLConnection usage with the shared OkHttpClient for
video downloads in support ticket attachments.

Changes:
- Inject `@Named("regular") OkHttpClient` via Dagger
- Use `okHttpClient.newBuilder()` to configure custom timeouts
- Stream response body to temp file using OkHttp's byteStream API
- Simplify cleanup by relying on OkHttp's response.use {} auto-close
Replace direct HttpURLConnection usage with the shared OkHttpClient for
intercepting private site image requests in WebViews.

Changes:
- Inject `@Named("regular") OkHttpClient` via Dagger field injection
- Use synchronous `execute()` as required by `shouldInterceptRequest`
- Configure timeouts via `newBuilder()` to preserve existing behavior
- Pass response body stream directly to WebResourceResponse
Replace direct HttpURLConnection usage with the shared OkHttpClient for
intercepting private post image requests in Reader WebViews.

Changes:
- Inject `@Named("regular") OkHttpClient` in ReaderWebView
- Pass OkHttpClient to inner ReaderWebViewClient class
- Use synchronous `execute()` as required by `shouldInterceptRequest`
- Preserve User-Agent and Connection headers from original implementation
@oguzkocer oguzkocer added this to the 26.5 milestone Nov 28, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Nov 28, 2025

1 Warning
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.

Generated by 🚫 Danger

@sonarqubecloud
Copy link

@wpmobilebot
Copy link
Contributor

App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
FlavorJalapeno
Build TypeDebug
Versionpr22375-3749bba
Commit3749bba
Direct Downloadwordpress-prototype-build-pr22375-3749bba.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
FlavorJalapeno
Build TypeDebug
Versionpr22375-3749bba
Commit3749bba
Direct Downloadjetpack-prototype-build-pr22375-3749bba.apk
Note: Google Login is not supported on these builds.

@codecov
Copy link

codecov bot commented Nov 28, 2025

Codecov Report

❌ Patch coverage is 0% with 48 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.02%. Comparing base (06a7f4e) to head (3749bba).
⚠️ Report is 3 commits behind head on trunk.

Files with missing lines Patch % Lines
...ess/android/support/he/util/TempAttachmentsUtil.kt 0.00% 26 Missing ⚠️
...va/org/wordpress/android/util/WPWebViewClient.java 0.00% 14 Missing ⚠️
...java/org/wordpress/android/ui/media/VideoLoader.kt 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #22375      +/-   ##
==========================================
- Coverage   39.02%   39.02%   -0.01%     
==========================================
  Files        2203     2203              
  Lines      106342   106351       +9     
  Branches    15061    15061              
==========================================
  Hits        41501    41501              
- Misses      61350    61359       +9     
  Partials     3491     3491              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@oguzkocer oguzkocer marked this pull request as ready for review November 28, 2025 21:50
@oguzkocer oguzkocer enabled auto-merge (squash) November 28, 2025 21:50

class TempAttachmentsUtil @Inject constructor(
@Named(IO_THREAD) private val ioDispatcher: CoroutineDispatcher,
@Named("regular") private val okHttpClient: OkHttpClient,
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Can we use a constant here? There are 4 instances of "regular" in the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've looked at the same thing while reviewing the changes and found that this is extensively used across the code base. So, introducing a constant would need to be done in a separate PR - or we'd either introduce inconsistency or change too many irrelevant files.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in #22379

Copy link
Contributor

@adalpari adalpari left a comment

Choose a reason for hiding this comment

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

LGTM and works as expected!
Just left a minor comment

@oguzkocer oguzkocer merged commit 8ffd5e0 into trunk Dec 1, 2025
29 of 30 checks passed
@oguzkocer oguzkocer deleted the refactor/migrate-httpurlconnection-to-okhttp branch December 1, 2025 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants