Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

203 righe
8.2 KiB

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