Closed Onepamopa closed 3 years ago
Hello @Onepamopa !
First of all, (as a shameless plug) I'd recommend moving to https://github.com/nodejs/llhttp instead of http_parser. As stated in readme this project is not actively maintained.
You can pickup the latest release, and init the parser with the settings object that has following callbacks:
on_header_field
on_header_value
on_headers_complete
The idea is to track what header fields you get and record their respective values. on_headers_complete
marks the end of the http request and the start of the request's data. You can check the recorded header fields at this point to see if certain header is present.
Hope this helps, Fedor.
That's what I don't get - the parser uses user-defined callbacks, which should contain what, exactly? If I want to extract a value of a header - I should do that where, and ... how ?
That's what I don't get - the parser uses user-defined callbacks, which should contain what, exactly?
The code for handling appropriate events.
If I want to extract a value of a header - I should do that where, and ... how ?
In the on_header_field
and on_header_value
callbacks. You can just do strncmp
on the field, and then take the value from the next on_header_value
call.
Are there any examples of that ?
Have you seen a short setup in llhttp's README?
@indutny I have seen the short setup, I haven't seen example callback functions extracting url, http method, headers, etc.
Hello,
Can someone tell me how exactly can I check if a certain header exists, and get its value ? I can't quite figure out how this parser works...