Giter VIP home page Giter VIP logo

Comments (10)

1st1 avatar 1st1 commented on July 2, 2024

Can you send me the full source code of a test that fails?

from httptools.

fafhrd91 avatar fafhrd91 commented on July 2, 2024
import httptools

import unittest
from unittest import mock

CHUNKED_REQUEST1_3 = b'''POST /test.php?a=b+c HTTP/1.2
User-Agent: Fooo
Host: bar
Transfer-Encoding: chunked

b\r\n+\xce\xcfM\xb5MI,I\x04\x00\r\n0\r\n\r\n'''


class TestRequestParser(unittest.TestCase):

    def test_parser_request_chunked_3(self):
        m = mock.Mock()
        p = httptools.HttpRequestParser(m)

        p.feed_data(CHUNKED_REQUEST1_3)

        self.assertEqual(p.get_method(), b'POST')

        m.on_url.assert_called_once_with(b'/test.php?a=b+c')
        self.assertEqual(p.get_http_version(), '1.2')

        m.on_header.assert_called_with(b'Transfer-Encoding', b'chunked')
        m.on_chunk_header.assert_called_with()
        m.on_chunk_complete.assert_called_with()

        self.assertFalse(m.on_message_complete.called)

from httptools.

1st1 avatar 1st1 commented on July 2, 2024

Hm. I'm still not sure what's going on here.

It looks like this request is invalid: the length of first chunk is b == 11. The parser correctly calls on_body with b'+g\xce\xcfM\xb5MI,I\x04'. But there is an extra byte x00 which isn't consumed, and there is no exception either...

from httptools.

1st1 avatar 1st1 commented on July 2, 2024

Got it, I got an extra char in my CHUNKED_REQUEST1_3. Seems like it has troubles with \x00.

from httptools.

1st1 avatar 1st1 commented on July 2, 2024

Yep, it's a bug in http-parser.c. If you change \x00 to \x01 everything works.

from httptools.

fafhrd91 avatar fafhrd91 commented on July 2, 2024

Yes, I noticed that.

On May 6, 2016, at 5:21 PM, Yury Selivanov [email protected] wrote:

Yep, it's a bug in http-parser.c. If you change \x00 to \x01 everything works.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub

from httptools.

1st1 avatar 1st1 commented on July 2, 2024

Nope. Bug in my code, which is a good thing :) Will commit a fix soon.

from httptools.

1st1 avatar 1st1 commented on July 2, 2024

Should be fixed in v0.0.6.

from httptools.

1st1 avatar 1st1 commented on July 2, 2024

The bug was in a len function called on a char*. Cython, without a warning, used strlen, which gave the http-parser a wrong length (because of the \x00 byte).

from httptools.

1st1 avatar 1st1 commented on July 2, 2024

Anyways, I've updated the code to use buffer protocol -- it's much more efficient.

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.