Giter VIP home page Giter VIP logo

Comments (9)

1st1 avatar 1st1 commented on August 21, 2024

On how to get the data, see the existing unittest for upgrade. Although I think I'll remove the exception in favour of a callback, as you suggested.

from httptools.

fafhrd91 avatar fafhrd91 commented on August 21, 2024

i think there is bug in offset calculation

import httptools

import unittest
from unittest import mock

UPGRADE_RESPONSE = b'''HTTP/1.1 101 Switching Protocols\r\nUPGRADE: websocket\r\nSEC-WEBSOCKET-ACCEPT: rVg+XakFNFOxk3ZH0lzrZBmg0aU=\r\nTRANSFER-ENCODING: chunked\r\nCONNECTION: upgrade\r\nDATE: Sat, 07 May 2016 23:44:32 GMT\r\nSERVER: Python/3.4 aiohttp/1.0.3\r\n\r\n\x89\x04data'''


class TestResponseParser(unittest.TestCase):

    def test_parser_upgrade_response(self):
        m = mock.Mock()

        headers = {}
        m.on_header.side_effect = headers.__setitem__

        p = httptools.HttpResponseParser(m)
        try:
            p.feed_data(UPGRADE_RESPONSE)
        except httptools.HttpParserUpgrade as ex:
            offset = ex.args[0]
        else:
            self.fail('HttpParserUpgrade was not raised')

        self.assertEqual(UPGRADE_RESPONSE[offset:], b'\x89\x04data')

        self.assertEqual(p.get_http_version(), '1.1')
        self.assertEqual(p.get_status_code(), 101)

        m.on_status.assert_called_once_with(b'Switching Protocols')

        m.on_headers_complete.assert_called_once_with()
        self.assertEqual(m.on_header.call_count, 6)
        self.assertEqual(len(headers), 6)

        m.on_message_complete.assert_called_once_with()

got this AssertionError: b'\x04data' != b'\x89\x04data'

from httptools.

1st1 avatar 1st1 commented on August 21, 2024

Transfer encoding is set to chunked. If I remove the transfer-encoding header everything works as expected.

from httptools.

1st1 avatar 1st1 commented on August 21, 2024

Are you sure that this response is valid?

from httptools.

fafhrd91 avatar fafhrd91 commented on August 21, 2024

i am not sure, but autobahn test suit passes for default websocket implementation.

from httptools.

1st1 avatar 1st1 commented on August 21, 2024

Is this response something that autobahn tests for?

To me this seems like an invalid response -- you essentially ask the protocol to upgrade, at the same time specifying the transfer-encoding. If this is a real-world situation then we probably need to fix http-parser.c

from httptools.

1st1 avatar 1st1 commented on August 21, 2024

Alright, seems that http-parser supports this -- have to fix the httptools. Working on it.

from httptools.

1st1 avatar 1st1 commented on August 21, 2024

Should be fixed in v0.0.9

from httptools.

fafhrd91 avatar fafhrd91 commented on August 21, 2024

thanks, works!

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.