Skip to content
Permalink
Browse files

Add modules to implement a http/2 server and client

* h2		i/o abstracted http/2 framing protocol
* hpack		headers packing module
* hyper		http/2 client module
* hyperframe
* rfc2986
  • Loading branch information...
cvaroqui committed Jun 21, 2019
1 parent a3e3542 commit f43683ca6f17b53defe75c84824253ece895f2e7
Showing with 25,533 additions and 0 deletions.
  1. +8 −0 lib/h2/__init__.py
  2. +164 −0 lib/h2/config.py
  3. +2,012 −0 lib/h2/connection.py
  4. +75 −0 lib/h2/errors.py
  5. +648 −0 lib/h2/events.py
  6. +186 −0 lib/h2/exceptions.py
  7. +175 −0 lib/h2/frame_buffer.py
  8. +339 −0 lib/h2/settings.py
  9. +1,403 −0 lib/h2/stream.py
  10. +660 −0 lib/h2/utilities.py
  11. +139 −0 lib/h2/windows.py
  12. +20 −0 lib/hpack/__init__.py
  13. +42 −0 lib/hpack/compat.py
  14. +49 −0 lib/hpack/exceptions.py
  15. +630 −0 lib/hpack/hpack.py
  16. +68 −0 lib/hpack/huffman.py
  17. +288 −0 lib/hpack/huffman_constants.py
  18. +4,739 −0 lib/hpack/huffman_table.py
  19. +39 −0 lib/hpack/struct.py
  20. +235 −0 lib/hpack/table.py
  21. +36 −0 lib/hyper/__init__.py
  22. +5,275 −0 lib/hyper/certs.pem
  23. +264 −0 lib/hyper/cli.py
  24. +7 −0 lib/hyper/common/__init__.py
  25. +240 −0 lib/hyper/common/bufsocket.py
  26. +164 −0 lib/hyper/common/connection.py
  27. +48 −0 lib/hyper/common/decoder.py
  28. +92 −0 lib/hyper/common/exceptions.py
  29. +260 −0 lib/hyper/common/headers.py
  30. +69 −0 lib/hyper/common/util.py
  31. +84 −0 lib/hyper/compat.py
  32. +205 −0 lib/hyper/contrib.py
  33. +7 −0 lib/hyper/http11/__init__.py
  34. +480 −0 lib/hyper/http11/connection.py
  35. +83 −0 lib/hyper/http11/parser.py
  36. +342 −0 lib/hyper/http11/response.py
  37. +7 −0 lib/hyper/http20/__init__.py
  38. +870 −0 lib/hyper/http20/connection.py
  39. +77 −0 lib/hyper/http20/errors.py
  40. +51 −0 lib/hyper/http20/exceptions.py
  41. +239 −0 lib/hyper/http20/response.py
  42. +344 −0 lib/hyper/http20/stream.py
  43. +60 −0 lib/hyper/http20/util.py
  44. +154 −0 lib/hyper/http20/window.py
  45. +116 −0 lib/hyper/httplib_compat.py
  46. +308 −0 lib/hyper/ssl_compat.py
  47. +133 −0 lib/hyper/tls.py
  48. +8 −0 lib/hyperframe/__init__.py
  49. +41 −0 lib/hyperframe/exceptions.py
  50. +50 −0 lib/hyperframe/flags.py
  51. +822 −0 lib/hyperframe/frame.py
  52. +56 −0 lib/rfc3986/__init__.py
  53. +353 −0 lib/rfc3986/_mixin.py
  54. +267 −0 lib/rfc3986/abnf_regexp.py
  55. +106 −0 lib/rfc3986/api.py
  56. +298 −0 lib/rfc3986/builder.py
  57. +54 −0 lib/rfc3986/compat.py
  58. +118 −0 lib/rfc3986/exceptions.py
  59. +147 −0 lib/rfc3986/iri.py
  60. +124 −0 lib/rfc3986/misc.py
  61. +167 −0 lib/rfc3986/normalizers.py
  62. +385 −0 lib/rfc3986/parseresult.py
  63. +153 −0 lib/rfc3986/uri.py
  64. +450 −0 lib/rfc3986/validators.py
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
"""
h2
~~
A HTTP/2 implementation.
"""
__version__ = '3.2.0dev0'
@@ -0,0 +1,164 @@
# -*- coding: utf-8 -*-
"""
h2/config
~~~~~~~~~
Objects for controlling the configuration of the HTTP/2 stack.
"""


class _BooleanConfigOption(object):
"""
Descriptor for handling a boolean config option. This will block
attempts to set boolean config options to non-bools.
"""
def __init__(self, name):
self.name = name
self.attr_name = '_%s' % self.name

def __get__(self, instance, owner):
return getattr(instance, self.attr_name)

def __set__(self, instance, value):
if not isinstance(value, bool):
raise ValueError("%s must be a bool" % self.name)
setattr(instance, self.attr_name, value)


class DummyLogger(object):
"""
An Logger object that does not actual logging, hence a DummyLogger.
For the class the log operation is merely a no-op. The intent is to avoid
conditionals being sprinkled throughout the hyper-h2 code for calls to
logging functions when no logger is passed into the corresponding object.
"""
def __init__(self, *vargs):
pass

def debug(self, *vargs, **kwargs):
"""
No-op logging. Only level needed for now.
"""
pass


class H2Configuration(object):
"""
An object that controls the way a single HTTP/2 connection behaves.
This object allows the users to customize behaviour. In particular, it
allows users to enable or disable optional features, or to otherwise handle
various unusual behaviours.
This object has very little behaviour of its own: it mostly just ensures
that configuration is self-consistent.
:param client_side: Whether this object is to be used on the client side of
a connection, or on the server side. Affects the logic used by the
state machine, the default settings values, the allowable stream IDs,
and several other properties. Defaults to ``True``.
:type client_side: ``bool``
:param header_encoding: Controls whether the headers emitted by this object
in events are transparently decoded to ``unicode`` strings, and what
encoding is used to do that decoding. This defaults to ``None``,
meaning that headers will be returned as bytes. To automatically
decode headers (that is, to return them as unicode strings), this can
be set to the string name of any encoding, e.g. ``'utf-8'``.
.. versionchanged:: 3.0.0
Changed default value from ``'utf-8'`` to ``None``
:type header_encoding: ``str``, ``False``, or ``None``
:param validate_outbound_headers: Controls whether the headers emitted
by this object are validated against the rules in RFC 7540.
Disabling this setting will cause outbound header validation to
be skipped, and allow the object to emit headers that may be illegal
according to RFC 7540. Defaults to ``True``.
:type validate_outbound_headers: ``bool``
:param normalize_outbound_headers: Controls whether the headers emitted
by this object are normalized before sending. Disabling this setting
will cause outbound header normalization to be skipped, and allow
the object to emit headers that may be illegal according to
RFC 7540. Defaults to ``True``.
:type normalize_outbound_headers: ``bool``
:param validate_inbound_headers: Controls whether the headers received
by this object are validated against the rules in RFC 7540.
Disabling this setting will cause inbound header validation to
be skipped, and allow the object to receive headers that may be illegal
according to RFC 7540. Defaults to ``True``.
:type validate_inbound_headers: ``bool``
:param normalize_inbound_headers: Controls whether the headers received by
this object are normalized according to the rules of RFC 7540.
Disabling this setting may lead to hyper-h2 emitting header blocks that
some RFCs forbid, e.g. with multiple cookie fields.
.. versionadded:: 3.0.0
:type normalize_inbound_headers: ``bool``
:param logger: A logger that conforms to the requirements for this module,
those being no I/O and no context switches, which is needed in order
to run in asynchronous operation.
.. versionadded:: 2.6.0
:type logger: ``logging.Logger``
"""
client_side = _BooleanConfigOption('client_side')
validate_outbound_headers = _BooleanConfigOption(
'validate_outbound_headers'
)
normalize_outbound_headers = _BooleanConfigOption(
'normalize_outbound_headers'
)
validate_inbound_headers = _BooleanConfigOption(
'validate_inbound_headers'
)
normalize_inbound_headers = _BooleanConfigOption(
'normalize_inbound_headers'
)

def __init__(self,
client_side=True,
header_encoding=None,
validate_outbound_headers=True,
normalize_outbound_headers=True,
validate_inbound_headers=True,
normalize_inbound_headers=True,
logger=None):
self.client_side = client_side
self.header_encoding = header_encoding
self.validate_outbound_headers = validate_outbound_headers
self.normalize_outbound_headers = normalize_outbound_headers
self.validate_inbound_headers = validate_inbound_headers
self.normalize_inbound_headers = normalize_inbound_headers
self.logger = logger or DummyLogger(__name__)

@property
def header_encoding(self):
"""
Controls whether the headers emitted by this object in events are
transparently decoded to ``unicode`` strings, and what encoding is used
to do that decoding. This defaults to ``None``, meaning that headers
will be returned as bytes. To automatically decode headers (that is, to
return them as unicode strings), this can be set to the string name of
any encoding, e.g. ``'utf-8'``.
"""
return self._header_encoding

@header_encoding.setter
def header_encoding(self, value):
"""
Enforces constraints on the value of header encoding.
"""
if not isinstance(value, (bool, str, type(None))):
raise ValueError("header_encoding must be bool, string, or None")
if value is True:
raise ValueError("header_encoding cannot be True")
self._header_encoding = value

0 comments on commit f43683c

Please sign in to comment.
You can’t perform that action at this time.