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

Added option to ignore Content-Type header. #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KarelChanivecky
Copy link
Contributor

A kwarg parameter named ignore_content_type was added to get_pac and download_pac. The rationale for adding a new parameter is that it maintain the best backwards compatibility and ease of use. Also considered using accepting a specific value for allowed_content_types. However, I believe that this may be unexpected for current users. The parameter was placed before the 'session' parameter in order to maintain related parameter together. However, it risks breaking usages where all the passed arguments are positional. I leave this last matter in the discretion of the repo maintainer

A kwarg parameter named ignore_content_type was added to get_pac and download_pac. The rationale for adding a new parameter is that it maintain the best backwards compatibility and ease of use. Also considered using accepting a specific value for allowed_content_types. However, I believe that this may be unexpected for current users. The arg was placed before the 'session' arg in order to maintain related args together. However, it risks breaking usages where all the parameters are positional.
@carsonyl
Copy link
Owner

carsonyl commented Aug 5, 2023

This new feature seems to address a use case where the developer does not know the content type returned by the server and just wants PyPAC to accept any. But why wouldn't the developer just check for the content type and set it in allowed_content_types?

Due to how the content type comparison works, a workaround to needing ignore_content_type could be to set allowed_content_types = ['/'], assuming the server will always return a value containing /.

@KarelChanivecky
Copy link
Contributor Author

The issue arises when the developer has no control or knowledge of the runtime environment of the application. Reportedly, many clients do not enforce this. For example, see the chromium docs: https://chromium.googlesource.com/chromium/src/+/HEAD/net/docs/proxy.md#Downloading-PAC-scripts

One could require the users of the application to set the mime type. However, it may be desirable to reduce the number of possible configuration conflicts with an application user. Specially, if having the correct mime type is not considered critical.

@carsonyl
Copy link
Owner

That Chromium doc is another very good discovery. But I want to avoid adding new parameters as much as possible, and this issue of nonstandard content type headers doesn't seem common. So maybe a "good enough" workaround is to set allowed_content_types = ['/']? The code already allows the content-type header to be missing, so this workaround would only fail for the case where the header is present but the value doesn't contain /.

@KarelChanivecky
Copy link
Contributor Author

I hear you about adding more args. How about add a special token that can be passed in the allowed content types such as "*"?

@carsonyl
Copy link
Owner

allowed_content_types could be changed to handle list[str]|Literal["*"]. But we could also instead avoid changing the code by adding doc on this topic. What do you think?

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.

None yet

2 participants