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

Valid cURL invocation fails with httpstat because of URL position #19

Closed
bbiskup opened this issue Oct 7, 2016 · 3 comments
Closed

Comments

@bbiskup
Copy link

bbiskup commented Oct 7, 2016

An invocation that would be valid with cURL:

curl -X GET http://www.google.de/

gives the following error with httpstat:

$ httpstat -X GET http://www.google.de/
> curl -w <output-format> -D <tempfile> -o <tempfile> -s -S GET http://www.google.de/ -X
curl error: curl: option -X: requires parameter
curl: try 'curl --help' or 'curl --manual' for more information

whereas the command

httpstat http://www.google.de/ -X GET

is parsed successfully.

It would be nice if httpstat did not depend on the position of the URL. In my concrete example, the cURL command was generated by Flask-RESTPlus Swagger documentation.

@reorx
Copy link
Owner

reorx commented Oct 8, 2016

After digging around with curl for a while, I found that

It would be nice if httpstat did not depend on the position of the URL

is very hard to achieve. curl actually don't care the position of URL, whether URL is at first, or last, or in the middle, as long as the other arguments follow the rules, curl can parse the inputs correctly.

As to httpstat, we couldn't just pass all the arguments to curl directly, we have to find out the URL to decide whether to use http or https display template. Specify position is the easiest way to help getting the URL, if not specify, we have to implement an argument parser the same as curl's, which is not an easy work. In that case, whether the position is first or last doesn't make much difference, since both will still have invocation valid to curl but invalid to itself. What do you think?

@bbiskup
Copy link
Author

bbiskup commented Oct 8, 2016

Thank you for the prompt reply. I think replicating curl's command-line parsing or adding a library dependency would overkill. Nevertheless, I would suggest a comment making it clear to first-time users that the URL needs to be given first, because

  • curl --help gives prints this usage:
    curl [options...] <url>
  • the curl manpage gives examples with options and URL in any order

Anyway, it is a minor issue or even just a matter of habit.

@reorx
Copy link
Owner

reorx commented Oct 8, 2016

Actually the usage has made it clear that the URL should be put at the first position:

$ python httpstat.py
Usage: httpstat URL [CURL_OPTIONS]
       httpstat -h | --help
       httpstat --version

The time I was considering the URL's position, I was thinking that httpstat itself actually has no option. So it should be distinguished from normal situation, where intuitively options are put after command and before the main arguments. Thus when you see httpstat URL [CURL_OPTIONS], it becomes very clear that the curl options are just for curl, and will definitely have no effect on how httpstat will perform. All the options for httpstat, are environment variables, separately.

In conclusion, the position of URL won't be changed, thanks for your suggestion and cooperation :)

P.S. it's easy to modify the code for your own to make URL at the last position, just change L180 to url = args[-1] and L88 to curl_args = args[:-1].

@reorx reorx closed this as completed Oct 8, 2016
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

No branches or pull requests

2 participants