Display a user-friendly error when connecting to a site that doesn't support HTTPS#1204
Draft
Display a user-friendly error when connecting to a site that doesn't support HTTPS#1204
Conversation
…support HTTPS Adds `HttpsNotSupportedError` to `RequestExecutionErrorReason` across all three platforms (Rust, Swift, Kotlin) to distinguish "server doesn't support HTTPS" from generic connection errors. Detection covers two scenarios: - Server accepts TCP but responds with plain HTTP to a TLS handshake - HTTPS port is closed but the site is reachable via HTTP (probed with HEAD) Rust: Detects `InvalidContentType` TLS error from rustls, and probes HTTP on connect errors. Includes unit tests for TLS error classification. Swift: Detects `secureConnectionFailed` with no peer certificates, and probes HTTP on `cannotConnectToHost`. Fixes HTTPStubs to pass through `RequestExecutionError` values. Kotlin: Catches `SSLException` (including when wrapped in `ConnectException`) and probes HTTP on connection refused. Includes MockWebServer integration test. Closes #1192 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
a1fcf2c to
468cf01
Compare
Replace HttpURLConnection and HttpsURLConnection usage with OkHttpClient in the connectException(), sslException(), and invalidSSLError() helpers for consistency with the rest of the codebase. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
468cf01 to
cb49d85
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When a client tries to connect via HTTPS to a server that only speaks HTTP (e.g. a local WordPress dev environment at
http://localhost:8888), the TLS handshake fails. Previously this produced generic error messages. This PR detects the condition and returns a clearHttpsNotSupportedErroracross all three platforms.Closes #1192
Changes
wp_api/src/api_error.rs): AddedHttpsNotSupportedErrorvariant toRequestExecutionErrorReasonwp_api/src/reqwest_request_executor.rs): DetectInvalidMessage::InvalidContentTypeTLS error (server responded with HTTP to a TLS handshake). Added HTTP probe on connect errors — if HTTPS port is closed but the site responds on HTTP, returnHttpsNotSupportedErrorinstead of a generic connection errorwp_localization): Added user-facing message: "This site doesn't support a secure (HTTPS) connection..."SafeRequestExecutor.swift): DetectsecureConnectionFailedwith no peer certificates as HTTPS-not-supported. Added async HTTP probe forcannotConnectToHosterrors on HTTPS URLsWpRequestExecutor.kt): HandleSSLException(including when wrapped inConnectExceptionby OkHttp). Added HTTP probe using OkHttp for connect failures on HTTPS URLs. Migrated all SSL probe helpers fromjava.netto OkHttp for consistencyHTTPStubs.swift): Pass throughRequestExecutionErrorin test stubsWpRequestExecutorTest.kt): Added integration test using MockWebServer to verify HTTPS-to-HTTP detectionAll three platforms handle two scenarios identically:
HttpsNotSupportedErrorHttpsNotSupportedErrorTest plan
cargo fmt --all -- --checkpassescargo clippypassescargo test --libpasses (includes 4 new unit tests for TLS error mapping and HTTP probe)./gradlew :api:kotlin:integrationTestpasses (timeout test + HTTPS-not-supported test)https://no-https.wpmt.co:80HttpsNotSupportedError)🤖 Generated with Claude Code