Ejemplo n.º 1
0
 def test_override(self):
     h = Headers([('Accept-encoding', 'gzip'),
                  ('Accept-encoding', 'deflate'), ('Accept', '*/*')],
                 kind=2)
     h.override([('Accept-encoding', 'gzip2'),
                 ('Accept-encoding', 'deflate2'), ('Accept', 'text/html'),
                 ('Accept', '*/*; q=0.8')])
     self.assertEqual(len(h), 2)
     self.assertEqual(h['accept-encoding'], 'gzip2, deflate2')
     self.assertEqual(h['accept'], 'text/html, */*; q=0.8')
Ejemplo n.º 2
0
 def test_override(self):
     h = Headers([('Accept-encoding', 'gzip'),
                  ('Accept-encoding', 'deflate'),
                  ('Accept', '*/*')], kind=2)
     h.override([('Accept-encoding', 'gzip2'),
                 ('Accept-encoding', 'deflate2'),
                 ('Accept', 'text/html'),
                 ('Accept', '*/*; q=0.8')])
     self.assertEqual(len(h), 2)
     self.assertEqual(h['accept-encoding'], 'gzip2, deflate2')
     self.assertEqual(h['accept'], 'text/html, */*; q=0.8')
Ejemplo n.º 3
0
 def get_headers(self, request, headers=None):
     # Returns a :class:`Header` obtained from combining
     # :attr:`headers` with *headers*. Can handle websocket requests.
     if request.scheme in ('ws', 'wss'):
         d = Headers(
             (('Connection', 'Upgrade'), ('Upgrade', 'websocket'),
              ('Sec-WebSocket-Version', str(max(SUPPORTED_VERSIONS))),
              ('Sec-WebSocket-Key', self.websocket_key),
              ('user-agent', self.client_version)),
             kind='client')
     else:
         d = self.headers.copy()
     if headers:
         d.override(headers)
     return d
Ejemplo n.º 4
0
 def get_headers(self, request, headers=None):
     # Returns a :class:`Header` obtained from combining
     # :attr:`headers` with *headers*. Can handle websocket requests.
     if request.scheme in ('ws', 'wss'):
         d = Headers((
             ('Connection', 'Upgrade'),
             ('Upgrade', 'websocket'),
             ('Sec-WebSocket-Version', str(max(SUPPORTED_VERSIONS))),
             ('Sec-WebSocket-Key', self.websocket_key),
             ('user-agent', self.client_version)
             ), kind='client')
     else:
         d = self.headers.copy()
     if headers:
         d.override(headers)
     return d
Ejemplo n.º 5
0
 def get_headers(self, request, headers=None):
     # Returns a :class:`Header` obtained from combining
     # :attr:`headers` with *headers*. Can handle websocket requests.
     if request.scheme in ("ws", "wss"):
         d = Headers(
             (
                 ("Connection", "Upgrade"),
                 ("Upgrade", "websocket"),
                 ("Sec-WebSocket-Version", str(max(SUPPORTED_VERSIONS))),
                 ("Sec-WebSocket-Key", self.websocket_key),
                 ("user-agent", self.client_version),
             ),
             kind="client",
         )
     else:
         d = self.headers.copy()
     if headers:
         d.override(headers)
     return d