Example #1
0
    def test_altsvc_frame_with_origin_and_stream_serializes_properly(self):
        # This frame is not valid, but we allow it to be serialized anyway.
        f = AltSvcFrame(stream_id=1)
        f.origin = b'example.com'
        f.field = b'Alt-Svc: h2=":443"; ma=2592000; persist=1'

        assert f.serialize() == self.payload_with_origin_and_stream
Example #2
0
    def test_altsvc_frame_with_origin_serializes_properly(self):
        f = AltSvcFrame(stream_id=0)
        f.origin = b'example.com'
        f.field = b'h2="alt.example.com:8000", h2=":443"'

        s = f.serialize()
        assert s == self.payload_with_origin
Example #3
0
    def test_altsvc_frame_with_origin_serializes_properly(self):
        f = AltSvcFrame(stream_id=0)
        f.origin = b'example.com'
        f.field = b'h2="alt.example.com:8000", h2=":443"'

        s = f.serialize()
        assert s == self.payload_with_origin
Example #4
0
    def test_altsvc_frame_with_origin_and_stream_serializes_properly(self):
        # This frame is not valid, but we allow it to be serialized anyway.
        f = AltSvcFrame(stream_id=1)
        f.origin = b'example.com'
        f.field = b'Alt-Svc: h2=":443"; ma=2592000; persist=1'

        assert f.serialize() == self.payload_with_origin_and_stream
 def build_alt_svc_frame(self, stream_id, origin, field):
     """
     Builds a single ALTSVC frame.
     """
     f = AltSvcFrame(stream_id)
     f.origin = origin
     f.field = field
     return f
Example #6
0
 def build_alt_svc_frame(self, stream_id, origin, field):
     """
     Builds a single ALTSVC frame.
     """
     f = AltSvcFrame(stream_id)
     f.origin = origin
     f.field = field
     return f
Example #7
0
 def advertise_alternative_service(self, field_value):
     """
     Advertise an RFC 7838 alternative service. The semantics of this are
     better documented in the ``H2Connection`` class.
     """
     self.state_machine.process_input(StreamInputs.SEND_ALTERNATIVE_SERVICE)
     asf = AltSvcFrame(self.stream_id)
     asf.field = field_value
     return [asf]
Example #8
0
 def advertise_alternative_service(self, field_value):
     """
     Advertise an RFC 7838 alternative service. The semantics of this are
     better documented in the ``H2Connection`` class.
     """
     self.state_machine.process_input(StreamInputs.SEND_ALTERNATIVE_SERVICE)
     asf = AltSvcFrame(self.stream_id)
     asf.field = field_value
     return [asf]
Example #9
0
 def test_repr(self):
     f = AltSvcFrame(0)
     assert repr(f).endswith("origin=b'', field=b''")
     f.field = b'h2="alt.example.com:8000", h2=":443"'
     assert repr(f).endswith(
         "origin=b'', field=b'h2=\"alt.example.com:8000\", h2=\":443\"'")
     f.origin = b'example.com'
     assert repr(f).endswith(
         "origin=b'example.com', field=b'h2=\"alt.example.com:8000\", h2=\":443\"'"
     )
    def test_altsvc_frame_with_origin_serializes_properly(self):
        f = AltSvcFrame(0)
        f.host = b'google.com'
        f.port = 80
        f.protocol_id = b'h2'
        f.max_age = 29
        f.origin = Origin(scheme=b'https', host=b'yahoo.com', port=8080)

        s = f.serialize()
        assert s == self.payload_with_origin
    def test_altsvc_frame_without_origin_serializes_properly(self):
        f = AltSvcFrame(0)
        f.host = b'google.com'
        f.port = 80
        f.protocol_id = b'h2'
        f.max_age = 29

        s = f.serialize()
        assert s == self.payload_without_origin
    def test_altsvc_frame_serialize_origin_without_port(self):
        f = AltSvcFrame(0)
        f.origin = Origin(scheme=b'https', host=b'yahoo.com', port=None)

        assert f.serialize_origin() == b'https://yahoo.com'
    def test_altsvc_frame_flags(self):
        f = AltSvcFrame(0)
        flags = f.parse_flags(0xFF)

        assert flags == set()
Example #14
0
 def test_altsvc_with_unicode_field_fails(self):
     with pytest.raises(ValueError):
         AltSvcFrame(stream_id=0,
                     origin=b'hello',
                     field=u'h2=":8000"; ma=60')
Example #15
0
 def test_altsvc_frame_without_origin_serializes_properly(self):
     f = AltSvcFrame(stream_id=1, origin=b'', field=b'h2=":8000"; ma=60')
     s = f.serialize()
     assert s == self.payload_without_origin
Example #16
0
 def test_altsvc_frame_without_origin_serializes_properly(self):
     f = AltSvcFrame(stream_id=1, origin=b'', field=b'h2=":8000"; ma=60')
     s = f.serialize()
     assert s == self.payload_without_origin
Example #17
0
    def test_altsvc_frame_flags(self):
        f = AltSvcFrame(stream_id=0)
        flags = f.parse_flags(0xFF)

        assert flags == set()
Example #18
0
 def test_altsvc_with_unicode_origin_fails(self):
     with pytest.raises(InvalidDataError):
         AltSvcFrame(stream_id=0,
                     origin=u'hello',
                     field=b'h2=":8000"; ma=60')