-
Notifications
You must be signed in to change notification settings - Fork 98
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
enable stream when content-type is text/event-stream #360
Conversation
I have no idea how to write a test case for this feature. |
680e8af
to
a107333
Compare
a107333
to
38724cc
Compare
Not something to address in this PR but I noticed that HTTPie can format payloads contained in individual events $ http https://sse.dev/test --body
data: {
"msg": "It works!",
"now": 1712764259321,
"sse_dev": "is great",
"testing": true
}
data: {
"msg": "It works!",
"now": 1712764261322,
"sse_dev": "is great",
"testing": true
} |
b3e10cc
to
3c985f0
Compare
self, | ||
ContentType::Unknown | ContentType::UrlencodedForm | ContentType::Multipart | ||
) | ||
match self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ensure the author updates this method when adding a content-type in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! just one final comment:
@@ -168,8 +168,8 @@ Example: --print=Hb" | |||
pub quiet: bool, | |||
|
|||
/// Always stream the response body. | |||
#[clap(short = 'S', long)] | |||
pub stream: bool, | |||
#[clap(short = 'S', long, default_missing_value = "true", num_args= 0..=1, require_equals = true)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to prefer Option<bool>
over bool
? It affects the generated help output, but in terms of functionality, the result is the same: false
/true
versus None
/Some(true)
Before
-S, --stream Always stream the response body
After
-S, --stream[=<STREAM>] Always stream the response body [possible values: true, false]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to provide users with the ability to choose to turn off automatic print body as stream.
cli args | stream value | description |
---|---|---|
xh -S | Some(true) | alway enable stream |
xh -S=true | Some(true) | alway enable stream |
xh -S=false | Some(false) | alway disable stream |
xh | None | auto enable stream when meet stream body |
@@ -447,6 +447,9 @@ impl Printer { | |||
let compression_type = get_compression_type(response.headers()); | |||
let mut body = decompress(response, compression_type); | |||
|
|||
// Automatically activate stream mode when it hasn't been set by the user and the content type is stream | |||
let stream = self.stream.unwrap_or(content_type.is_stream()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if user set -S=false
, it will't print body as stream
closes #204