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

Normalize content-type before extention computation in SimpleHTTPResolver #509

Open
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

damooo
Copy link

@damooo damooo commented Aug 22, 2020

fixes #508

@alexwlchan
Copy link
Contributor

Thanks for raising this issue, and the initial patch!

Two suggestions:

  • We should use cgi.parse_header() instead of writing our own code to parse the Content-Type header. It’s more likely to handle other edge cases and be robust against other unexpected Content-Type headers.
  • Could you add a test for your change please?

@damooo
Copy link
Author

damooo commented Aug 27, 2020

It now uses cgi.parse_header, test case updated to issue complex content-type

@damooo
Copy link
Author

damooo commented Aug 29, 2020

Hello @alexwlchan, can you merge this patch, so that issue can be fixed?

)
responses.add(
responses.GET,
self.identifier_url,
body='II*\x00\x0c\x00\x00\x00\x80\x00 \x0e\x00\x00\x01\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x01\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x02\x01\x03\x00\x01\x00\x00\x00\x08\x00\x00\x00\x03\x01\x03\x00\x01\x00\x00\x00\x05\x00\x00\x00\x06\x01\x03\x00\x01\x00\x00\x00\x03\x00\x00\x00\x11\x01\x04\x00\x01\x00\x00\x00\x08\x00\x00\x00\x15\x01\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x16\x01\x03\x00\x01\x00\x00\x00\x08\x00\x00\x00\x17\x01\x04\x00\x01\x00\x00\x00\x04\x00\x00\x00\x1a\x01\x05\x00\x01\x00\x00\x00\xba\x00\x00\x00\x1b\x01\x05\x00\x01\x00\x00\x00\xc2\x00\x00\x00\x1c\x01\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00(\x01\x03\x00\x01\x00\x00\x00\x02\x00\x00\x00@\x01\x03\x00\x00\x03\x00\x00\xca\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00H\x00\x00\x00\x01\x00\x00\x00H\x00\x00\x00\x01\x00\x00\x00\xff`\xe6q\x19\x08\x00\x00\x80\t\x00\x00\x80\n\x00\x00\x80\x0b\x00\x00\x80\x0c\x00\x00\x80\r',
status=200,
content_type='image/tiff'
content_type='image/tiff; charset=UTF-8'
Copy link
Contributor

@alexwlchan alexwlchan Aug 29, 2020

Choose a reason for hiding this comment

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

This means we're no longer testing the old behaviour – we know the header image/tiff; charset=UTF-8 works, but not image/tiff. I'd rather have a test suite that covers both.

Can you add that, or would you rather I merge it and add the extra test myself?

Copy link
Author

Choose a reason for hiding this comment

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

I thought that simple case is just one of sub-cases of complex-headers case. Here it tests with any valid content-type in it's generic sense, than to check all possible header values.

I will add special simple case quickly if it is required.

Copy link
Author

Choose a reason for hiding this comment

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

at present, it has one self.identifier_url, around which test case runs. should i add another resource_identifier, to do this check? I seems bit lost in figuring out convention test cases following. I fear, i may make it more intrusive. if you don't mind, can you write the test case best suited with conventions?

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.

Normalize content-type before extention computation in SimpleHTTPResolver
2 participants