-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow http
commands' automatic redirect-following to be disabled
#11329
Conversation
http
commands' automatic redirect-following to be disabled
Thanks for your pr! Actually I think it's good to have one |
That's a good point. Actually, on that note, as far as I can tell all the http commands' existing flags have shorthands, which makes it difficult to find an appropriate one for this new flag that is still free. Anyone have any thoughts on that? Like, whether we even want a shorthand for this flag? And in general, any additional feedback on design and the names I chose would be appreciated before I get this PR ready for review :) |
Sadly to found that I have 2 ideas:
Personally I'd prefer the 1st option. |
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.
Really thanks for your improvement on http
commands, I think we can change something to make it better.
And, It's appreciated to have some tests for the feature. You can check here for more about testing code: https://github.com/nushell/nushell/tree/534287ed65630003d731bb8e0268a6e2f7f10bd2/crates/nu-command/tests/commands/network/http
Thanks for this note - I was hoping you'd say something about tests, because I couldn't figure how tests should be done here on my own. I'll add some :) |
Thanks! Would you please resolve conflict? |
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.
Thank you for working through all of this! Look good to me
Thank you for the ideas and the reviews :)) |
…ushell#11329) Intends to close nushell#8920 This PR suggests a new flag for the `http` commands, `--redirect-mode`, which enables users to choose between different redirect handling modes. The current behaviour of letting ureq silently follow redirects remains the default, but two new options are introduced here, following the lead of [JavaScript's `fetch` API](https://developer.mozilla.org/en-US/docs/Web/API/fetch#redirect): "manual", where any 3xx response to a request is simply returned as the command's result, and "error", where any 3xx response causes a network error like those caused by 4xx and 5xx responses. This PR is a draft. Tests have not been added or run, the flag is currently only implemented for the `http get` command, and design tweaks are likely to be appropriate. Most notably, it's not obvious to me whether a single flag which can take one of three values is the nicest solution here. We might instead consider two binary flags (like `--no-following-redirects` and `--disallow-redirects`, although I'm bad at naming things so I need help with that anyway), or completely drop the "error" option if it's not deemed useful enough. (I personally think it has some merit, especially since 4xx and 5xx responses are already treated as errors by default; So this would allow users to treat only immediate 2xx responses as success) # User-facing changes New options for the `http [method]` commands. Behaviour remains unchanged when the command line flag introduced here is not used. ![image](https://github.com/nushell/nushell/assets/12228688/1eb89f14-7d48-4f41-8a3e-cc0f1bd0a4f8)
Intends to close #8920
This PR suggests a new flag for the
http
commands,--redirect-mode
, which enables users to choose between different redirect handling modes. The current behaviour of letting ureq silently follow redirects remains the default, but two new options are introduced here, following the lead of JavaScript'sfetch
API: "manual", where any 3xx response to a request is simply returned as the command's result, and "error", where any 3xx response causes a network error like those caused by 4xx and 5xx responses.This PR is a draft. Tests have not been added or run, the flag is currently only implemented for the
http get
command, and design tweaks are likely to be appropriate.Most notably, it's not obvious to me whether a single flag which can take one of three values is the nicest solution here.
We might instead consider two binary flags (like
--no-following-redirects
and--disallow-redirects
, although I'm bad at naming things so I need help with that anyway), or completely drop the "error" option if it's not deemed useful enough. (I personally think it has some merit, especially since 4xx and 5xx responses are already treated as errors by default; So this would allow users to treat only immediate 2xx responses as success)User-facing changes
New options for the
http [method]
commands. Behaviour remains unchanged when the command line flag introduced here is not used.