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

Add unsafe initialisers for HTTPField and HTTPField.Name #56

Open
adam-fowler opened this issue Jun 28, 2024 · 3 comments
Open

Add unsafe initialisers for HTTPField and HTTPField.Name #56

adam-fowler opened this issue Jun 28, 2024 · 3 comments
Labels
kind/enhancement Improvements to existing feature.

Comments

@adam-fowler
Copy link

Currently when constructing an HTTPField or HTTPField.Name the values are checked to see if they are valid. This is the correct thing to do obviously when the source of the headers is unknown, but if we know in advance the headers are valid this is wasted effort.

The situation I am describing comes from building a SwiftNIO server which has constructed the header values via LLHTTP which validates they are correct and then we build a HTTPField from these that does the validation again.

Is there an argument for providing an unsafe initialiser for both HTTPField and HTTPField.Name to avoid this duplicate work

@guoye-zhang
Copy link
Collaborator

Yeah, that could be useful. Something like HTTPField.Name.init(unchecked name: String)?

I wouldn't expect llhttp to clear everything up though. If the field value contains lone CRs, we still have to parse it but would want to replace those with spaces before passing them to the client.

@adam-fowler
Copy link
Author

I wouldn't expect llhttp to clear everything up though.

I don’t know, maybe @Lukasa knows

@FranzBusch
Copy link
Member

I agree with @guoye-zhang that we probably can't use this proposed unchecked initialiser since the validation that lhttp does isn't fully matching what the current HTTPTypes inits do.

@adam-fowler You mentioned to me that you see a lot of time spent in these validating inits. It's worth getting an issue opened for that as well to see if we can optimise this more.

@guoye-zhang guoye-zhang added the kind/enhancement Improvements to existing feature. label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements to existing feature.
Projects
None yet
Development

No branches or pull requests

3 participants