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

uncurl.parse response puts headers in alphabetical order #37

Open
machine-gurning opened this issue Aug 10, 2020 · 3 comments
Open

uncurl.parse response puts headers in alphabetical order #37

machine-gurning opened this issue Aug 10, 2020 · 3 comments

Comments

@machine-gurning
Copy link

G'day there, I am using this python package in the hope that it does something identical to curl.trillworks.com.

Mostly works hunky-dory, but I note that the website mentioned above returns a headers dictionary in the correct headers order, whereas the uncurl.parse() function gives me an unordered dictionary, in alphabetical order. It it possible to change this to an ordered dictionary?

Input:

uncurl.parse("curl 'https://www.amazon.com/' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:77.0) Gecko/20100101 Firefox/77.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1'")

Output:
'requests.get("https://www.amazon.com/",\n headers={\n "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",\n "Accept-Language": "en-US,en;q=0.5",\n "Connection": "keep-alive",\n "DNT": "1",\n "Upgrade-Insecure-Requests": "1",\n "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:77.0) Gecko/20100101 Firefox/77.0"\n },\n cookies={},\n)'

Desired output:

headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:77.0) Gecko/20100101 Firefox/77.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Language': 'en-US,en;q=0.5', 'DNT': '1', 'Connection': 'keep-alive', 'Upgrade-Insecure-Requests': '1', }

Cheers and thanks for your work

@spulec
Copy link
Owner

spulec commented Aug 14, 2020

Hmmm, that is a fair point. We are being inaccurate by sorting headers.

It is really nice to have them sorted from a visual perspective though :/

Would we still want to sort cookies too or no?

@machine-gurning
Copy link
Author

May I suggest an option to either return the output in alphabetical order for easy comprehension, or unsorted order (i.e. the order of curl.trillworks.com, and the order of the headers generated automatically by browsers) for the purpose of accuracy?

Such an option I don't think has been offered before, as I have been fishing around on forums for some time now trying to find it

@spulec
Copy link
Owner

spulec commented Aug 20, 2020

Hey, can you take a look at this PR and see if it matches what you are thinking: #38

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