Coder Social home page Coder Social logo

Examples about http-parser HOT 6 CLOSED

Onepamopa avatar Onepamopa commented on August 16, 2024
Examples

from http-parser.

Comments (6)

indutny avatar indutny commented on August 16, 2024

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.

from http-parser.

Onepamopa avatar Onepamopa commented on August 16, 2024

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 ?

from http-parser.

indutny avatar indutny commented on August 16, 2024

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.

from http-parser.

Onepamopa avatar Onepamopa commented on August 16, 2024

Are there any examples of that ?

from http-parser.

indutny avatar indutny commented on August 16, 2024

Have you seen a short setup in llhttp's README?

from http-parser.

Onepamopa avatar Onepamopa commented on August 16, 2024

@indutny I have seen the short setup, I haven't seen example callback functions extracting url, http method, headers, etc.

from http-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.