You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

193 line
7.8 KiB

  1. Metadata-Version: 2.0
  2. Name: h11
  3. Version: 0.8.1
  4. Summary: A pure-Python, bring-your-own-I/O implementation of HTTP/1.1
  5. Home-page: https://github.com/python-hyper/h11
  6. Author: Nathaniel J. Smith
  7. Author-email: njs@pobox.com
  8. License: MIT
  9. Platform: UNKNOWN
  10. Classifier: Development Status :: 3 - Alpha
  11. Classifier: Intended Audience :: Developers
  12. Classifier: License :: OSI Approved :: MIT License
  13. Classifier: Programming Language :: Python :: Implementation :: CPython
  14. Classifier: Programming Language :: Python :: Implementation :: PyPy
  15. Classifier: Programming Language :: Python :: 2
  16. Classifier: Programming Language :: Python :: 2.7
  17. Classifier: Programming Language :: Python :: 3
  18. Classifier: Programming Language :: Python :: 3.3
  19. Classifier: Programming Language :: Python :: 3.4
  20. Classifier: Programming Language :: Python :: 3.5
  21. Classifier: Topic :: Internet :: WWW/HTTP
  22. Classifier: Topic :: System :: Networking
  23. h11
  24. ===
  25. .. image:: https://travis-ci.org/python-hyper/h11.svg?branch=master
  26. :target: https://travis-ci.org/python-hyper/h11
  27. :alt: Automated test status
  28. .. image:: https://codecov.io/gh/python-hyper/h11/branch/master/graph/badge.svg
  29. :target: https://codecov.io/gh/python-hyper/h11
  30. :alt: Test coverage
  31. .. image:: https://readthedocs.org/projects/h11/badge/?version=latest
  32. :target: http://h11.readthedocs.io/en/latest/?badge=latest
  33. :alt: Documentation Status
  34. This is a little HTTP/1.1 library written from scratch in Python,
  35. heavily inspired by `hyper-h2 <https://hyper-h2.readthedocs.io/>`_.
  36. It's a "bring-your-own-I/O" library; h11 contains no IO code
  37. whatsoever. This means you can hook h11 up to your favorite network
  38. API, and that could be anything you want: synchronous, threaded,
  39. asynchronous, or your own implementation of `RFC 6214
  40. <https://tools.ietf.org/html/rfc6214>`_ -- h11 won't judge you.
  41. (Compare this to the current state of the art, where every time a `new
  42. network API <https://trio.readthedocs.io/>`_ comes along then someone
  43. gets to start over reimplementing the entire HTTP protocol from
  44. scratch.) Cory Benfield made an `excellent blog post describing the
  45. benefits of this approach
  46. <https://lukasa.co.uk/2015/10/The_New_Hyper/>`_, or if you like video
  47. then here's his `PyCon 2016 talk on the same theme
  48. <https://www.youtube.com/watch?v=7cC3_jGwl_U>`_.
  49. This also means that h11 is not immediately useful out of the box:
  50. it's a toolkit for building programs that speak HTTP, not something
  51. that could directly replace ``requests`` or ``twisted.web`` or
  52. whatever. But h11 makes it much easier to implement something like
  53. ``requests`` or ``twisted.web``.
  54. At a high level, working with h11 goes like this:
  55. 1) First, create an ``h11.Connection`` object to track the state of a
  56. single HTTP/1.1 connection.
  57. 2) When you read data off the network, pass it to
  58. ``conn.receive_data(...)``; you'll get back a list of objects
  59. representing high-level HTTP "events".
  60. 3) When you want to send a high-level HTTP event, create the
  61. corresponding "event" object and pass it to ``conn.send(...)``;
  62. this will give you back some bytes that you can then push out
  63. through the network.
  64. For example, a client might instantiate and then send a
  65. ``h11.Request`` object, then zero or more ``h11.Data`` objects for the
  66. request body (e.g., if this is a POST), and then a
  67. ``h11.EndOfMessage`` to indicate the end of the message. Then the
  68. server would then send back a ``h11.Response``, some ``h11.Data``, and
  69. its own ``h11.EndOfMessage``. If either side violates the protocol,
  70. you'll get a ``h11.ProtocolError`` exception.
  71. h11 is suitable for implementing both servers and clients, and has a
  72. pleasantly symmetric API: the events you send as a client are exactly
  73. the ones that you receive as a server and vice-versa.
  74. `Here's an example of a tiny HTTP client
  75. <https://github.com/python-hyper/h11/blob/master/examples/basic-client.py>`_
  76. It also has `a fine manual <https://h11.readthedocs.io/>`_.
  77. FAQ
  78. ---
  79. *Whyyyyy?*
  80. I wanted to play with HTTP in `Curio
  81. <https://curio.readthedocs.io/en/latest/tutorial.html>`__ and `Trio
  82. <https://trio.readthedocs.io>`__, which at the time didn't have any
  83. HTTP libraries. So I thought, no big deal, Python has, like, a dozen
  84. different implementations of HTTP, surely I can find one that's
  85. reusable. I didn't find one, but I did find Cory's call-to-arms
  86. blog-post. So I figured, well, fine, if I have to implement HTTP from
  87. scratch, at least I can make sure no-one *else* has to ever again.
  88. *Should I use it?*
  89. Maybe. You should be aware that it's a very young project. But, it's
  90. feature complete and has an exhaustive test-suite and complete docs,
  91. so the next step is for people to try using it and see how it goes
  92. :-). If you do then please let us know -- if nothing else we'll want
  93. to talk to you before making any incompatible changes!
  94. *What are the features/limitations?*
  95. Roughly speaking, it's trying to be a robust, complete, and non-hacky
  96. implementation of the first "chapter" of the HTTP/1.1 spec: `RFC 7230:
  97. HTTP/1.1 Message Syntax and Routing
  98. <https://tools.ietf.org/html/rfc7230>`_. That is, it mostly focuses on
  99. implementing HTTP at the level of taking bytes on and off the wire,
  100. and the headers related to that, and tries to be anal about spec
  101. conformance. It doesn't know about higher-level concerns like URL
  102. routing, conditional GETs, cross-origin cookie policies, or content
  103. negotiation. But it does know how to take care of framing,
  104. cross-version differences in keep-alive handling, and the "obsolete
  105. line folding" rule, so you can focus your energies on the hard /
  106. interesting parts for your application, and it tries to support the
  107. full specification in the sense that any useful HTTP/1.1 conformant
  108. application should be able to use h11.
  109. It's pure Python, and has no dependencies outside of the standard
  110. library.
  111. It has a test suite with 100.0% coverage for both statements and
  112. branches.
  113. Currently it supports Python 3 (testing on 3.3-3.6), Python 2.7, and PyPy.
  114. (Originally it had a Cython wrapper for `http-parser
  115. <https://github.com/nodejs/http-parser>`_ and a beautiful nested state
  116. machine implemented with ``yield from`` to postprocess the output. But
  117. I had to take these out -- the new *parser* needs fewer lines-of-code
  118. than the old *parser wrapper*, is written in pure Python, uses no
  119. exotic language syntax, and has more features. It's sad, really; that
  120. old state machine was really slick. I just need a few sentences here
  121. to mourn that.)
  122. I don't know how fast it is. I haven't benchmarked or profiled it yet,
  123. so it's probably got a few pointless hot spots, and I've been trying
  124. to err on the side of simplicity and robustness instead of
  125. micro-optimization. But at the architectural level I tried hard to
  126. avoid fundamentally bad decisions, e.g., I believe that all the
  127. parsing algorithms remain linear-time even in the face of pathological
  128. input like slowloris, and there are no byte-by-byte loops. (I also
  129. believe that it maintains bounded memory usage in the face of
  130. arbitrary/pathological input.)
  131. The whole library is ~800 lines-of-code. You can read and understand
  132. the whole thing in less than an hour. Most of the energy invested in
  133. this so far has been spent on trying to keep things simple by
  134. minimizing special-cases and ad hoc state manipulation; even though it
  135. is now quite small and simple, I'm still annoyed that I haven't
  136. figured out how to make it even smaller and simpler. (Unfortunately,
  137. HTTP does not lend itself to simplicity.)
  138. The API is ~feature complete and I don't expect the general outlines
  139. to change much, but you can't judge an API's ergonomics until you
  140. actually document and use it, so I'd expect some changes in the
  141. details.
  142. *How do I try it?*
  143. .. code-block:: sh
  144. $ pip install h11
  145. $ git clone git@github.com:python-hyper/h11
  146. $ cd h11/examples
  147. $ python basic-client.py
  148. and go from there.
  149. *License?*
  150. MIT
  151. *Code of conduct?*
  152. Contributors are requested to follow our `code of conduct
  153. <https://github.com/python-hyper/h11/blob/master/CODE_OF_CONDUCT.md>`_ in
  154. all project spaces.