Skip to content

Display a user-friendly error when connecting to a site that doesn't support HTTPS#1204

Draft
jkmassel wants to merge 2 commits intotrunkfrom
jkmassel/fix-edit-context-fields
Draft

Display a user-friendly error when connecting to a site that doesn't support HTTPS#1204
jkmassel wants to merge 2 commits intotrunkfrom
jkmassel/fix-edit-context-fields

Conversation

@jkmassel
Copy link
Contributor

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 clear HttpsNotSupportedError across all three platforms.

Closes #1192

Changes

  • Rust (wp_api/src/api_error.rs): Added HttpsNotSupportedError variant to RequestExecutionErrorReason
  • Rust (wp_api/src/reqwest_request_executor.rs): Detect InvalidMessage::InvalidContentType TLS 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, return HttpsNotSupportedError instead of a generic connection error
  • Rust (wp_localization): Added user-facing message: "This site doesn't support a secure (HTTPS) connection..."
  • Swift (SafeRequestExecutor.swift): Detect secureConnectionFailed with no peer certificates as HTTPS-not-supported. Added async HTTP probe for cannotConnectToHost errors on HTTPS URLs
  • Kotlin (WpRequestExecutor.kt): Handle SSLException (including when wrapped in ConnectException by OkHttp). Added HTTP probe using OkHttp for connect failures on HTTPS URLs. Migrated all SSL probe helpers from java.net to OkHttp for consistency
  • Swift (HTTPStubs.swift): Pass through RequestExecutionError in test stubs
  • Kotlin (WpRequestExecutorTest.kt): Added integration test using MockWebServer to verify HTTPS-to-HTTP detection

All three platforms handle two scenarios identically:

  1. Server accepts TCP but responds with plain HTTP to a TLS handshake → HttpsNotSupportedError
  2. HTTPS port is closed, but site is reachable via HTTP (detected via HEAD probe) → HttpsNotSupportedError

Test plan

  • cargo fmt --all -- --check passes
  • cargo clippy passes
  • cargo test --lib passes (includes 4 new unit tests for TLS error mapping and HTTP probe)
  • Kotlin ./gradlew :api:kotlin:integrationTest passes (timeout test + HTTPS-not-supported test)
  • Swift compilation verified
  • Manually tested against a local HTTP-only server and https://no-https.wpmt.co:80
  • Verified no false positives: closed port with no HTTP available returns appropriate error (not HttpsNotSupportedError)

🤖 Generated with Claude Code

…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>
@jkmassel jkmassel force-pushed the jkmassel/fix-edit-context-fields branch from a1fcf2c to 468cf01 Compare February 27, 2026 19:00
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>
@jkmassel jkmassel force-pushed the jkmassel/fix-edit-context-fields branch from 468cf01 to cb49d85 Compare February 27, 2026 23:24
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.

Display a user-friendly error when connecting to a site that doesn't support HTTPS

1 participant