httoop 0.0__tar.gz → 0.2.0__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.
- httoop-0.2.0/LICENSE +19 -0
- httoop-0.2.0/PKG-INFO +174 -0
- httoop-0.2.0/README.md +131 -0
- httoop-0.2.0/httoop/__init__.py +77 -0
- httoop-0.2.0/httoop/__main__.py +150 -0
- httoop-0.2.0/httoop/authentication/__init__.py +125 -0
- httoop-0.2.0/httoop/authentication/basic.py +53 -0
- httoop-0.2.0/httoop/authentication/digest.py +214 -0
- httoop-0.2.0/httoop/client/__init__.py +16 -0
- httoop-0.2.0/httoop/codecs/__init__.py +32 -0
- {httoop-0.0 → httoop-0.2.0}/httoop/codecs/application/__init__.py +6 -6
- httoop-0.2.0/httoop/codecs/application/gzip.py +65 -0
- httoop-0.2.0/httoop/codecs/application/hal_json.py +143 -0
- httoop-0.2.0/httoop/codecs/application/json.py +25 -0
- httoop-0.2.0/httoop/codecs/application/x_www_form_urlencoded.py +43 -0
- httoop-0.2.0/httoop/codecs/application/xml.py +40 -0
- httoop-0.2.0/httoop/codecs/application/zlib.py +26 -0
- httoop-0.2.0/httoop/codecs/audio/__init__.py +0 -0
- httoop-0.2.0/httoop/codecs/codec.py +30 -0
- httoop-0.2.0/httoop/codecs/example/__init__.py +0 -0
- httoop-0.2.0/httoop/codecs/image/__init__.py +0 -0
- {httoop-0.0 → httoop-0.2.0}/httoop/codecs/message/__init__.py +1 -2
- httoop-0.2.0/httoop/codecs/message/http.py +36 -0
- httoop-0.2.0/httoop/codecs/model/__init__.py +0 -0
- httoop-0.2.0/httoop/codecs/multipart/__init__.py +40 -0
- httoop-0.2.0/httoop/codecs/multipart/multipart.py +59 -0
- {httoop-0.0 → httoop-0.2.0}/httoop/codecs/text/__init__.py +3 -3
- {httoop-0.0 → httoop-0.2.0}/httoop/codecs/text/html.py +1 -2
- httoop-0.2.0/httoop/codecs/text/plain.py +31 -0
- httoop-0.2.0/httoop/codecs/video/__init__.py +0 -0
- httoop-0.2.0/httoop/date.py +186 -0
- httoop-0.2.0/httoop/exceptions.py +35 -0
- httoop-0.2.0/httoop/gateway/__init__.py +0 -0
- httoop-0.2.0/httoop/gateway/wsgi.py +189 -0
- httoop-0.2.0/httoop/header/__init__.py +23 -0
- httoop-0.2.0/httoop/header/auth.py +34 -0
- httoop-0.2.0/httoop/header/cache.py +32 -0
- httoop-0.2.0/httoop/header/conditional.py +86 -0
- httoop-0.2.0/httoop/header/element.py +412 -0
- httoop-0.2.0/httoop/header/headers.py +168 -0
- httoop-0.2.0/httoop/header/messaging.py +470 -0
- httoop-0.2.0/httoop/header/ranges.py +144 -0
- httoop-0.2.0/httoop/header/security.py +130 -0
- {httoop-0.0 → httoop-0.2.0}/httoop/messages/__init__.py +6 -5
- httoop-0.2.0/httoop/messages/body.py +306 -0
- httoop-0.2.0/httoop/messages/message.py +91 -0
- httoop-0.2.0/httoop/messages/method.py +53 -0
- httoop-0.2.0/httoop/messages/protocol.py +93 -0
- httoop-0.2.0/httoop/messages/request.py +102 -0
- httoop-0.2.0/httoop/messages/response.py +65 -0
- httoop-0.2.0/httoop/meta.py +44 -0
- httoop-0.2.0/httoop/parser.py +310 -0
- {httoop-0.0 → httoop-0.2.0}/httoop/proxy/__init__.py +1 -3
- {httoop-0.0 → httoop-0.2.0}/httoop/semantic/__init__.py +1 -1
- httoop-0.2.0/httoop/semantic/message.py +56 -0
- httoop-0.2.0/httoop/semantic/request.py +80 -0
- httoop-0.2.0/httoop/semantic/response.py +147 -0
- httoop-0.2.0/httoop/server/__init__.py +156 -0
- httoop-0.2.0/httoop/status/__init__.py +21 -0
- httoop-0.2.0/httoop/status/client_error.py +216 -0
- httoop-0.2.0/httoop/status/informational.py +32 -0
- httoop-0.2.0/httoop/status/redirect.py +109 -0
- httoop-0.2.0/httoop/status/server_error.py +90 -0
- httoop-0.2.0/httoop/status/status.py +235 -0
- httoop-0.2.0/httoop/status/success.py +114 -0
- httoop-0.2.0/httoop/status/types.py +103 -0
- httoop-0.2.0/httoop/uri/__init__.py +12 -0
- httoop-0.2.0/httoop/uri/http.py +18 -0
- httoop-0.2.0/httoop/uri/percent_encoding.py +52 -0
- httoop-0.2.0/httoop/uri/query_string.py +20 -0
- httoop-0.2.0/httoop/uri/schemes.py +36 -0
- httoop-0.2.0/httoop/uri/uri.py +387 -0
- httoop-0.2.0/httoop/util.py +210 -0
- httoop-0.2.0/httoop/version.py +8 -0
- httoop-0.2.0/httoop.egg-info/PKG-INFO +174 -0
- {httoop-0.0 → httoop-0.2.0}/httoop.egg-info/SOURCES.txt +5 -6
- httoop-0.2.0/httoop.egg-info/requires.txt +12 -0
- httoop-0.2.0/pyproject.toml +176 -0
- httoop-0.2.0/tests/test_cli.py +38 -0
- httoop-0.0/PKG-INFO +0 -145
- httoop-0.0/README.md +0 -112
- httoop-0.0/httoop/__init__.py +0 -59
- httoop-0.0/httoop/__main__.py +0 -113
- httoop-0.0/httoop/authentication/__init__.py +0 -95
- httoop-0.0/httoop/authentication/basic.py +0 -53
- httoop-0.0/httoop/authentication/digest.py +0 -211
- httoop-0.0/httoop/cache/__init__.py +0 -1
- httoop-0.0/httoop/client/__init__.py +0 -17
- httoop-0.0/httoop/codecs/__init__.py +0 -41
- httoop-0.0/httoop/codecs/application/gzip.py +0 -38
- httoop-0.0/httoop/codecs/application/hal_json.py +0 -137
- httoop-0.0/httoop/codecs/application/json.py +0 -22
- httoop-0.0/httoop/codecs/application/x_www_form_urlencoded.py +0 -37
- httoop-0.0/httoop/codecs/application/xml.py +0 -32
- httoop-0.0/httoop/codecs/application/zlib.py +0 -28
- httoop-0.0/httoop/codecs/audio/__init__.py +0 -1
- httoop-0.0/httoop/codecs/codec.py +0 -25
- httoop-0.0/httoop/codecs/example/__init__.py +0 -1
- httoop-0.0/httoop/codecs/image/__init__.py +0 -1
- httoop-0.0/httoop/codecs/message/http.py +0 -28
- httoop-0.0/httoop/codecs/model/__init__.py +0 -1
- httoop-0.0/httoop/codecs/multipart/__init__.py +0 -40
- httoop-0.0/httoop/codecs/multipart/multipart.py +0 -51
- httoop-0.0/httoop/codecs/text/plain.py +0 -24
- httoop-0.0/httoop/codecs/video/__init__.py +0 -1
- httoop-0.0/httoop/date.py +0 -179
- httoop-0.0/httoop/exceptions.py +0 -38
- httoop-0.0/httoop/gateway/wsgi.py +0 -151
- httoop-0.0/httoop/header/__init__.py +0 -36
- httoop-0.0/httoop/header/auth.py +0 -36
- httoop-0.0/httoop/header/cache.py +0 -35
- httoop-0.0/httoop/header/conditional.py +0 -62
- httoop-0.0/httoop/header/element.py +0 -414
- httoop-0.0/httoop/header/headers.py +0 -166
- httoop-0.0/httoop/header/messaging.py +0 -473
- httoop-0.0/httoop/header/range.py +0 -122
- httoop-0.0/httoop/header/security.py +0 -122
- httoop-0.0/httoop/header/semantics.py +0 -1
- httoop-0.0/httoop/messages/body.py +0 -302
- httoop-0.0/httoop/messages/message.py +0 -89
- httoop-0.0/httoop/messages/method.py +0 -51
- httoop-0.0/httoop/messages/protocol.py +0 -91
- httoop-0.0/httoop/messages/request.py +0 -98
- httoop-0.0/httoop/messages/response.py +0 -64
- httoop-0.0/httoop/meta.py +0 -60
- httoop-0.0/httoop/parser.py +0 -300
- httoop-0.0/httoop/semantic/message.py +0 -58
- httoop-0.0/httoop/semantic/request.py +0 -80
- httoop-0.0/httoop/semantic/response.py +0 -132
- httoop-0.0/httoop/server/__init__.py +0 -151
- httoop-0.0/httoop/six.py +0 -4
- httoop-0.0/httoop/status/__init__.py +0 -29
- httoop-0.0/httoop/status/client_error.py +0 -245
- httoop-0.0/httoop/status/informational.py +0 -30
- httoop-0.0/httoop/status/redirect.py +0 -109
- httoop-0.0/httoop/status/server_error.py +0 -100
- httoop-0.0/httoop/status/status.py +0 -195
- httoop-0.0/httoop/status/success.py +0 -114
- httoop-0.0/httoop/status/types.py +0 -124
- httoop-0.0/httoop/uri/__init__.py +0 -11
- httoop-0.0/httoop/uri/http.py +0 -18
- httoop-0.0/httoop/uri/percent_encoding.py +0 -53
- httoop-0.0/httoop/uri/query_string.py +0 -20
- httoop-0.0/httoop/uri/schemes.py +0 -38
- httoop-0.0/httoop/uri/type.py +0 -13
- httoop-0.0/httoop/uri/uri.py +0 -376
- httoop-0.0/httoop/util.py +0 -241
- httoop-0.0/httoop/version.py +0 -14
- httoop-0.0/httoop.egg-info/PKG-INFO +0 -145
- httoop-0.0/httoop.egg-info/requires.txt +0 -1
- httoop-0.0/setup.py +0 -51
- {httoop-0.0/httoop/gateway → httoop-0.2.0/httoop/cache}/__init__.py +0 -0
- {httoop-0.0 → httoop-0.2.0}/httoop.egg-info/dependency_links.txt +0 -0
- {httoop-0.0 → httoop-0.2.0}/httoop.egg-info/top_level.txt +0 -0
- {httoop-0.0 → httoop-0.2.0}/httoop.egg-info/zip-safe +0 -0
- {httoop-0.0 → httoop-0.2.0}/setup.cfg +0 -0
httoop-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2013-2020 SpaceOne <space@wechall.net>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
5
|
+
the Software without restriction, including without limitation the rights to
|
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
8
|
+
so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
httoop-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: httoop
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: object oriented HTTP protocol library
|
|
5
|
+
Author-email: SpaceOne <space@wechall.net>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/spaceone/httoop
|
|
8
|
+
Keywords: HTTP,web,proxy,cache,client,server,library
|
|
9
|
+
Classifier: Environment :: Web Environment
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Information Technology
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Operating System :: POSIX :: BSD
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
16
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
25
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
|
|
26
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware
|
|
27
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Server
|
|
28
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
29
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
30
|
+
Requires-Python: >=3.8
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
License-File: LICENSE
|
|
33
|
+
Provides-Extra: xml
|
|
34
|
+
Requires-Dist: defusedxml; extra == "xml"
|
|
35
|
+
Provides-Extra: hal
|
|
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
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
[](https://github.com/spaceone/httoop/actions/workflows/ci.yml)
|
|
45
|
+
[](https://codecov.io/gh/spaceone/httoop)
|
|
46
|
+
[](https://codeclimate.com/github/spaceone/httoop)
|
|
47
|
+
[](https://github.com/spaceone/httoop/raw/master/LICENSE)
|
|
48
|
+
|
|
49
|
+
httoop
|
|
50
|
+
======
|
|
51
|
+
|
|
52
|
+
An object oriented HTTP/1.1 library. (HTTP/2 will probably follow in the future).
|
|
53
|
+
|
|
54
|
+
Httoop can be used to parse, compose and work with HTTP-Request- and Response-Messages.
|
|
55
|
+
|
|
56
|
+
It is an generic library for implementing HTTP servers, clients, caches and proxies.
|
|
57
|
+
|
|
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).
|
|
59
|
+
|
|
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)
|
|
62
|
+
|
|
63
|
+
On top of the object oriented abstraction of HTTP httoop provides an easy way to support WSGI.
|
|
64
|
+
|
|
65
|
+
|
|
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)
|
|
69
|
+
|
|
70
|
+
* HTTP/1.1 RFC 7231 [Semantics and Content](https://datatracker.ietf.org/doc/html/rfc7231)
|
|
71
|
+
|
|
72
|
+
* HTTP/1.1 RFC 7232 [Conditional Requests](https://datatracker.ietf.org/doc/html/rfc7232)
|
|
73
|
+
|
|
74
|
+
* HTTP/1.1 RFC 7233 [Range Requests](https://datatracker.ietf.org/doc/html/rfc7233)
|
|
75
|
+
|
|
76
|
+
* HTTP/1.1 RFC 7234 [Caching](https://datatracker.ietf.org/doc/html/rfc7234)
|
|
77
|
+
|
|
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
|
+
* HTTP/2 RFC 7540 [Hypertext Transfer Protocol Version 2](https://datatracker.ietf.org/doc/html/rfc7540)
|
|
83
|
+
|
|
84
|
+
* HTTP/2 RFC 7541 [HPACK: Header Compression for HTTP/2](https://datatracker.ietf.org/doc/html/rfc7541)
|
|
85
|
+
|
|
86
|
+
* [IANA HTTP Status Codes](http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml)
|
|
87
|
+
|
|
88
|
+
* [IANA HTTP Methods](http://www.iana.org/assignments/http-methods/http-methods.xhtml)
|
|
89
|
+
|
|
90
|
+
* [IANA Message Headers](http://www.iana.org/assignments/message-headers/message-headers.xhtml)
|
|
91
|
+
|
|
92
|
+
* [IANA URI Schemes](http://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml)
|
|
93
|
+
|
|
94
|
+
* [IANA HTTP Authentication Schemes](http://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml)
|
|
95
|
+
|
|
96
|
+
* [IANA HTTP Cache Directives](http://www.iana.org/assignments/http-cache-directives/http-cache-directives.xhtml)
|
|
97
|
+
|
|
98
|
+
* RFC 5987 [Character Set and Language Encoding for Hypertext Transfer Protocol (HTTP) Header Field Parameters](https://datatracker.ietf.org/doc/html/rfc5987)
|
|
99
|
+
|
|
100
|
+
* Uniform Resource Identifier (URI) ([RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986))
|
|
101
|
+
|
|
102
|
+
* 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
|
+
|
|
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
|
+
* HTTP Digest Access Authentication ([RFC 7616](https://datatracker.ietf.org/doc/html/rfc7616))
|
|
109
|
+
|
|
110
|
+
* The 'Basic' HTTP Authentication Scheme ([RFC 7617](https://datatracker.ietf.org/doc/html/rfc7617))
|
|
111
|
+
|
|
112
|
+
* Additional HTTP Status Codes ([RFC 6585](https://datatracker.ietf.org/doc/html/rfc6585))
|
|
113
|
+
|
|
114
|
+
* Forwarded HTTP Extension [RFC 7239](https://datatracker.ietf.org/doc/html/rfc7239)
|
|
115
|
+
|
|
116
|
+
* Prefer Header for HTTP [RFC 7240](https://datatracker.ietf.org/doc/html/rfc7240)
|
|
117
|
+
|
|
118
|
+
* PATCH Method for HTTP ([RFC 5789](https://datatracker.ietf.org/doc/html/rfc5789))
|
|
119
|
+
|
|
120
|
+
* JavaScript Object Notation (JSON) Patch ([RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902))
|
|
121
|
+
|
|
122
|
+
* Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP) ([RFC 6266](https://datatracker.ietf.org/doc/html/rfc6266))
|
|
123
|
+
|
|
124
|
+
* Upgrading to TLS Within HTTP/1.1 ([RFC 2817](https://datatracker.ietf.org/doc/html/rfc2817))
|
|
125
|
+
|
|
126
|
+
* Transparent Content Negotiation in HTTP ([RFC 2295](https://datatracker.ietf.org/doc/html/rfc2295))
|
|
127
|
+
|
|
128
|
+
* HTTP Remote Variant Selection Algorithm -- RVSA/1.0 ([RFC 2296](https://datatracker.ietf.org/doc/html/rfc2296))
|
|
129
|
+
|
|
130
|
+
* HTTP State Management Mechanism ([RFC 6265](https://datatracker.ietf.org/doc/html/rfc6265))
|
|
131
|
+
|
|
132
|
+
* Same-site Cookies ([Draft 7](https://datatracker.ietf.org/doc/html/rfcdraft-west-first-party-cookies-07))
|
|
133
|
+
|
|
134
|
+
* HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) ([RFC 4918](https://datatracker.ietf.org/doc/html/rfc4918))
|
|
135
|
+
|
|
136
|
+
* Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0) ([RFC 2324](https://datatracker.ietf.org/doc/html/rfc2324))
|
|
137
|
+
|
|
138
|
+
Extended information about hypermedia, WWW and how HTTP is meant to be used:
|
|
139
|
+
|
|
140
|
+
* Web Linking ([RFC 5988](https://datatracker.ietf.org/doc/html/rfc5988))
|
|
141
|
+
|
|
142
|
+
* Representational State Transfer [REST](http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm)
|
|
143
|
+
|
|
144
|
+
* [REST APIs must be hypertext-driven](https://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven)
|
|
145
|
+
|
|
146
|
+
* [Specialization](https://roy.gbiv.com/untangled/2008/specialization)
|
|
147
|
+
|
|
148
|
+
* [No REST in CMIS](https://roy.gbiv.com/untangled/2008/no-rest-in-cmis)
|
|
149
|
+
|
|
150
|
+
* [On software architecture](https://roy.gbiv.com/untangled/2008/on-software-architecture)
|
|
151
|
+
|
|
152
|
+
* [It is okay to use POST](https://roy.gbiv.com/untangled/2009/it-is-okay-to-use-post)
|
|
153
|
+
|
|
154
|
+
* [Paper tigers and hidden dragons](https://roy.gbiv.com/untangled/2008/paper-tigers-and-hidden-dragons)
|
|
155
|
+
|
|
156
|
+
* [Economies of scale](https://roy.gbiv.com/untangled/2008/economies-of-scale)
|
|
157
|
+
|
|
158
|
+
* [Richardson Maturity Model](https://martinfowler.com/articles/richardsonMaturityModel.html)
|
|
159
|
+
|
|
160
|
+
* [Test Cases for HTTP Content-Disposition header field](http://greenbytes.de/tech/tc2231/)
|
|
161
|
+
|
|
162
|
+
* [Cross-Origin Resource Sharing](http://www.w3.org/TR/cors/)
|
|
163
|
+
|
|
164
|
+
* [HTTP (HTML) Leaks](https://github.com/cure53/HTTPLeaks/blob/main/leak.html)
|
|
165
|
+
|
|
166
|
+
OAuth 2.0:
|
|
167
|
+
|
|
168
|
+
* [OAuth Working Group Specifications](https://oauth.net/specs/)
|
|
169
|
+
* [OAuth 2.0 Security Best Current Practice](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics)
|
|
170
|
+
* [The OAuth 2.0 Authorization Framework](https://datatracker.ietf.org/doc/html/rfc6749)
|
|
171
|
+
* [Bearer Token Usage](https://datatracker.ietf.org/doc/html/rfc6750)
|
|
172
|
+
* [JSON Web Token (JWT)](https://datatracker.ietf.org/doc/html/rfc7519)
|
|
173
|
+
* [JSON Web Token (JWT) Profile for OAuth 2.0 Access Tokens](https://datatracker.ietf.org/doc/html/rfc9068)
|
|
174
|
+
* [Resource Indicators for OAuth 2.0](https://datatracker.ietf.org/doc/html/rfc8707)
|
httoop-0.2.0/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
[](https://github.com/spaceone/httoop/actions/workflows/ci.yml)
|
|
2
|
+
[](https://codecov.io/gh/spaceone/httoop)
|
|
3
|
+
[](https://codeclimate.com/github/spaceone/httoop)
|
|
4
|
+
[](https://github.com/spaceone/httoop/raw/master/LICENSE)
|
|
5
|
+
|
|
6
|
+
httoop
|
|
7
|
+
======
|
|
8
|
+
|
|
9
|
+
An object oriented HTTP/1.1 library. (HTTP/2 will probably follow in the future).
|
|
10
|
+
|
|
11
|
+
Httoop can be used to parse, compose and work with HTTP-Request- and Response-Messages.
|
|
12
|
+
|
|
13
|
+
It is an generic library for implementing HTTP servers, clients, caches and proxies.
|
|
14
|
+
|
|
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).
|
|
16
|
+
|
|
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)
|
|
19
|
+
|
|
20
|
+
On top of the object oriented abstraction of HTTP httoop provides an easy way to support WSGI.
|
|
21
|
+
|
|
22
|
+
|
|
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)
|
|
26
|
+
|
|
27
|
+
* HTTP/1.1 RFC 7231 [Semantics and Content](https://datatracker.ietf.org/doc/html/rfc7231)
|
|
28
|
+
|
|
29
|
+
* HTTP/1.1 RFC 7232 [Conditional Requests](https://datatracker.ietf.org/doc/html/rfc7232)
|
|
30
|
+
|
|
31
|
+
* HTTP/1.1 RFC 7233 [Range Requests](https://datatracker.ietf.org/doc/html/rfc7233)
|
|
32
|
+
|
|
33
|
+
* HTTP/1.1 RFC 7234 [Caching](https://datatracker.ietf.org/doc/html/rfc7234)
|
|
34
|
+
|
|
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
|
+
* HTTP/2 RFC 7540 [Hypertext Transfer Protocol Version 2](https://datatracker.ietf.org/doc/html/rfc7540)
|
|
40
|
+
|
|
41
|
+
* HTTP/2 RFC 7541 [HPACK: Header Compression for HTTP/2](https://datatracker.ietf.org/doc/html/rfc7541)
|
|
42
|
+
|
|
43
|
+
* [IANA HTTP Status Codes](http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml)
|
|
44
|
+
|
|
45
|
+
* [IANA HTTP Methods](http://www.iana.org/assignments/http-methods/http-methods.xhtml)
|
|
46
|
+
|
|
47
|
+
* [IANA Message Headers](http://www.iana.org/assignments/message-headers/message-headers.xhtml)
|
|
48
|
+
|
|
49
|
+
* [IANA URI Schemes](http://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml)
|
|
50
|
+
|
|
51
|
+
* [IANA HTTP Authentication Schemes](http://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml)
|
|
52
|
+
|
|
53
|
+
* [IANA HTTP Cache Directives](http://www.iana.org/assignments/http-cache-directives/http-cache-directives.xhtml)
|
|
54
|
+
|
|
55
|
+
* RFC 5987 [Character Set and Language Encoding for Hypertext Transfer Protocol (HTTP) Header Field Parameters](https://datatracker.ietf.org/doc/html/rfc5987)
|
|
56
|
+
|
|
57
|
+
* Uniform Resource Identifier (URI) ([RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986))
|
|
58
|
+
|
|
59
|
+
* 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
|
+
|
|
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
|
+
* HTTP Digest Access Authentication ([RFC 7616](https://datatracker.ietf.org/doc/html/rfc7616))
|
|
66
|
+
|
|
67
|
+
* The 'Basic' HTTP Authentication Scheme ([RFC 7617](https://datatracker.ietf.org/doc/html/rfc7617))
|
|
68
|
+
|
|
69
|
+
* Additional HTTP Status Codes ([RFC 6585](https://datatracker.ietf.org/doc/html/rfc6585))
|
|
70
|
+
|
|
71
|
+
* Forwarded HTTP Extension [RFC 7239](https://datatracker.ietf.org/doc/html/rfc7239)
|
|
72
|
+
|
|
73
|
+
* Prefer Header for HTTP [RFC 7240](https://datatracker.ietf.org/doc/html/rfc7240)
|
|
74
|
+
|
|
75
|
+
* PATCH Method for HTTP ([RFC 5789](https://datatracker.ietf.org/doc/html/rfc5789))
|
|
76
|
+
|
|
77
|
+
* JavaScript Object Notation (JSON) Patch ([RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902))
|
|
78
|
+
|
|
79
|
+
* Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP) ([RFC 6266](https://datatracker.ietf.org/doc/html/rfc6266))
|
|
80
|
+
|
|
81
|
+
* Upgrading to TLS Within HTTP/1.1 ([RFC 2817](https://datatracker.ietf.org/doc/html/rfc2817))
|
|
82
|
+
|
|
83
|
+
* Transparent Content Negotiation in HTTP ([RFC 2295](https://datatracker.ietf.org/doc/html/rfc2295))
|
|
84
|
+
|
|
85
|
+
* HTTP Remote Variant Selection Algorithm -- RVSA/1.0 ([RFC 2296](https://datatracker.ietf.org/doc/html/rfc2296))
|
|
86
|
+
|
|
87
|
+
* HTTP State Management Mechanism ([RFC 6265](https://datatracker.ietf.org/doc/html/rfc6265))
|
|
88
|
+
|
|
89
|
+
* Same-site Cookies ([Draft 7](https://datatracker.ietf.org/doc/html/rfcdraft-west-first-party-cookies-07))
|
|
90
|
+
|
|
91
|
+
* HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) ([RFC 4918](https://datatracker.ietf.org/doc/html/rfc4918))
|
|
92
|
+
|
|
93
|
+
* Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0) ([RFC 2324](https://datatracker.ietf.org/doc/html/rfc2324))
|
|
94
|
+
|
|
95
|
+
Extended information about hypermedia, WWW and how HTTP is meant to be used:
|
|
96
|
+
|
|
97
|
+
* Web Linking ([RFC 5988](https://datatracker.ietf.org/doc/html/rfc5988))
|
|
98
|
+
|
|
99
|
+
* Representational State Transfer [REST](http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm)
|
|
100
|
+
|
|
101
|
+
* [REST APIs must be hypertext-driven](https://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven)
|
|
102
|
+
|
|
103
|
+
* [Specialization](https://roy.gbiv.com/untangled/2008/specialization)
|
|
104
|
+
|
|
105
|
+
* [No REST in CMIS](https://roy.gbiv.com/untangled/2008/no-rest-in-cmis)
|
|
106
|
+
|
|
107
|
+
* [On software architecture](https://roy.gbiv.com/untangled/2008/on-software-architecture)
|
|
108
|
+
|
|
109
|
+
* [It is okay to use POST](https://roy.gbiv.com/untangled/2009/it-is-okay-to-use-post)
|
|
110
|
+
|
|
111
|
+
* [Paper tigers and hidden dragons](https://roy.gbiv.com/untangled/2008/paper-tigers-and-hidden-dragons)
|
|
112
|
+
|
|
113
|
+
* [Economies of scale](https://roy.gbiv.com/untangled/2008/economies-of-scale)
|
|
114
|
+
|
|
115
|
+
* [Richardson Maturity Model](https://martinfowler.com/articles/richardsonMaturityModel.html)
|
|
116
|
+
|
|
117
|
+
* [Test Cases for HTTP Content-Disposition header field](http://greenbytes.de/tech/tc2231/)
|
|
118
|
+
|
|
119
|
+
* [Cross-Origin Resource Sharing](http://www.w3.org/TR/cors/)
|
|
120
|
+
|
|
121
|
+
* [HTTP (HTML) Leaks](https://github.com/cure53/HTTPLeaks/blob/main/leak.html)
|
|
122
|
+
|
|
123
|
+
OAuth 2.0:
|
|
124
|
+
|
|
125
|
+
* [OAuth Working Group Specifications](https://oauth.net/specs/)
|
|
126
|
+
* [OAuth 2.0 Security Best Current Practice](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics)
|
|
127
|
+
* [The OAuth 2.0 Authorization Framework](https://datatracker.ietf.org/doc/html/rfc6749)
|
|
128
|
+
* [Bearer Token Usage](https://datatracker.ietf.org/doc/html/rfc6750)
|
|
129
|
+
* [JSON Web Token (JWT)](https://datatracker.ietf.org/doc/html/rfc7519)
|
|
130
|
+
* [JSON Web Token (JWT) Profile for OAuth 2.0 Access Tokens](https://datatracker.ietf.org/doc/html/rfc9068)
|
|
131
|
+
* [Resource Indicators for OAuth 2.0](https://datatracker.ietf.org/doc/html/rfc8707)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""
|
|
2
|
+
HTTPOOP - an OOP model of the HTTP protocol.
|
|
3
|
+
|
|
4
|
+
.. seealso:: :rfc:`2616`
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from httoop import cache
|
|
8
|
+
from httoop.client import ClientStateMachine
|
|
9
|
+
from httoop.date import Date
|
|
10
|
+
from httoop.exceptions import DecodeError, EncodeError, InvalidBody, InvalidDate, InvalidHeader, InvalidLine, InvalidURI
|
|
11
|
+
from httoop.header import Headers
|
|
12
|
+
from httoop.messages import Body, Method, Protocol, Request, Response
|
|
13
|
+
from httoop.proxy import ProxyStateMachine
|
|
14
|
+
from httoop.semantic import ComposedRequest, ComposedResponse
|
|
15
|
+
from httoop.server import ServerStateMachine
|
|
16
|
+
from httoop.status import (
|
|
17
|
+
ACCEPTED,
|
|
18
|
+
BAD_GATEWAY,
|
|
19
|
+
BAD_REQUEST,
|
|
20
|
+
CONFLICT,
|
|
21
|
+
CONTINUE,
|
|
22
|
+
CREATED,
|
|
23
|
+
EXPECTATION_FAILED,
|
|
24
|
+
FORBIDDEN,
|
|
25
|
+
FOUND,
|
|
26
|
+
GATEWAY_TIMEOUT,
|
|
27
|
+
GONE,
|
|
28
|
+
HTTP_VERSION_NOT_SUPPORTED,
|
|
29
|
+
I_AM_A_TEAPOT,
|
|
30
|
+
INTERNAL_SERVER_ERROR,
|
|
31
|
+
LENGTH_REQUIRED,
|
|
32
|
+
METHOD_NOT_ALLOWED,
|
|
33
|
+
MOVED_PERMANENTLY,
|
|
34
|
+
MULTIPLE_CHOICES,
|
|
35
|
+
NO_CONTENT,
|
|
36
|
+
NON_AUTHORITATIVE_INFORMATION,
|
|
37
|
+
NOT_ACCEPTABLE,
|
|
38
|
+
NOT_FOUND,
|
|
39
|
+
NOT_IMPLEMENTED,
|
|
40
|
+
NOT_MODIFIED,
|
|
41
|
+
OK,
|
|
42
|
+
PARTIAL_CONTENT,
|
|
43
|
+
PAYLOAD_TOO_LARGE,
|
|
44
|
+
PAYMENT_REQUIRED,
|
|
45
|
+
PRECONDITION_FAILED,
|
|
46
|
+
PROXY_AUTHENTICATION_REQUIRED,
|
|
47
|
+
RANGE_NOT_SATISFIABLE,
|
|
48
|
+
REQUEST_TIMEOUT,
|
|
49
|
+
RESET_CONTENT,
|
|
50
|
+
SEE_OTHER,
|
|
51
|
+
SERVICE_UNAVAILABLE,
|
|
52
|
+
SWITCHING_PROTOCOLS,
|
|
53
|
+
TEMPORARY_REDIRECT,
|
|
54
|
+
UNAUTHORIZED,
|
|
55
|
+
UNPROCESSABLE_ENTITY,
|
|
56
|
+
UNSUPPORTED_MEDIA_TYPE,
|
|
57
|
+
URI_TOO_LONG,
|
|
58
|
+
USE_PROXY,
|
|
59
|
+
Status,
|
|
60
|
+
StatusException,
|
|
61
|
+
)
|
|
62
|
+
from httoop.uri import URI
|
|
63
|
+
from httoop.version import ServerHeader, ServerProtocol, UserAgentHeader, __version__
|
|
64
|
+
|
|
65
|
+
|
|
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',
|
|
76
|
+
'StatusException', 'UserAgentHeader', '__version__', 'cache',
|
|
77
|
+
]
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""
|
|
2
|
+
httoop CLI tool.
|
|
3
|
+
|
|
4
|
+
Examples
|
|
5
|
+
--------
|
|
6
|
+
python3 -m httoop compose request -H 'Host: www.example.net' | python3 -m httoop parse request
|
|
7
|
+
python3 -m httoop compose response | python3 -m httoop parse response
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import pathlib
|
|
11
|
+
import sys
|
|
12
|
+
from argparse import ArgumentParser, FileType
|
|
13
|
+
|
|
14
|
+
from httoop import Request, Response, __name__ as name, __version__ as version
|
|
15
|
+
from httoop.client import ClientStateMachine
|
|
16
|
+
from httoop.server import ServerStateMachine
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class CLI:
|
|
20
|
+
"""httoop CLI tool."""
|
|
21
|
+
|
|
22
|
+
def __init__(self) -> None:
|
|
23
|
+
self.message = None
|
|
24
|
+
self.parser = ArgumentParser(name, description=self.__doc__, epilog='https://github.com/spaceone/httoop/')
|
|
25
|
+
self.parent_parser = ArgumentParser(add_help=False)
|
|
26
|
+
self.parser.add_argument('-v', '--version', action='version', version=f'%(prog)s {version}')
|
|
27
|
+
self.add_subparsers()
|
|
28
|
+
self.parse_arguments()
|
|
29
|
+
|
|
30
|
+
def add_subparsers(self) -> None:
|
|
31
|
+
action_subparsers = self.parser.add_subparsers(title='action', dest='action', required=True)
|
|
32
|
+
parse_parser = action_subparsers.add_parser('parse', parents=[self.parent_parser])
|
|
33
|
+
compose_parser = action_subparsers.add_parser('compose', parents=[self.parent_parser])
|
|
34
|
+
|
|
35
|
+
compose_message_subparsers = compose_parser.add_subparsers(title='message', dest='message')
|
|
36
|
+
request = compose_message_subparsers.add_parser('request', parents=[self.parent_parser])
|
|
37
|
+
request.set_defaults(func=self.compose_request)
|
|
38
|
+
add = request.add_argument
|
|
39
|
+
add('-m', '--method')
|
|
40
|
+
add('-u', '--uri')
|
|
41
|
+
self.add_common_arguments(add)
|
|
42
|
+
|
|
43
|
+
response = compose_message_subparsers.add_parser('response', parents=[self.parent_parser])
|
|
44
|
+
response.set_defaults(func=self.compose_response)
|
|
45
|
+
add = response.add_argument
|
|
46
|
+
add('-s', '--status')
|
|
47
|
+
add('--reason')
|
|
48
|
+
self.add_common_arguments(add)
|
|
49
|
+
|
|
50
|
+
parse_message_subparsers = parse_parser.add_subparsers(title='message', dest='message')
|
|
51
|
+
request = parse_message_subparsers.add_parser('request', parents=[self.parent_parser])
|
|
52
|
+
request.set_defaults(func=self.parse_request)
|
|
53
|
+
add = request.add_argument
|
|
54
|
+
add('--file', default='-', type=FileType('rb'))
|
|
55
|
+
add('--scheme', default='http')
|
|
56
|
+
add('--host', default='www.example.net')
|
|
57
|
+
add('--port', default=80, type=int)
|
|
58
|
+
|
|
59
|
+
response = parse_message_subparsers.add_parser('response', parents=[self.parent_parser])
|
|
60
|
+
add = response.add_argument
|
|
61
|
+
response.set_defaults(func=self.parse_response)
|
|
62
|
+
add('--file', default='-', type=FileType('rb'))
|
|
63
|
+
|
|
64
|
+
def parse_arguments(self) -> None:
|
|
65
|
+
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
|
+
self.arguments.func()
|
|
71
|
+
|
|
72
|
+
def add_common_arguments(self, add) -> None:
|
|
73
|
+
add('--protocol')
|
|
74
|
+
add('-H', '--header', action='append', default=[])
|
|
75
|
+
add('-b', '--body', default='')
|
|
76
|
+
|
|
77
|
+
def parse_request(self) -> None:
|
|
78
|
+
server = ServerStateMachine(self.arguments.scheme, self.arguments.host, self.arguments.port)
|
|
79
|
+
for _request, response in server.parse(self.arguments.file.read()):
|
|
80
|
+
print(repr(response))
|
|
81
|
+
print(repr(response.headers))
|
|
82
|
+
print(repr(response.body))
|
|
83
|
+
|
|
84
|
+
def parse_response(self) -> None:
|
|
85
|
+
client = ClientStateMachine()
|
|
86
|
+
client.request = Request()
|
|
87
|
+
for response in client.parse(self.arguments.file.read()):
|
|
88
|
+
print(repr(response))
|
|
89
|
+
print(repr(response.headers))
|
|
90
|
+
print(repr(response.body))
|
|
91
|
+
print(repr(bytes(response.body)))
|
|
92
|
+
if client.buffer:
|
|
93
|
+
print('WARNING: response not yet complete!:')
|
|
94
|
+
print(repr(client.message))
|
|
95
|
+
print(repr(client.message.headers))
|
|
96
|
+
print(repr(client.message.body))
|
|
97
|
+
print(repr(client.buffer))
|
|
98
|
+
|
|
99
|
+
def compose_request(self) -> None:
|
|
100
|
+
self.message = Request()
|
|
101
|
+
if self.arguments.method:
|
|
102
|
+
self.message.method = self.arguments.method
|
|
103
|
+
if self.arguments.uri:
|
|
104
|
+
self.message.uri = self.arguments.uri
|
|
105
|
+
self.common()
|
|
106
|
+
|
|
107
|
+
def compose_response(self) -> None:
|
|
108
|
+
self.message = Response()
|
|
109
|
+
status = self.message.status.code
|
|
110
|
+
if self.arguments.status:
|
|
111
|
+
status = int(self.arguments.status)
|
|
112
|
+
if self.arguments.reason:
|
|
113
|
+
status = (status, self.arguments.reason)
|
|
114
|
+
self.message.status = status
|
|
115
|
+
self.common()
|
|
116
|
+
|
|
117
|
+
def common(self) -> None:
|
|
118
|
+
if self.arguments.protocol:
|
|
119
|
+
protocol = self.arguments.protocol
|
|
120
|
+
try:
|
|
121
|
+
protocol = [int(x) for x in protocol.split('.', 1)]
|
|
122
|
+
except ValueError:
|
|
123
|
+
pass
|
|
124
|
+
else:
|
|
125
|
+
self.message.protocol = protocol
|
|
126
|
+
for header in self.arguments.header:
|
|
127
|
+
try:
|
|
128
|
+
key, value = header.split(':', 1)
|
|
129
|
+
except ValueError:
|
|
130
|
+
continue
|
|
131
|
+
self.message.headers[key.strip()] = value.strip()
|
|
132
|
+
body = self.arguments.body
|
|
133
|
+
if body == '-':
|
|
134
|
+
body = sys.stdin.read()
|
|
135
|
+
elif body.startswith('@'):
|
|
136
|
+
body = pathlib.Path(body[1:]).open('rb')
|
|
137
|
+
self.message.body = body
|
|
138
|
+
|
|
139
|
+
sys.stdout.write(self.decode(bytes(self.message)))
|
|
140
|
+
sys.stdout.write(self.decode(bytes(self.message.headers)))
|
|
141
|
+
sys.stdout.write(self.decode(bytes(self.message.body)))
|
|
142
|
+
|
|
143
|
+
def decode(self, data):
|
|
144
|
+
if str is not bytes:
|
|
145
|
+
data = data.decode('ISO8859-1')
|
|
146
|
+
return data
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
if __name__ == '__main__':
|
|
150
|
+
CLI()
|