Giter VIP home page Giter VIP logo

Comments (5)

tomchristie avatar tomchristie commented on July 20, 2024

My current approach is:

  • Inspect upgrade header in on_header.
  • Ignore any events in on_body and on_message complete if an upgrade header existed.
  • Handle the httptools.HttpParserUpgrade in data_received as normally.

That works fine, only downside being a small amount of extra work in Python-land that could perhaps be dealt with by the parser, if the exception was raised prior to the event hooks being called.

I guess good options would be:

  • Close this off as a known constraint.
  • Ensure that httpparser instead raises the exception immediately prior to the point of calling on_headers_complete.

from httptools.

tomchristie avatar tomchristie commented on July 20, 2024

Okay, looks like this is a limitation of the underlying library...

the parser will treat this as a normal HTTP message without a body, issuing both on_headers_complete and on_message_complete callbacks

I'll close the issue off.

from httptools.

ramonz avatar ramonz commented on July 20, 2024

hi. also got HttpParserUpgrade when parsing
b'CONNECT /proxy/url HTTP/1.1\r\nHost: test01-proxy.com:80\r\nAuthorization: Basic dXNlcjpwYXNz\r\nX-Forwarded-For: 8.8.8.8\r\n\r\n'

In [60]: b = b'CONNECT /proxy/url HTTP/1.1\r\nHost: test01-proxy.com:80\r\nAuthorization: Basic dXNlcjpwYXNz\r\nX-Forwarded-For: 8.8.8.8\r\n\r\n'

In [61]: p = HttpRequestParser (lambda: None)

In [62]: p.feed_data(b)
---------------------------------------------------------------------------
HttpParserUpgrade                         Traceback (most recent call last)
<ipython-input-62-032eaec4cf5a> in <module>()
----> 1 p.feed_data(b)

httptools/parser/parser.pyx in httptools.parser.parser.HttpParser.feed_data (httptools/parser/parser.c:2781)()

HttpParserUpgrade: 119

if replace the b'\r\n\r\n' with b\r\n' the error is disappears

made more tests. parsing the request above and even replacing '\r\n\r\n' not works correctly: callback functions such as on_message_complete, on_headers_complete not fired at all.
just replacing the b'CONNECT' with b'GET' without other modifications makes all working.

from httptools.

yohanboniface avatar yohanboniface commented on July 20, 2024

cf #29 for the record

from httptools.

yohanboniface avatar yohanboniface commented on July 20, 2024

@ramonz I think it's expected behaviour, see https://github.com/nodejs/http-parser/blob/0264a0aefcd119e179a3bc730ac517efbbccd4bb/http_parser.c#L1319

from httptools.

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.