Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content-type header doesn't seem to be set #19

Closed
martinetd opened this issue Jul 13, 2023 · 3 comments · Fixed by #20
Closed

content-type header doesn't seem to be set #19

martinetd opened this issue Jul 13, 2023 · 3 comments · Fixed by #20

Comments

@martinetd
Copy link

Hi, thanks for this!

Running the example straight of this git, I do not seem to get a Content-Type header off the server:

$ cargo run --example json-example --features json
(another terminal)
$ curl -v http://127.0.0.1:8080/json-nl-stream
*   Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET /json-nl-stream HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.88.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< transfer-encoding: chunked
< date: Wed, 12 Jul 2023 22:38:59 GMT
< 
{"some_test_field":"test1"}
{"some_test_field":"test1"}
{"some_test_field":"test1"}
...

(also tried csv with no difference)

In the code e.g. src/json_formats.rs seems to set Content-type to application/jsonstream for json-nl-stream, and src/stream_body_as.rs plugs it in HttpBody's poll_trailers, so I'm not sure what's wrong.

FWIW I was able to work around this by returning the header manually as follow (example); I ended up not using json so went for plain axum::body::StreamBody (might not have existed at the time?) but figured I might as well report this.

diff --git a/examples/json-example.rs b/examples/json-example.rs
index ae3de784bb87..1e3942fa371a 100644
--- a/examples/json-example.rs
+++ b/examples/json-example.rs
@@ -1,6 +1,7 @@
 use axum::response::IntoResponse;
 use axum::routing::*;
 use axum::Router;
+use axum::http::header::CONTENT_TYPE;
 use std::net::SocketAddr;
 
 use futures::prelude::*;
@@ -30,7 +31,7 @@ async fn test_json_array_stream() -> impl IntoResponse {
 }
 
 async fn test_json_nl_stream() -> impl IntoResponse {
-    StreamBodyAs::json_nl(source_test_stream())
+    ([(CONTENT_TYPE, "application/jsonstream")], StreamBodyAs::json_nl(source_test_stream()))
 }
 
 #[tokio::main]
@abdolence
Copy link
Owner

Thanks for the report, this is I believe is fixed now in
https://github.com/abdolence/axum-streams-rs/releases/tag/v0.9.0

@abdolence
Copy link
Owner

btw If you need to override headers now StreamBodyAs supports headers().

@martinetd
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants