httoop 0.2.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. {httoop-0.2.0 → httoop-0.2.2}/PKG-INFO +71 -29
  2. {httoop-0.2.0 → httoop-0.2.2}/README.md +68 -21
  3. {httoop-0.2.0 → httoop-0.2.2}/httoop/__init__.py +8 -10
  4. {httoop-0.2.0 → httoop-0.2.2}/httoop/__main__.py +20 -13
  5. {httoop-0.2.0 → httoop-0.2.2}/httoop/authentication/__init__.py +15 -11
  6. {httoop-0.2.0 → httoop-0.2.2}/httoop/authentication/basic.py +10 -11
  7. {httoop-0.2.0 → httoop-0.2.2}/httoop/authentication/digest.py +56 -31
  8. httoop-0.2.2/httoop/client/__init__.py +35 -0
  9. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/__init__.py +1 -1
  10. httoop-0.2.2/httoop/codecs/application/gzip.py +69 -0
  11. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/application/hal_json.py +5 -5
  12. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/application/json.py +2 -4
  13. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/application/x_www_form_urlencoded.py +1 -2
  14. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/application/xml.py +2 -2
  15. httoop-0.2.2/httoop/codecs/application/zlib.py +56 -0
  16. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/codec.py +5 -3
  17. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/message/http.py +1 -1
  18. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/multipart/multipart.py +2 -3
  19. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/text/plain.py +4 -4
  20. {httoop-0.2.0 → httoop-0.2.2}/httoop/date.py +17 -38
  21. {httoop-0.2.0 → httoop-0.2.2}/httoop/exceptions.py +9 -1
  22. {httoop-0.2.0 → httoop-0.2.2}/httoop/gateway/wsgi.py +14 -7
  23. {httoop-0.2.0 → httoop-0.2.2}/httoop/header/__init__.py +2 -4
  24. {httoop-0.2.0 → httoop-0.2.2}/httoop/header/cache.py +1 -1
  25. {httoop-0.2.0 → httoop-0.2.2}/httoop/header/conditional.py +5 -3
  26. {httoop-0.2.0 → httoop-0.2.2}/httoop/header/element.py +70 -42
  27. {httoop-0.2.0 → httoop-0.2.2}/httoop/header/headers.py +49 -34
  28. {httoop-0.2.0 → httoop-0.2.2}/httoop/header/messaging.py +35 -14
  29. {httoop-0.2.0 → httoop-0.2.2}/httoop/header/ranges.py +11 -9
  30. {httoop-0.2.0 → httoop-0.2.2}/httoop/header/security.py +4 -4
  31. {httoop-0.2.0 → httoop-0.2.2}/httoop/messages/body.py +14 -8
  32. {httoop-0.2.0 → httoop-0.2.2}/httoop/messages/method.py +3 -3
  33. {httoop-0.2.0 → httoop-0.2.2}/httoop/messages/protocol.py +8 -5
  34. {httoop-0.2.0 → httoop-0.2.2}/httoop/messages/request.py +1 -1
  35. {httoop-0.2.0 → httoop-0.2.2}/httoop/messages/response.py +1 -1
  36. {httoop-0.2.0 → httoop-0.2.2}/httoop/meta.py +1 -1
  37. {httoop-0.2.0 → httoop-0.2.2}/httoop/parser.py +82 -27
  38. {httoop-0.2.0 → httoop-0.2.2}/httoop/semantic/message.py +16 -1
  39. {httoop-0.2.0 → httoop-0.2.2}/httoop/semantic/request.py +1 -0
  40. {httoop-0.2.0 → httoop-0.2.2}/httoop/semantic/response.py +3 -1
  41. {httoop-0.2.0 → httoop-0.2.2}/httoop/server/__init__.py +16 -8
  42. {httoop-0.2.0 → httoop-0.2.2}/httoop/status/__init__.py +1 -1
  43. {httoop-0.2.0 → httoop-0.2.2}/httoop/status/client_error.py +1 -1
  44. {httoop-0.2.0 → httoop-0.2.2}/httoop/status/status.py +4 -3
  45. {httoop-0.2.0 → httoop-0.2.2}/httoop/status/types.py +2 -2
  46. {httoop-0.2.0 → httoop-0.2.2}/httoop/uri/percent_encoding.py +12 -11
  47. {httoop-0.2.0 → httoop-0.2.2}/httoop/uri/uri.py +21 -19
  48. {httoop-0.2.0 → httoop-0.2.2}/httoop/util.py +70 -12
  49. {httoop-0.2.0 → httoop-0.2.2}/httoop/version.py +1 -1
  50. {httoop-0.2.0 → httoop-0.2.2}/httoop.egg-info/PKG-INFO +71 -29
  51. httoop-0.2.2/httoop.egg-info/requires.txt +7 -0
  52. {httoop-0.2.0 → httoop-0.2.2}/pyproject.toml +70 -3
  53. httoop-0.2.0/httoop/client/__init__.py +0 -16
  54. httoop-0.2.0/httoop/codecs/application/gzip.py +0 -65
  55. httoop-0.2.0/httoop/codecs/application/zlib.py +0 -26
  56. httoop-0.2.0/httoop.egg-info/requires.txt +0 -12
  57. {httoop-0.2.0 → httoop-0.2.2}/LICENSE +0 -0
  58. {httoop-0.2.0 → httoop-0.2.2}/httoop/cache/__init__.py +0 -0
  59. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/application/__init__.py +0 -0
  60. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/audio/__init__.py +0 -0
  61. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/example/__init__.py +0 -0
  62. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/image/__init__.py +0 -0
  63. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/message/__init__.py +0 -0
  64. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/model/__init__.py +0 -0
  65. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/multipart/__init__.py +0 -0
  66. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/text/__init__.py +0 -0
  67. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/text/html.py +0 -0
  68. {httoop-0.2.0 → httoop-0.2.2}/httoop/codecs/video/__init__.py +0 -0
  69. {httoop-0.2.0 → httoop-0.2.2}/httoop/gateway/__init__.py +0 -0
  70. {httoop-0.2.0 → httoop-0.2.2}/httoop/header/auth.py +0 -0
  71. {httoop-0.2.0 → httoop-0.2.2}/httoop/messages/__init__.py +0 -0
  72. {httoop-0.2.0 → httoop-0.2.2}/httoop/messages/message.py +0 -0
  73. {httoop-0.2.0 → httoop-0.2.2}/httoop/proxy/__init__.py +0 -0
  74. {httoop-0.2.0 → httoop-0.2.2}/httoop/semantic/__init__.py +0 -0
  75. {httoop-0.2.0 → httoop-0.2.2}/httoop/status/informational.py +0 -0
  76. {httoop-0.2.0 → httoop-0.2.2}/httoop/status/redirect.py +0 -0
  77. {httoop-0.2.0 → httoop-0.2.2}/httoop/status/server_error.py +0 -0
  78. {httoop-0.2.0 → httoop-0.2.2}/httoop/status/success.py +0 -0
  79. {httoop-0.2.0 → httoop-0.2.2}/httoop/uri/__init__.py +0 -0
  80. {httoop-0.2.0 → httoop-0.2.2}/httoop/uri/http.py +0 -0
  81. {httoop-0.2.0 → httoop-0.2.2}/httoop/uri/query_string.py +0 -0
  82. {httoop-0.2.0 → httoop-0.2.2}/httoop/uri/schemes.py +0 -0
  83. {httoop-0.2.0 → httoop-0.2.2}/httoop.egg-info/SOURCES.txt +0 -0
  84. {httoop-0.2.0 → httoop-0.2.2}/httoop.egg-info/dependency_links.txt +0 -0
  85. {httoop-0.2.0 → httoop-0.2.2}/httoop.egg-info/top_level.txt +0 -0
  86. {httoop-0.2.0 → httoop-0.2.2}/httoop.egg-info/zip-safe +0 -0
  87. {httoop-0.2.0 → httoop-0.2.2}/setup.cfg +0 -0
  88. {httoop-0.2.0 → httoop-0.2.2}/tests/test_cli.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: httoop
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: object oriented HTTP protocol library
5
5
  Author-email: SpaceOne <space@wechall.net>
6
6
  License: MIT
@@ -14,7 +14,6 @@ Classifier: Operating System :: POSIX :: BSD
14
14
  Classifier: Operating System :: POSIX :: Linux
15
15
  Classifier: Operating System :: MacOS :: MacOS X
16
16
  Classifier: Operating System :: Microsoft :: Windows
17
- Classifier: Programming Language :: Python :: 3.8
18
17
  Classifier: Programming Language :: Python :: 3.9
19
18
  Classifier: Programming Language :: Python :: 3.10
20
19
  Classifier: Programming Language :: Python :: 3.11
@@ -27,18 +26,14 @@ Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware
27
26
  Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Server
28
27
  Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
29
28
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
30
- Requires-Python: >=3.8
29
+ Requires-Python: >=3.9
31
30
  Description-Content-Type: text/markdown
32
31
  License-File: LICENSE
32
+ Requires-Dist: typing_extensions>=4.4
33
33
  Provides-Extra: xml
34
34
  Requires-Dist: defusedxml; extra == "xml"
35
35
  Provides-Extra: hal
36
36
  Requires-Dist: uritemplate; extra == "hal"
37
- Provides-Extra: test
38
- Requires-Dist: pytest; extra == "test"
39
- Requires-Dist: pytest-cov; extra == "test"
40
- Requires-Dist: coveralls; extra == "test"
41
- Requires-Dist: defusedxml; extra == "test"
42
37
  Dynamic: license-file
43
38
 
44
39
  [![Build Status](https://github.com/spaceone/httoop/actions/workflows/ci.yml/badge.svg)](https://github.com/spaceone/httoop/actions/workflows/ci.yml)
@@ -49,36 +44,46 @@ Dynamic: license-file
49
44
  httoop
50
45
  ======
51
46
 
52
- An object oriented HTTP/1.1 library. (HTTP/2 will probably follow in the future).
47
+ An object-oriented HTTP/1.x protocol library for Python.
53
48
 
54
- Httoop can be used to parse, compose and work with HTTP-Request- and Response-Messages.
49
+ Httoop is for applications that need to understand HTTP, not merely send a request.
50
+ It parses and composes requests and responses, and gives every important part of a message a useful object: methods, URIs, protocols, headers, statuses, and bodies.
51
+ The same model can be used to build protocol-aware clients, servers, gateways, middleware, caches, and proxies.
55
52
 
56
- It is an generic library for implementing HTTP servers, clients, caches and proxies.
53
+ ## Why httoop?
57
54
 
58
- Httoop provides an powerful interface using the vocabularity used in RFC 7230 - 7235 and focuses on implementing HTTP "compliant" as defined in [RFC 7230 Section 2.5](https://datatracker.ietf.org/doc/html/rfc7230#section-2.5).
55
+ Most HTTP libraries make the network convenient by hiding the protocol.
56
+ Httoop takes a different approach: it makes the protocol convenient to work with.
57
+ You can inspect, validate, transform, and re-compose a message without dropping down to ad-hoc string manipulation or abandoning the HTTP wire format.
59
58
 
60
- "An implementation is not compliant if it fails to satisfy one or more of the MUST or REQUIRED level requirements for the protocols it implements."
61
- [RFC 2616 Section 1.2](https://datatracker.ietf.org/doc/html/rfc2616#section-1.2)
59
+ * **One coherent object model.** HTTP values share a small semantic interface: they can be parsed, composed, converted to bytes, compared, and represented consistently.
60
+ * **Incremental by design.** The state-machine parser accepts fragmented input, supports pipelined messages, handles fixed-length and chunked bodies, and preserves trailers.
61
+ * **Structured instead of stringly typed.** Headers and URIs expose parsed components, parameters, normalization, joining, and validation. Cookies, ranges, content types, dates, authentication fields, and security headers do not need to be hand-parsed.
62
+ * **Streaming without special cases.** A body can be bytes, text, a file, a file-like object, or an iterable. The same body abstraction handles content encoding, transfer encoding, chunking, and limits.
63
+ * **Protocol-aware composition.** Request and response preparation takes care of HTTP details such as `Host`, `Content-Length`, `Date`, connection semantics, bodyless statuses, `HEAD`, and byte ranges.
64
+ * **Safe boundaries for untrusted input.** Header counts and sizes, URI lengths, body sizes, and decompressed body sizes can be bounded explicitly, while malformed framing and invalid fields are rejected.
65
+ * **Designed to be extended.** New header elements, URI schemes, statuses, and media codecs can be registered and used through the same interfaces as the built-ins.
66
+ * **Integration where it matters.** WSGI support provides a bridge to existing Python web applications without requiring a second message representation.
62
67
 
63
- On top of the object oriented abstraction of HTTP httoop provides an easy way to support WSGI.
68
+ ## The Zen of httoop
64
69
 
70
+ Httoop follows a few simple principles:
65
71
 
66
- HTTP and extensions are defined in the following RFC's:
67
-
68
- * HTTP/1.1 RFC 7230 [Message Syntax and Routing](https://datatracker.ietf.org/doc/html/rfc7230)
72
+ 1. **Model HTTP as meaning, not as text.** Wire bytes are an input and output format; inside the application, HTTP should be represented by objects with explicit semantics.
73
+ 2. **Separate syntax, semantics, and transport.** Parsing answers "is this a valid message?", composition answers "what should this message mean on the wire?", and adapters answer "where does it run?". Each layer can evolve independently.
74
+ 3. **Make the wire visible when it matters.** Httoop does not hide framing, headers, status codes, encodings, or protocol versions. This makes unusual HTTP behavior possible to inspect and reason about.
75
+ 4. **Treat partial input and large bodies as normal.** Streaming, buffering, pipelining, and resource limits are part of the model rather than afterthoughts.
76
+ 5. **Prefer composition over special-purpose APIs.** The same `Request`, `Response`, `Headers`, `URI`, and `Body` objects work across clients, servers, gateways, and middleware.
77
+ 6. **Extend by adding knowledge, not by rewriting the core.** Protocol extensions plug into registries and semantic types instead of requiring changes throughout the parser.
69
78
 
70
- * HTTP/1.1 RFC 7231 [Semantics and Content](https://datatracker.ietf.org/doc/html/rfc7231)
79
+ ## HTTP standards
71
80
 
72
- * HTTP/1.1 RFC 7232 [Conditional Requests](https://datatracker.ietf.org/doc/html/rfc7232)
81
+ HTTP and extensions are defined in the following RFC's:
73
82
 
74
- * HTTP/1.1 RFC 7233 [Range Requests](https://datatracker.ietf.org/doc/html/rfc7233)
83
+ * [RFC 9110 HTTP Semantics](https://datatracker.ietf.org/doc/html/rfc9110)
75
84
 
76
85
  * HTTP/1.1 RFC 7234 [Caching](https://datatracker.ietf.org/doc/html/rfc7234)
77
86
 
78
- * HTTP/1.1 RFC 7235 [Authentication](https://datatracker.ietf.org/doc/html/rfc7235)
79
-
80
- * <s>Hypertext Transfer Protocol -- HTTP/1.1 ([RFC 2616](https://datatracker.ietf.org/doc/html/rfc2616)) </s>
81
-
82
87
  * HTTP/2 RFC 7540 [Hypertext Transfer Protocol Version 2](https://datatracker.ietf.org/doc/html/rfc7540)
83
88
 
84
89
  * HTTP/2 RFC 7541 [HPACK: Header Compression for HTTP/2](https://datatracker.ietf.org/doc/html/rfc7541)
@@ -101,10 +106,6 @@ HTTP and extensions are defined in the following RFC's:
101
106
 
102
107
  * Internet Message Format ([RFC 822](https://datatracker.ietf.org/doc/html/rfc822), [2822](https://datatracker.ietf.org/doc/html/rfc2822), [5322](https://datatracker.ietf.org/doc/html/rfc5322))
103
108
 
104
- * <s>HTTP Authentication: Basic and Digest Access Authentication ([RFC 2617](https://datatracker.ietf.org/doc/html/rfc2617))</s>
105
-
106
- * HTTP Authentication-Info and Proxy-Authentication-Info Response Header Fields ([RFC 7615](https://datatracker.ietf.org/doc/html/rfc7615))
107
-
108
109
  * HTTP Digest Access Authentication ([RFC 7616](https://datatracker.ietf.org/doc/html/rfc7616))
109
110
 
110
111
  * The 'Basic' HTTP Authentication Scheme ([RFC 7617](https://datatracker.ietf.org/doc/html/rfc7617))
@@ -119,6 +120,8 @@ HTTP and extensions are defined in the following RFC's:
119
120
 
120
121
  * JavaScript Object Notation (JSON) Patch ([RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902))
121
122
 
123
+ * The HTTP QUERY Method ([RFC 10008](https://datatracker.ietf.org/doc/html/rfc10008))
124
+
122
125
  * Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP) ([RFC 6266](https://datatracker.ietf.org/doc/html/rfc6266))
123
126
 
124
127
  * Upgrading to TLS Within HTTP/1.1 ([RFC 2817](https://datatracker.ietf.org/doc/html/rfc2817))
@@ -155,6 +158,34 @@ Extended information about hypermedia, WWW and how HTTP is meant to be used:
155
158
 
156
159
  * [Economies of scale](https://roy.gbiv.com/untangled/2008/economies-of-scale)
157
160
 
161
+ Clarifications of misconceptions people have about REST:
162
+
163
+ * [Do You Really Understand the REST?](https://t-code.pl/blog/2016/02/rest-misconceptions-0/)
164
+
165
+ * [the URI Confusion](https://t-code.pl/blog/2016/02/rest-misconceptions-1/)
166
+
167
+ * [(Not) Linking Data (Enough)](https://t-code.pl/blog/2016/02/rest-misconceptions-2/)
168
+
169
+ * [More Than Links](https://t-code.pl/blog/2016/03/rest-misconceptions-3/)
170
+
171
+ * [Resources Are Application State](https://t-code.pl/blog/2016/03/rest-misconceptions-4/)
172
+
173
+ * [REST "Documentation"](https://t-code.pl/blog/2016/03/rest-misconceptions-5/)
174
+
175
+ * [Versioning and Hypermedia](https://t-code.pl/blog/2016/03/rest-misconceptions-6/)
176
+
177
+ * [HATEOAS as if You Meant It](https://t-code.pl/blog/2015/01/hateoas-as-if-you-meant-it/)
178
+
179
+ * [The Labours of Hypermedia](https://t-code.pl/blog/2016/04/labours-of-hypermedia/)
180
+
181
+ * [Hypermedia must be extensible - Extensible Media Types](https://t-code.pl/blog/2016/04/hypermedia-must-be-extensible/)
182
+
183
+ * [Consuming Hypermedia - Declarative UI](https://t-code.pl/blog/2016/04/hypermedia-driven-ui/)
184
+
185
+ * [Towards Server-side Routing With URI Templates (RFC 6570)](https://t-code.pl/blog/2016/11/towards-server-side-routing-with-uri-templates/)
186
+
187
+ * [Testing APIs Hypermedia-style](https://t-code.pl/blog/2019/06/testing-hypermedia-api/)
188
+
158
189
  * [Richardson Maturity Model](https://martinfowler.com/articles/richardsonMaturityModel.html)
159
190
 
160
191
  * [Test Cases for HTTP Content-Disposition header field](http://greenbytes.de/tech/tc2231/)
@@ -172,3 +203,14 @@ OAuth 2.0:
172
203
  * [JSON Web Token (JWT)](https://datatracker.ietf.org/doc/html/rfc7519)
173
204
  * [JSON Web Token (JWT) Profile for OAuth 2.0 Access Tokens](https://datatracker.ietf.org/doc/html/rfc9068)
174
205
  * [Resource Indicators for OAuth 2.0](https://datatracker.ietf.org/doc/html/rfc8707)
206
+
207
+ Obsolete:
208
+
209
+ * <s>HTTP/1.1 RFC 7230 [Message Syntax and Routing](https://datatracker.ietf.org/doc/html/rfc7230)</s>
210
+ * <s>HTTP/1.1 RFC 7231 [Semantics and Content](https://datatracker.ietf.org/doc/html/rfc7231)</s>
211
+ * <s>HTTP/1.1 RFC 7232 [Conditional Requests](https://datatracker.ietf.org/doc/html/rfc7232)</s>
212
+ * <s>HTTP/1.1 RFC 7233 [Range Requests](https://datatracker.ietf.org/doc/html/rfc7233)</s>
213
+ * <s>HTTP/1.1 RFC 7235 [Authentication](https://datatracker.ietf.org/doc/html/rfc7235)</s>
214
+ * <s>Hypertext Transfer Protocol -- HTTP/1.1 ([RFC 2616](https://datatracker.ietf.org/doc/html/rfc2616)) </s>
215
+ * <s>HTTP Authentication: Basic and Digest Access Authentication ([RFC 2617](https://datatracker.ietf.org/doc/html/rfc2617))</s>
216
+ * <s>HTTP Authentication-Info and Proxy-Authentication-Info Response Header Fields ([RFC 7615](https://datatracker.ietf.org/doc/html/rfc7615))</s>
@@ -6,36 +6,46 @@
6
6
  httoop
7
7
  ======
8
8
 
9
- An object oriented HTTP/1.1 library. (HTTP/2 will probably follow in the future).
9
+ An object-oriented HTTP/1.x protocol library for Python.
10
10
 
11
- Httoop can be used to parse, compose and work with HTTP-Request- and Response-Messages.
11
+ Httoop is for applications that need to understand HTTP, not merely send a request.
12
+ It parses and composes requests and responses, and gives every important part of a message a useful object: methods, URIs, protocols, headers, statuses, and bodies.
13
+ The same model can be used to build protocol-aware clients, servers, gateways, middleware, caches, and proxies.
12
14
 
13
- It is an generic library for implementing HTTP servers, clients, caches and proxies.
15
+ ## Why httoop?
14
16
 
15
- Httoop provides an powerful interface using the vocabularity used in RFC 7230 - 7235 and focuses on implementing HTTP "compliant" as defined in [RFC 7230 Section 2.5](https://datatracker.ietf.org/doc/html/rfc7230#section-2.5).
17
+ Most HTTP libraries make the network convenient by hiding the protocol.
18
+ Httoop takes a different approach: it makes the protocol convenient to work with.
19
+ You can inspect, validate, transform, and re-compose a message without dropping down to ad-hoc string manipulation or abandoning the HTTP wire format.
16
20
 
17
- "An implementation is not compliant if it fails to satisfy one or more of the MUST or REQUIRED level requirements for the protocols it implements."
18
- [RFC 2616 Section 1.2](https://datatracker.ietf.org/doc/html/rfc2616#section-1.2)
21
+ * **One coherent object model.** HTTP values share a small semantic interface: they can be parsed, composed, converted to bytes, compared, and represented consistently.
22
+ * **Incremental by design.** The state-machine parser accepts fragmented input, supports pipelined messages, handles fixed-length and chunked bodies, and preserves trailers.
23
+ * **Structured instead of stringly typed.** Headers and URIs expose parsed components, parameters, normalization, joining, and validation. Cookies, ranges, content types, dates, authentication fields, and security headers do not need to be hand-parsed.
24
+ * **Streaming without special cases.** A body can be bytes, text, a file, a file-like object, or an iterable. The same body abstraction handles content encoding, transfer encoding, chunking, and limits.
25
+ * **Protocol-aware composition.** Request and response preparation takes care of HTTP details such as `Host`, `Content-Length`, `Date`, connection semantics, bodyless statuses, `HEAD`, and byte ranges.
26
+ * **Safe boundaries for untrusted input.** Header counts and sizes, URI lengths, body sizes, and decompressed body sizes can be bounded explicitly, while malformed framing and invalid fields are rejected.
27
+ * **Designed to be extended.** New header elements, URI schemes, statuses, and media codecs can be registered and used through the same interfaces as the built-ins.
28
+ * **Integration where it matters.** WSGI support provides a bridge to existing Python web applications without requiring a second message representation.
19
29
 
20
- On top of the object oriented abstraction of HTTP httoop provides an easy way to support WSGI.
30
+ ## The Zen of httoop
21
31
 
32
+ Httoop follows a few simple principles:
22
33
 
23
- HTTP and extensions are defined in the following RFC's:
24
-
25
- * HTTP/1.1 RFC 7230 [Message Syntax and Routing](https://datatracker.ietf.org/doc/html/rfc7230)
34
+ 1. **Model HTTP as meaning, not as text.** Wire bytes are an input and output format; inside the application, HTTP should be represented by objects with explicit semantics.
35
+ 2. **Separate syntax, semantics, and transport.** Parsing answers "is this a valid message?", composition answers "what should this message mean on the wire?", and adapters answer "where does it run?". Each layer can evolve independently.
36
+ 3. **Make the wire visible when it matters.** Httoop does not hide framing, headers, status codes, encodings, or protocol versions. This makes unusual HTTP behavior possible to inspect and reason about.
37
+ 4. **Treat partial input and large bodies as normal.** Streaming, buffering, pipelining, and resource limits are part of the model rather than afterthoughts.
38
+ 5. **Prefer composition over special-purpose APIs.** The same `Request`, `Response`, `Headers`, `URI`, and `Body` objects work across clients, servers, gateways, and middleware.
39
+ 6. **Extend by adding knowledge, not by rewriting the core.** Protocol extensions plug into registries and semantic types instead of requiring changes throughout the parser.
26
40
 
27
- * HTTP/1.1 RFC 7231 [Semantics and Content](https://datatracker.ietf.org/doc/html/rfc7231)
41
+ ## HTTP standards
28
42
 
29
- * HTTP/1.1 RFC 7232 [Conditional Requests](https://datatracker.ietf.org/doc/html/rfc7232)
43
+ HTTP and extensions are defined in the following RFC's:
30
44
 
31
- * HTTP/1.1 RFC 7233 [Range Requests](https://datatracker.ietf.org/doc/html/rfc7233)
45
+ * [RFC 9110 HTTP Semantics](https://datatracker.ietf.org/doc/html/rfc9110)
32
46
 
33
47
  * HTTP/1.1 RFC 7234 [Caching](https://datatracker.ietf.org/doc/html/rfc7234)
34
48
 
35
- * HTTP/1.1 RFC 7235 [Authentication](https://datatracker.ietf.org/doc/html/rfc7235)
36
-
37
- * <s>Hypertext Transfer Protocol -- HTTP/1.1 ([RFC 2616](https://datatracker.ietf.org/doc/html/rfc2616)) </s>
38
-
39
49
  * HTTP/2 RFC 7540 [Hypertext Transfer Protocol Version 2](https://datatracker.ietf.org/doc/html/rfc7540)
40
50
 
41
51
  * HTTP/2 RFC 7541 [HPACK: Header Compression for HTTP/2](https://datatracker.ietf.org/doc/html/rfc7541)
@@ -58,10 +68,6 @@ HTTP and extensions are defined in the following RFC's:
58
68
 
59
69
  * Internet Message Format ([RFC 822](https://datatracker.ietf.org/doc/html/rfc822), [2822](https://datatracker.ietf.org/doc/html/rfc2822), [5322](https://datatracker.ietf.org/doc/html/rfc5322))
60
70
 
61
- * <s>HTTP Authentication: Basic and Digest Access Authentication ([RFC 2617](https://datatracker.ietf.org/doc/html/rfc2617))</s>
62
-
63
- * HTTP Authentication-Info and Proxy-Authentication-Info Response Header Fields ([RFC 7615](https://datatracker.ietf.org/doc/html/rfc7615))
64
-
65
71
  * HTTP Digest Access Authentication ([RFC 7616](https://datatracker.ietf.org/doc/html/rfc7616))
66
72
 
67
73
  * The 'Basic' HTTP Authentication Scheme ([RFC 7617](https://datatracker.ietf.org/doc/html/rfc7617))
@@ -76,6 +82,8 @@ HTTP and extensions are defined in the following RFC's:
76
82
 
77
83
  * JavaScript Object Notation (JSON) Patch ([RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902))
78
84
 
85
+ * The HTTP QUERY Method ([RFC 10008](https://datatracker.ietf.org/doc/html/rfc10008))
86
+
79
87
  * Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP) ([RFC 6266](https://datatracker.ietf.org/doc/html/rfc6266))
80
88
 
81
89
  * Upgrading to TLS Within HTTP/1.1 ([RFC 2817](https://datatracker.ietf.org/doc/html/rfc2817))
@@ -112,6 +120,34 @@ Extended information about hypermedia, WWW and how HTTP is meant to be used:
112
120
 
113
121
  * [Economies of scale](https://roy.gbiv.com/untangled/2008/economies-of-scale)
114
122
 
123
+ Clarifications of misconceptions people have about REST:
124
+
125
+ * [Do You Really Understand the REST?](https://t-code.pl/blog/2016/02/rest-misconceptions-0/)
126
+
127
+ * [the URI Confusion](https://t-code.pl/blog/2016/02/rest-misconceptions-1/)
128
+
129
+ * [(Not) Linking Data (Enough)](https://t-code.pl/blog/2016/02/rest-misconceptions-2/)
130
+
131
+ * [More Than Links](https://t-code.pl/blog/2016/03/rest-misconceptions-3/)
132
+
133
+ * [Resources Are Application State](https://t-code.pl/blog/2016/03/rest-misconceptions-4/)
134
+
135
+ * [REST "Documentation"](https://t-code.pl/blog/2016/03/rest-misconceptions-5/)
136
+
137
+ * [Versioning and Hypermedia](https://t-code.pl/blog/2016/03/rest-misconceptions-6/)
138
+
139
+ * [HATEOAS as if You Meant It](https://t-code.pl/blog/2015/01/hateoas-as-if-you-meant-it/)
140
+
141
+ * [The Labours of Hypermedia](https://t-code.pl/blog/2016/04/labours-of-hypermedia/)
142
+
143
+ * [Hypermedia must be extensible - Extensible Media Types](https://t-code.pl/blog/2016/04/hypermedia-must-be-extensible/)
144
+
145
+ * [Consuming Hypermedia - Declarative UI](https://t-code.pl/blog/2016/04/hypermedia-driven-ui/)
146
+
147
+ * [Towards Server-side Routing With URI Templates (RFC 6570)](https://t-code.pl/blog/2016/11/towards-server-side-routing-with-uri-templates/)
148
+
149
+ * [Testing APIs Hypermedia-style](https://t-code.pl/blog/2019/06/testing-hypermedia-api/)
150
+
115
151
  * [Richardson Maturity Model](https://martinfowler.com/articles/richardsonMaturityModel.html)
116
152
 
117
153
  * [Test Cases for HTTP Content-Disposition header field](http://greenbytes.de/tech/tc2231/)
@@ -129,3 +165,14 @@ OAuth 2.0:
129
165
  * [JSON Web Token (JWT)](https://datatracker.ietf.org/doc/html/rfc7519)
130
166
  * [JSON Web Token (JWT) Profile for OAuth 2.0 Access Tokens](https://datatracker.ietf.org/doc/html/rfc9068)
131
167
  * [Resource Indicators for OAuth 2.0](https://datatracker.ietf.org/doc/html/rfc8707)
168
+
169
+ Obsolete:
170
+
171
+ * <s>HTTP/1.1 RFC 7230 [Message Syntax and Routing](https://datatracker.ietf.org/doc/html/rfc7230)</s>
172
+ * <s>HTTP/1.1 RFC 7231 [Semantics and Content](https://datatracker.ietf.org/doc/html/rfc7231)</s>
173
+ * <s>HTTP/1.1 RFC 7232 [Conditional Requests](https://datatracker.ietf.org/doc/html/rfc7232)</s>
174
+ * <s>HTTP/1.1 RFC 7233 [Range Requests](https://datatracker.ietf.org/doc/html/rfc7233)</s>
175
+ * <s>HTTP/1.1 RFC 7235 [Authentication](https://datatracker.ietf.org/doc/html/rfc7235)</s>
176
+ * <s>Hypertext Transfer Protocol -- HTTP/1.1 ([RFC 2616](https://datatracker.ietf.org/doc/html/rfc2616)) </s>
177
+ * <s>HTTP Authentication: Basic and Digest Access Authentication ([RFC 2617](https://datatracker.ietf.org/doc/html/rfc2617))</s>
178
+ * <s>HTTP Authentication-Info and Proxy-Authentication-Info Response Header Fields ([RFC 7615](https://datatracker.ietf.org/doc/html/rfc7615))</s>
@@ -18,6 +18,7 @@ from httoop.status import (
18
18
  BAD_GATEWAY,
19
19
  BAD_REQUEST,
20
20
  CONFLICT,
21
+ CONTENT_TOO_LARGE,
21
22
  CONTINUE,
22
23
  CREATED,
23
24
  EXPECTATION_FAILED,
@@ -40,7 +41,6 @@ from httoop.status import (
40
41
  NOT_MODIFIED,
41
42
  OK,
42
43
  PARTIAL_CONTENT,
43
- PAYLOAD_TOO_LARGE,
44
44
  PAYMENT_REQUIRED,
45
45
  PRECONDITION_FAILED,
46
46
  PROXY_AUTHENTICATION_REQUIRED,
@@ -64,14 +64,12 @@ from httoop.version import ServerHeader, ServerProtocol, UserAgentHeader, __vers
64
64
 
65
65
 
66
66
  __all__ = [
67
- 'ACCEPTED', 'BAD_GATEWAY', 'BAD_REQUEST', 'CONFLICT', 'CONTINUE', 'CREATED', 'EXPECTATION_FAILED', 'FORBIDDEN', 'FOUND', 'GATEWAY_TIMEOUT',
68
- 'GONE', 'HTTP_VERSION_NOT_SUPPORTED', 'INTERNAL_SERVER_ERROR', 'I_AM_A_TEAPOT', 'LENGTH_REQUIRED', 'METHOD_NOT_ALLOWED', 'MOVED_PERMANENTLY',
69
- 'MULTIPLE_CHOICES', 'NON_AUTHORITATIVE_INFORMATION', 'NOT_ACCEPTABLE', 'NOT_FOUND', 'NOT_IMPLEMENTED', 'NOT_MODIFIED', 'NO_CONTENT', 'OK',
70
- 'PARTIAL_CONTENT', 'PAYLOAD_TOO_LARGE', 'PAYMENT_REQUIRED', 'PRECONDITION_FAILED', 'PROXY_AUTHENTICATION_REQUIRED', 'RANGE_NOT_SATISFIABLE',
71
- 'REQUEST_TIMEOUT', 'RESET_CONTENT', 'SEE_OTHER', 'SERVICE_UNAVAILABLE', 'SWITCHING_PROTOCOLS', 'TEMPORARY_REDIRECT', 'UNAUTHORIZED',
72
- 'UNPROCESSABLE_ENTITY', 'UNSUPPORTED_MEDIA_TYPE', 'URI', 'URI_TOO_LONG', 'USE_PROXY',
73
- 'Body', 'ClientStateMachine', 'ComposedRequest', 'ComposedResponse', 'Date', 'DecodeError', 'EncodeError', 'Headers',
74
- 'InvalidBody', 'InvalidDate', 'InvalidHeader', 'InvalidLine', 'InvalidURI',
75
- 'Method', 'Protocol', 'ProxyStateMachine', 'Request', 'Response', 'ServerHeader', 'ServerProtocol', 'ServerStateMachine', 'Status',
67
+ 'ACCEPTED', 'BAD_GATEWAY', 'BAD_REQUEST', 'CONFLICT', 'CONTENT_TOO_LARGE', 'CONTINUE', 'CREATED', 'EXPECTATION_FAILED', 'FORBIDDEN', 'FOUND', 'GATEWAY_TIMEOUT',
68
+ 'GONE', 'HTTP_VERSION_NOT_SUPPORTED', 'INTERNAL_SERVER_ERROR', 'I_AM_A_TEAPOT', 'LENGTH_REQUIRED', 'METHOD_NOT_ALLOWED', 'MOVED_PERMANENTLY', 'MULTIPLE_CHOICES',
69
+ 'NON_AUTHORITATIVE_INFORMATION', 'NOT_ACCEPTABLE', 'NOT_FOUND', 'NOT_IMPLEMENTED', 'NOT_MODIFIED', 'NO_CONTENT', 'OK', 'PARTIAL_CONTENT', 'PAYMENT_REQUIRED',
70
+ 'PRECONDITION_FAILED', 'PROXY_AUTHENTICATION_REQUIRED', 'RANGE_NOT_SATISFIABLE', 'REQUEST_TIMEOUT', 'RESET_CONTENT', 'SEE_OTHER', 'SERVICE_UNAVAILABLE',
71
+ 'SWITCHING_PROTOCOLS', 'TEMPORARY_REDIRECT', 'UNAUTHORIZED', 'UNPROCESSABLE_ENTITY', 'UNSUPPORTED_MEDIA_TYPE', 'URI', 'URI_TOO_LONG', 'USE_PROXY', 'Body',
72
+ 'ClientStateMachine', 'ComposedRequest', 'ComposedResponse', 'Date', 'DecodeError', 'EncodeError', 'Headers', 'InvalidBody', 'InvalidDate', 'InvalidHeader',
73
+ 'InvalidLine', 'InvalidURI', 'Method', 'Protocol', 'ProxyStateMachine', 'Request', 'Response', 'ServerHeader', 'ServerProtocol', 'ServerStateMachine', 'Status',
76
74
  'StatusException', 'UserAgentHeader', '__version__', 'cache',
77
75
  ]
@@ -9,7 +9,8 @@ python3 -m httoop compose response | python3 -m httoop parse response
9
9
 
10
10
  import pathlib
11
11
  import sys
12
- from argparse import ArgumentParser, FileType
12
+ from argparse import ArgumentParser
13
+ from typing import IO
13
14
 
14
15
  from httoop import Request, Response, __name__ as name, __version__ as version
15
16
  from httoop.client import ClientStateMachine
@@ -51,7 +52,7 @@ class CLI:
51
52
  request = parse_message_subparsers.add_parser('request', parents=[self.parent_parser])
52
53
  request.set_defaults(func=self.parse_request)
53
54
  add = request.add_argument
54
- add('--file', default='-', type=FileType('rb'))
55
+ add('--file', default='-')
55
56
  add('--scheme', default='http')
56
57
  add('--host', default='www.example.net')
57
58
  add('--port', default=80, type=int)
@@ -59,24 +60,27 @@ class CLI:
59
60
  response = parse_message_subparsers.add_parser('response', parents=[self.parent_parser])
60
61
  add = response.add_argument
61
62
  response.set_defaults(func=self.parse_response)
62
- add('--file', default='-', type=FileType('rb'))
63
+ add('--file', default='-')
63
64
 
64
65
  def parse_arguments(self) -> None:
65
66
  self.arguments = self.parser.parse_args()
66
-
67
- if self.arguments.action == 'parse' and hasattr(self.arguments.file, 'buffer'):
68
- # https://bugs.python.org/issue14156
69
- self.arguments.file = self.arguments.file.buffer
70
67
  self.arguments.func()
71
68
 
72
- def add_common_arguments(self, add) -> None:
69
+ @classmethod
70
+ def add_common_arguments(cls, add) -> None:
73
71
  add('--protocol')
74
72
  add('-H', '--header', action='append', default=[])
75
73
  add('-b', '--body', default='')
76
74
 
75
+ @classmethod
76
+ def get_file(cls, file: str) -> IO:
77
+ if file == '-':
78
+ return sys.stdin.buffer
79
+ return pathlib.Path(file).open('rb')
80
+
77
81
  def parse_request(self) -> None:
78
82
  server = ServerStateMachine(self.arguments.scheme, self.arguments.host, self.arguments.port)
79
- for _request, response in server.parse(self.arguments.file.read()):
83
+ for _request, response in server.parse(self.get_file(self.arguments.file).read()):
80
84
  print(repr(response))
81
85
  print(repr(response.headers))
82
86
  print(repr(response.body))
@@ -84,12 +88,13 @@ class CLI:
84
88
  def parse_response(self) -> None:
85
89
  client = ClientStateMachine()
86
90
  client.request = Request()
87
- for response in client.parse(self.arguments.file.read()):
91
+ for response in client.parse(self.get_file(self.arguments.file).read()):
88
92
  print(repr(response))
89
93
  print(repr(response.headers))
90
94
  print(repr(response.body))
91
95
  print(repr(bytes(response.body)))
92
96
  if client.buffer:
97
+ assert client.message # noqa: S101
93
98
  print('WARNING: response not yet complete!:')
94
99
  print(repr(client.message))
95
100
  print(repr(client.message.headers))
@@ -115,10 +120,11 @@ class CLI:
115
120
  self.common()
116
121
 
117
122
  def common(self) -> None:
123
+ assert self.message is not None # noqa: S101
118
124
  if self.arguments.protocol:
119
125
  protocol = self.arguments.protocol
120
126
  try:
121
- protocol = [int(x) for x in protocol.split('.', 1)]
127
+ protocol = tuple(int(x) for x in protocol.split('.', 1))
122
128
  except ValueError:
123
129
  pass
124
130
  else:
@@ -133,14 +139,15 @@ class CLI:
133
139
  if body == '-':
134
140
  body = sys.stdin.read()
135
141
  elif body.startswith('@'):
136
- body = pathlib.Path(body[1:]).open('rb')
142
+ body = pathlib.Path(body[1:]).open('rb') # noqa: SIM115
137
143
  self.message.body = body
138
144
 
139
145
  sys.stdout.write(self.decode(bytes(self.message)))
140
146
  sys.stdout.write(self.decode(bytes(self.message.headers)))
141
147
  sys.stdout.write(self.decode(bytes(self.message.body)))
142
148
 
143
- def decode(self, data):
149
+ @classmethod
150
+ def decode(cls, data):
144
151
  if str is not bytes:
145
152
  data = data.decode('ISO8859-1')
146
153
  return data
@@ -1,10 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import re
4
- from typing import TYPE_CHECKING, Any
4
+ from typing import TYPE_CHECKING, Any, ClassVar
5
5
 
6
6
  from httoop.authentication.basic import BasicAuthRequestScheme, BasicAuthResponseScheme
7
- from httoop.authentication.digest import DigestAuthRequestScheme, DigestAuthResponseScheme
7
+ from httoop.authentication.digest import DigestAuthRequestScheme, DigestAuthResponseScheme, SecureDigestAuthRequestScheme
8
8
  from httoop.exceptions import InvalidHeader
9
9
  from httoop.header.element import HeaderElement
10
10
  from httoop.util import _
@@ -16,7 +16,7 @@ if TYPE_CHECKING:
16
16
 
17
17
  class AuthElement(HeaderElement):
18
18
 
19
- schemes = {}
19
+ schemes: ClassVar = {}
20
20
  RE_SPACE_SPLIT = re.compile(rb'\s+(?=(?:[^"]*"[^"]*")*[^"]*$)')
21
21
 
22
22
  def sanitize(self) -> None:
@@ -31,16 +31,16 @@ class AuthElement(HeaderElement):
31
31
  try:
32
32
  scheme, authinfo = elementstr.split(b' ', 1)
33
33
  except ValueError:
34
- raise InvalidHeader(_('Authorization headers must contain authentication scheme'))
34
+ raise InvalidHeader(_('Authorization headers must contain authentication scheme')) from None
35
35
  try:
36
36
  parser = cls.schemes[scheme.decode('ISO8859-1').lower()]
37
37
  except KeyError:
38
- raise InvalidHeader(_('Unsupported authentication scheme: %r'), scheme)
38
+ raise InvalidHeader(_('Unsupported authentication scheme: %r'), scheme) from None
39
39
 
40
40
  try:
41
41
  authinfo = parser.parse(authinfo)
42
42
  except KeyError as key:
43
- raise InvalidHeader(_('Missing parameter %r for authentication scheme %r'), str(key), scheme)
43
+ raise InvalidHeader(_('Missing parameter %r for authentication scheme %r'), str(key), scheme) from None
44
44
 
45
45
  return scheme.title(), authinfo
46
46
 
@@ -48,12 +48,12 @@ class AuthElement(HeaderElement):
48
48
  try:
49
49
  scheme = self.schemes[self.value.lower()]
50
50
  except KeyError:
51
- raise InvalidHeader(_('Unsupported authentication scheme: %r'), self.value)
51
+ raise InvalidHeader(_('Unsupported authentication scheme: %r'), self.value) from None
52
52
 
53
53
  try:
54
54
  authinfo = scheme.compose(self.params)
55
55
  except KeyError as key:
56
- raise InvalidHeader(_('Missing parameter %r for authentication scheme %r'), str(key), self.value)
56
+ raise InvalidHeader(_('Missing parameter %r for authentication scheme %r'), str(key), self.value) from None
57
57
 
58
58
  return b'%s %s' % (self.value.encode('ASCII').title(), authinfo)
59
59
 
@@ -68,11 +68,15 @@ class AuthRequestElement(AuthElement):
68
68
 
69
69
  encoding = 'ASCII'
70
70
 
71
- schemes = {
71
+ schemes: ClassVar = {
72
72
  'basic': BasicAuthRequestScheme,
73
- 'digest': DigestAuthRequestScheme,
73
+ 'digest': SecureDigestAuthRequestScheme,
74
74
  }
75
75
 
76
+ @classmethod
77
+ def allow_insecure_digest_algorithms(cls, *, allow=False):
78
+ cls.schemes['digest'] = DigestAuthRequestScheme if allow else SecureDigestAuthRequestScheme
79
+
76
80
  @property
77
81
  def scheme(self):
78
82
  return self.value.lower()
@@ -99,7 +103,7 @@ class AuthRequestElement(AuthElement):
99
103
 
100
104
  class AuthResponseElement(AuthElement):
101
105
 
102
- schemes = {
106
+ schemes: ClassVar = {
103
107
  'basic': BasicAuthResponseScheme,
104
108
  'digest': DigestAuthResponseScheme,
105
109
  }
@@ -1,11 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
- import base64
4
- from binascii import Error as Base64Error
5
-
6
3
  from httoop.exceptions import InvalidHeader
7
4
  from httoop.header.element import HeaderElement
8
- from httoop.util import ByteUnicodeDict, _
5
+ from httoop.util import Base64Error, ByteUnicodeDict, _, base64, base64_decode
9
6
 
10
7
 
11
8
  class BasicAuthRequestScheme:
@@ -18,11 +15,13 @@ class BasicAuthRequestScheme:
18
15
  # raise InvalidHeader(_(u'Invalid base64 in basic authentication'))
19
16
 
20
17
  try:
21
- username, password = base64.b64decode(authinfo.strip()).split(b':')
18
+ username, password = base64_decode(authinfo.strip()).split(b':', 1)
19
+ if not username:
20
+ raise ValueError()
22
21
  except Base64Error:
23
- raise InvalidHeader(_('Basic authentication contains invalid base64'))
22
+ raise InvalidHeader(_('Basic authentication contains invalid base64')) from None
24
23
  except ValueError:
25
- raise InvalidHeader(_('No username:password provided'))
24
+ raise InvalidHeader(_('No username:password provided')) from None
26
25
 
27
26
  return {
28
27
  # 'username': username.decode('ISO8859-1'),
@@ -37,17 +36,17 @@ class BasicAuthRequestScheme:
37
36
  password = authinfo['password']
38
37
  # username = username.encode('ISO8859-1')
39
38
  # password = password.encode('ISO8859-1')
40
- return base64.b64encode(b'%s:%s' % (username, password))
39
+ return base64(b'%s:%s' % (username, password))
41
40
 
42
41
 
43
42
  class BasicAuthResponseScheme:
44
43
 
45
44
  @staticmethod
46
- def parse(authinfo: bytes) -> dict[bytes, str | bytes]:
45
+ def parse(authinfo: bytes) -> dict[bytes, str]:
47
46
  params = HeaderElement.parseparams(b'X;%s' % authinfo)[1]
48
- params.setdefault(b'realm', b'')
47
+ params.setdefault(b'realm', '')
49
48
  return params
50
49
 
51
50
  @staticmethod
52
51
  def compose(authinfo: ByteUnicodeDict) -> bytes:
53
- return HeaderElement.formatparam(b'realm', authinfo['realm'], True)
52
+ return HeaderElement.formatparam(b'realm', authinfo['realm'], quote=True)