Xuanwo opened a new pull request, #8962:
URL: https://github.com/apache/opendal/pull/8962

   # Which issue does this PR close?
   
   None.
   
   # Rationale for this change
   
   `opendal-service-http` had three configuration and error-handling bugs:
   
   1. `HttpBuilder::build()` accepted any non-empty `endpoint` string without 
validating that it is a valid `http://` or `https://` URI with a host (and 
without a query or fragment), and did not strip trailing `/` characters. When 
`endpoint` ended with `/` (such as `https://example.com/` or 
`https://example.com/prefix/`), `HttpCore` concatenated `self.endpoint` with 
the leading-slash path from `build_rooted_absolute_path`, producing 
double-slash URLs (`//...`) in `stat`, `read`, and `presign`.
   2. `parse_error` mapped `401 Unauthorized` to `ErrorKind::Unexpected` 
instead of permanent `ErrorKind::PermissionDenied`, and mapped `429 Too Many 
Requests` to `ErrorKind::Unexpected` instead of temporary 
`ErrorKind::RateLimited`.
   3. `HttpConfig::from_uri()` ignored `uri.username()` and `uri.password()`, 
so URIs like `https://user:[email protected]/static` silently constructed an 
unauthenticated operator and reported `presign` / `presign_read` / 
`presign_stat` as supported.
   
   # What changes are included in this PR?
   
   - Validate `endpoint` in `HttpBuilder::build()` as an `http` or `https` 
`http::Uri` with a non-empty host and no query or fragment, returning 
`ErrorKind::ConfigInvalid` otherwise, and normalize it by trimming trailing `/` 
characters.
   - Update `core/services/http/src/docs.md` so the `HttpBuilder` doc example 
uses a valid scheme-prefixed endpoint (`https://example.com`).
   - Map `StatusCode::UNAUTHORIZED` to permanent `ErrorKind::PermissionDenied` 
and `StatusCode::TOO_MANY_REQUESTS` to temporary `ErrorKind::RateLimited` in 
`core/services/http/src/core.rs`.
   - Extract `uri.username()` and `uri.password()` in `HttpConfig::from_uri()` 
without overriding explicit options or query parameters, ensuring Basic 
authentication is applied and `presign` capabilities are disabled when URI 
credentials are present.
   - Add deterministic unit tests (including mock `HttpTransport` tests) 
covering endpoint validation, trailing-slash normalization across 
`stat`/`read`/`presign`, `401`/`429` error mapping, and `Operator::from_uri` 
credential extraction, overrides, header injection, and `presign` capability 
behavior.
   
   # Are there any user-facing changes?
   
   - `HttpBuilder::build()` now rejects malformed, schemeless, non-HTTP(S), 
query-bearing, or fragment-bearing `endpoint` values with 
`ErrorKind::ConfigInvalid`, and normalizes trailing `/` characters on valid 
endpoints.
   - HTTP `401 Unauthorized` responses now return permanent 
`ErrorKind::PermissionDenied`, and `429 Too Many Requests` responses now return 
temporary `ErrorKind::RateLimited`.
   - `Operator::from_uri` for `http://` and `https://` URIs now uses userinfo 
credentials for Basic authentication unless overridden by explicit options, and 
disables `presign` capabilities when credentials are configured.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: pi
   - Model: Gemini 4 Neon
   - Effort: high
   - Role: Independently verified the three bugs in `core/services/http`, 
implemented the fixes, updated the builder doc example, added deterministic 
unit tests with a mock `HttpTransport`, and ran local formatting, lint, test, 
and rustdoc checks. Verification used unit tests and a mock HTTP transport 
rather than a live external HTTP server.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to