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

add support for HTTPie's --raw flag #202

Merged
merged 9 commits into from
Nov 30, 2021
Merged

add support for HTTPie's --raw flag #202

merged 9 commits into from
Nov 30, 2021

Conversation

ducaale
Copy link
Owner

@ducaale ducaale commented Nov 29, 2021

Resolves #178

@ducaale ducaale mentioned this pull request Nov 29, 2021
28 tasks
Copy link
Collaborator

@blyxxyz blyxxyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great!

It's not caused by this change, but I just noticed that HTTPie doesn't use a POST request for a zero-length body, e.g. printf '' | xh --offline :. I don't know how straightforward that'll be to fix, so we could make an issue for it instead.

src/main.rs Outdated
if body.is_multipart() {
let body_from_request_items = args.request_items.body()?;

let body = match (!ignore_stdin, args.raw, !body_from_request_items.is_empty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find matching on negated booleans hard to follow.

Maybe it would be better to turn ignore_stdin into let use_stdin = !(args.ignore_stdin || atty::is(Stream::Stdin) || test_pretend_term());? And perhaps let has_request_items = !body_from_request_items.is_empty();.

src/main.rs Outdated Show resolved Hide resolved
@@ -1350,6 +1350,30 @@ fn mixed_stdin_request_items() {
));
}

#[test]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also test successful use of the option?

Co-authored-by: Jan Verbeek <jan.verbeek@posteo.nl>
Copy link
Collaborator

@blyxxyz blyxxyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

src/main.rs Outdated Show resolved Hide resolved
tests/cli.rs Outdated
binary_file.write_all(b"foo\0bar").unwrap();
binary_file.seek(SeekFrom::Start(0)).unwrap();
redirecting_command()
.args(&["--print=B", "--offline", ":"])
.stdin(binary_file)
.pipe_stdin(binary_file.path())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would .write_stdin(b"foo\0bar") work?

ducaale and others added 2 commits November 30, 2021 14:40
Co-authored-by: Jan Verbeek <jan.verbeek@posteo.nl>
@ducaale ducaale merged commit c0fdc6d into develop Nov 30, 2021
@ducaale ducaale deleted the raw-flag branch November 30, 2021 13:11
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.

2 participants