Skip to content

Conversation

@oguzkocer
Copy link
Contributor

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).

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
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.

4 participants