You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "aayushbaluni (via GitHub)" <gi...@apache.org> on 2026/10/07 10:46:13 UTC
[PR] fix(services/http): read a response that carries no content length [opendal]
aayushbaluni opened a new pull request, #8385:
URL: https://github.com/apache/opendal/pull/8385
# Which issue does this PR close?
Closes #8384.
# Rationale for this change
`Content-Length` is optional in HTTP. An HTTP/1.1 response can be framed with `Transfer-Encoding: chunked` (RFC 9112 §6.1) and an HTTP/2 response is framed by the end of the stream (RFC 9113 §8.1.1); RFC 9110 §8.6 only says a server *should* send a length when it knows one in advance. Since 0.59, `services-http` fails every read of such a response:
```
Unexpected (permanent) at read, context: { service: http, path: file.txt, range: 0- }
=> HTTP response does not contain file content length
```
The requirement comes from #8196, which made `Metadata` for a file always carry its complete content length. **That invariant is right and this PR does not touch it.** `parse_into_metadata` must keep refusing to invent a length.
What it does change is that `services-http` was asking for metadata it does not need in order to read. `RpRead` holds an `Option<Metadata>`, and its own documentation says so:
> Services should set it only when the metadata is returned natively by the read operation.
So when the response states no length, the right answer is to report no metadata — not to refuse the read.
# What changes are included in this PR?
One decision moved into a named function in `core/services/http/src/reader.rs`:
```rust
let content_length = parse_content_range(headers)?
.and_then(|value| value.size())
.or(parse_content_length(headers)?);
match content_length {
Some(_) => Ok(RpRead::new(parse_into_metadata(path, headers)?)),
None => Ok(RpRead::default()),
}
```
The length is derived exactly as `parse_into_metadata` derives it, so the two cannot disagree about whether one is present. **A malformed `Content-Length` still errors** — absent and unparseable are different, and there is a test for each.
This is not a new shape for the codebase. `services-ipmfs` already returns `RpRead::default()` for the same `OK | PARTIAL_CONTENT` arm, and `services-ftp` and `services-gcs-grpc` do the same, so "this service does not report read metadata" is established in-tree.
It is also what the behaviour suite already expects. `core/tests/behavior/async_read.rs` accepts an absent reply:
```rust
match stream.metadata().await {
Ok(meta) => assert_eq!(meta.content_length(), content.len() as u64, "metadata content length"),
Err(err) if err.kind() == ErrorKind::Unsupported => {}
Err(err) => return Err(err.into()),
}
```
So a caller that explicitly asks for `Reader::metadata()` on a chunked response now gets `ErrorKind::Unsupported`, which is the documented answer for a service that does not return metadata on read. Before this, the read itself failed.
# What is NOT in this PR: `stat`
The issue names `stat` as well, and I have deliberately left it alone, because it is not the same problem.
`RpStat::new` takes a `Metadata`, not an `Option<Metadata>`, and a file's `Metadata` carries a length by the #8196 invariant. On a `HEAD` with no length there is therefore nothing correct for `stat` to return: the resource exists and its size is genuinely unknown. `MetadataBuilder::unknown()` would let the call succeed with `EntryMode::Unknown`, but that changes what `stat` promises about a file that does exist, and it would silently break any caller branching on `is_file()`. That is a maintainer's call about the metadata model, not something to slip into a read fix.
If you would like `stat` to answer with an unknown mode in this case, say so and I will add it here or in a follow-up.
# Are there any user-facing changes?
Yes, and only in the failing direction:
- Reading an HTTP resource whose response carries no length **succeeds** instead of failing. This is the 0.58.2 behaviour.
- On such a read, `Reader::metadata()` returns `ErrorKind::Unsupported` rather than a `Metadata`. A caller that needs the size should `stat` it, on a server that reports one.
- Nothing changes for a response that does carry `Content-Length` or `Content-Range`: identical path, identical metadata.
- `stat` is unchanged, so the error in the issue still appears for `stat` on a length-free response.
# Breaking changes
None. No public API changes, and no behaviour change for any response that states a length.
# Tests
Five cases in `core/services/http/src/reader.rs`, in the shape `core.rs` already uses (`#[cfg(test)] mod tests` over a `HeaderMap`, no network):
| Test | Pins |
| --- | --- |
| `test_read_metadata_with_content_length` | a length is still reported, and is the one sent |
| `test_read_metadata_from_content_range` | a ranged read takes the **full** size from `Content-Range`, not the 4-byte `Content-Length` |
| `test_read_metadata_without_content_length_reports_none` | a chunked response is read, with no metadata |
| `test_read_metadata_without_any_headers_reports_none` | the HTTP/2 shape — no length header at all |
| `test_read_metadata_rejects_a_malformed_content_length` | `content-length: not-a-number` is still an error, not "absent" |
--
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: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(services/http): read a response that carries no content length [opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo merged PR #8385:
URL: https://github.com/apache/opendal/pull/8385
--
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: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(services/http): read a response that carries no content length [opendal]
Posted by "aayushbaluni (via GitHub)" <gi...@apache.org>.
aayushbaluni commented on PR #8385:
URL: https://github.com/apache/opendal/pull/8385#issuecomment-6036622329
Two jobs are red and neither is in a code path this PR touches, so here is the evidence rather than an assertion — I cannot re-run them from my side.
**`core / ubuntu-latest / redis`** — 32 of the 33 `core / *` jobs pass; redis is the only one that does not, and the failing step is `Test Core`. A change that broke `core` would fail all 33, not one. This PR touches a single file, `core/services/http/src/reader.rs`, which redis does not go through.
**`binding_dotnet / ubuntu-latest / webhdfs / webhdfs`** — a .NET binding against webhdfs. `core / ubuntu-latest / webhdfs` passes in the same run, so it is not webhdfs support that is broken.
The jobs that do exercise this change are green:
```
binding_c / ubuntu-latest / http / caddy pass 2m40s
binding_cpp / ubuntu-latest / http / caddy pass 2m44s
binding_dotnet / ubuntu-latest / http / caddy pass 4m7s
```
plus `lint`, `code-format`, `licenses` and `Breaking change declaration`. Locally, `cargo test -p opendal-service-http --lib` is 13 passed, and `cargo clippy -p opendal-service-http --lib --all-targets -- -D warnings` is clean.
Happy to push an empty commit to re-trigger if that is easier than a re-run.
--
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: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(services/http): read a response that carries no content length [opendal]
Posted by "aayushbaluni (via GitHub)" <gi...@apache.org>.
aayushbaluni commented on PR #8385:
URL: https://github.com/apache/opendal/pull/8385#issuecomment-6210266014
The one red check, `core / ubuntu-latest / redis`, is unrelated to this PR — a re-run should clear it.
It fails in the redis **writer** behaviour suite:
```
thread '<unnamed>' panicked at tests/behavior/async_write.rs:1154:37:
test panicked: stat must succeed: NotFound (persistent) at stat => key not found in redis
test behavior::test_writer_write_non_contiguous_data ... FAILED
test result: FAILED. 85 passed; 1 failed
```
This PR changes exactly one file, `core/services/http/src/reader.rs`, and nothing in the shared write or stat path — so it cannot reach a redis writer test. The shape (a single key reported `NotFound` immediately after a write, with the other 85 cases passing) looks like read-after-write timing against the redis service rather than a logic failure.
`Breaking change declaration` is green, and every other job passes.
--
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: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org