session-adapters 0.1.0__py3-none-any.whl
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.
- session_adapters/__about__.py +15 -0
- session_adapters/__init__.py +13 -0
- session_adapters/base.py +191 -0
- session_adapters/file_adapter.py +134 -0
- session_adapters/http_conts.py +282 -0
- session_adapters/oci_adapter.py +256 -0
- session_adapters/s3_adapter.py +238 -0
- session_adapters-0.1.0.dist-info/METADATA +117 -0
- session_adapters-0.1.0.dist-info/RECORD +11 -0
- session_adapters-0.1.0.dist-info/WHEEL +4 -0
- session_adapters-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copyright 2026 Terradue
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright 2026 Terradue
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
session_adapters/base.py
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# Copyright 2026 Terradue
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from session_adapters.http_conts import (
|
|
16
|
+
DEFAULT_ENCODING,
|
|
17
|
+
ContentType,
|
|
18
|
+
HTTPHeader,
|
|
19
|
+
HTTPMethod,
|
|
20
|
+
)
|
|
21
|
+
from abc import abstractmethod
|
|
22
|
+
from http import HTTPStatus
|
|
23
|
+
from magic import Magic
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
from requests import PreparedRequest, Response
|
|
26
|
+
from typing import Any, Dict, final, Generic, TypeVar, Union
|
|
27
|
+
from datetime import datetime
|
|
28
|
+
|
|
29
|
+
from requests.adapters import BaseAdapter
|
|
30
|
+
|
|
31
|
+
import mimetypes
|
|
32
|
+
|
|
33
|
+
__DEFAULT_READ_MODE__ = "rb"
|
|
34
|
+
|
|
35
|
+
__DATE_HEADER_FORMAT__ = "%a, %d %b %Y %H:%M:%S GMT"
|
|
36
|
+
|
|
37
|
+
AdapterRequest = TypeVar("AdapterRequest")
|
|
38
|
+
|
|
39
|
+
magic = Magic(mime=True, uncompress=True)
|
|
40
|
+
|
|
41
|
+
# Ensure YAML extensions are known by the stdlib
|
|
42
|
+
mimetypes.add_type(ContentType.YAML.value, ".yaml")
|
|
43
|
+
mimetypes.add_type(ContentType.YAML.value, ".yml")
|
|
44
|
+
mimetypes.add_type(ContentType.YAML.value, ".cwl")
|
|
45
|
+
|
|
46
|
+
# Optional: add other common texty types if you care
|
|
47
|
+
mimetypes.add_type(ContentType.JSON.value, ".json")
|
|
48
|
+
mimetypes.add_type(ContentType.XML.value, ".xml")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class ExtendedResponse(Response):
|
|
52
|
+
def __init__(self):
|
|
53
|
+
super().__init__()
|
|
54
|
+
|
|
55
|
+
@final
|
|
56
|
+
def send_status(self, http_status: HTTPStatus):
|
|
57
|
+
self.status_code = http_status.value
|
|
58
|
+
self.reason = http_status.phrase
|
|
59
|
+
|
|
60
|
+
@final
|
|
61
|
+
def send_header(self, name: Union[str, HTTPHeader], value: Any):
|
|
62
|
+
self.headers[str(name)] = str(value)
|
|
63
|
+
|
|
64
|
+
@final
|
|
65
|
+
def send_date_header(self, name: Union[str, HTTPHeader], value: datetime):
|
|
66
|
+
self.send_header(name=name, value=value.strftime(__DATE_HEADER_FORMAT__))
|
|
67
|
+
|
|
68
|
+
@final
|
|
69
|
+
def send_headers(self, headers_dict: Dict[HTTPHeader, Any]):
|
|
70
|
+
if headers_dict:
|
|
71
|
+
for key, value in headers_dict.items():
|
|
72
|
+
self.send_header(name=key, value=value)
|
|
73
|
+
|
|
74
|
+
@final
|
|
75
|
+
def send_file_info(self, path: Path):
|
|
76
|
+
stat_info = path.stat()
|
|
77
|
+
mod_time_timestamp = stat_info.st_mtime
|
|
78
|
+
mod_time = datetime.fromtimestamp(mod_time_timestamp)
|
|
79
|
+
|
|
80
|
+
self.send_status(HTTPStatus.OK)
|
|
81
|
+
self.send_date_header(HTTPHeader.LAST_MODIFIED, mod_time)
|
|
82
|
+
|
|
83
|
+
mime = magic.from_file(path)
|
|
84
|
+
if not mime or ContentType.PLAIN == ContentType(mime):
|
|
85
|
+
guess_mime = mimetypes.guess_type(path)
|
|
86
|
+
if guess_mime:
|
|
87
|
+
mime = guess_mime[0]
|
|
88
|
+
|
|
89
|
+
self.send_header(HTTPHeader.CONTENT_TYPE, mime)
|
|
90
|
+
|
|
91
|
+
@final
|
|
92
|
+
def send_error(self, http_status: HTTPStatus, error: Any):
|
|
93
|
+
self.send_status(http_status)
|
|
94
|
+
self._content = str(error).encode(DEFAULT_ENCODING)
|
|
95
|
+
self.send_headers(
|
|
96
|
+
{
|
|
97
|
+
HTTPHeader.CONTENT_TYPE: ContentType.PLAIN,
|
|
98
|
+
HTTPHeader.CONTENT_LENGTH: len(self._content),
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class AbstractAdapter(BaseAdapter, Generic[AdapterRequest]):
|
|
104
|
+
def __init__(self):
|
|
105
|
+
super(AbstractAdapter, self).__init__()
|
|
106
|
+
|
|
107
|
+
self.allowed_methods = ", ".join(
|
|
108
|
+
list(
|
|
109
|
+
map(
|
|
110
|
+
lambda method: method.name,
|
|
111
|
+
[
|
|
112
|
+
HTTPMethod.GET,
|
|
113
|
+
HTTPMethod.HEAD,
|
|
114
|
+
HTTPMethod.PUT,
|
|
115
|
+
HTTPMethod.DELETE,
|
|
116
|
+
],
|
|
117
|
+
)
|
|
118
|
+
)
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
# ----- requests.Adapter API -----
|
|
122
|
+
|
|
123
|
+
@final
|
|
124
|
+
def send(
|
|
125
|
+
self,
|
|
126
|
+
request: PreparedRequest,
|
|
127
|
+
stream=False,
|
|
128
|
+
timeout=None,
|
|
129
|
+
verify=True,
|
|
130
|
+
cert=None,
|
|
131
|
+
proxies=None,
|
|
132
|
+
) -> Response:
|
|
133
|
+
"""
|
|
134
|
+
Map the PreparedRequest (s3://bucket/key) to a boto3 call and wrap the
|
|
135
|
+
result into a requests.Response.
|
|
136
|
+
"""
|
|
137
|
+
response = ExtendedResponse()
|
|
138
|
+
response.url = (
|
|
139
|
+
request.url if request.url else ""
|
|
140
|
+
) # should not happen, but IDE complains
|
|
141
|
+
response.request = request
|
|
142
|
+
response.send_date_header(HTTPHeader.DATE, datetime.now())
|
|
143
|
+
|
|
144
|
+
try:
|
|
145
|
+
parsed_request = self.parse_request(request=request)
|
|
146
|
+
|
|
147
|
+
# Normalize method
|
|
148
|
+
method = (
|
|
149
|
+
HTTPMethod(request.method.upper()) if request.method else HTTPMethod.GET
|
|
150
|
+
) # should not happen
|
|
151
|
+
|
|
152
|
+
match method:
|
|
153
|
+
case HTTPMethod.GET:
|
|
154
|
+
self.do_get(request=parsed_request, response=response)
|
|
155
|
+
|
|
156
|
+
case HTTPMethod.HEAD:
|
|
157
|
+
self.do_head(request=parsed_request, response=response)
|
|
158
|
+
|
|
159
|
+
case HTTPMethod.PUT:
|
|
160
|
+
self.do_put(request=parsed_request, response=response)
|
|
161
|
+
|
|
162
|
+
case HTTPMethod.DELETE:
|
|
163
|
+
self.do_delete(request=parsed_request, response=response)
|
|
164
|
+
|
|
165
|
+
case _:
|
|
166
|
+
response.send_status(HTTPStatus.METHOD_NOT_ALLOWED)
|
|
167
|
+
response.send_header(HTTPHeader.ALLOW, self.allowed_methods)
|
|
168
|
+
except ValueError as ve:
|
|
169
|
+
response.send_error(HTTPStatus.METHOD_NOT_ALLOWED, ve)
|
|
170
|
+
except TypeError as te:
|
|
171
|
+
response.send_error(HTTPStatus.BAD_REQUEST, te)
|
|
172
|
+
except Exception as e:
|
|
173
|
+
response.send_error(HTTPStatus.INTERNAL_SERVER_ERROR, e)
|
|
174
|
+
|
|
175
|
+
return response
|
|
176
|
+
|
|
177
|
+
@abstractmethod
|
|
178
|
+
def parse_request(self, request: PreparedRequest) -> AdapterRequest:
|
|
179
|
+
pass
|
|
180
|
+
|
|
181
|
+
def do_head(self, request: AdapterRequest, response: ExtendedResponse):
|
|
182
|
+
response.send_status(HTTPStatus.NOT_IMPLEMENTED)
|
|
183
|
+
|
|
184
|
+
def do_get(self, request: AdapterRequest, response: ExtendedResponse):
|
|
185
|
+
response.send_status(HTTPStatus.NOT_IMPLEMENTED)
|
|
186
|
+
|
|
187
|
+
def do_put(self, request: AdapterRequest, response: ExtendedResponse):
|
|
188
|
+
response.send_status(HTTPStatus.NOT_IMPLEMENTED)
|
|
189
|
+
|
|
190
|
+
def do_delete(self, request: AdapterRequest, response: ExtendedResponse):
|
|
191
|
+
response.send_status(HTTPStatus.NOT_IMPLEMENTED)
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Copyright 2026 Terradue
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from session_adapters.base import (
|
|
16
|
+
AbstractAdapter,
|
|
17
|
+
ExtendedResponse,
|
|
18
|
+
__DEFAULT_READ_MODE__,
|
|
19
|
+
)
|
|
20
|
+
from session_adapters.http_conts import HTTPHeader
|
|
21
|
+
from http import HTTPStatus
|
|
22
|
+
from loguru import logger
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
from pydantic import BaseModel
|
|
25
|
+
from shutil import rmtree
|
|
26
|
+
from requests import PreparedRequest
|
|
27
|
+
from urllib.parse import urlparse
|
|
28
|
+
from typing import Any, final
|
|
29
|
+
|
|
30
|
+
import errno
|
|
31
|
+
import io
|
|
32
|
+
|
|
33
|
+
import os
|
|
34
|
+
|
|
35
|
+
__DEFAULT_WRITE_MODE__ = "w"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class _FileRequest(BaseModel):
|
|
39
|
+
path: Path
|
|
40
|
+
# from original request
|
|
41
|
+
body: Any
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@final
|
|
45
|
+
class FileAdapter(AbstractAdapter[_FileRequest]):
|
|
46
|
+
def __init__(self):
|
|
47
|
+
super(FileAdapter, self).__init__()
|
|
48
|
+
|
|
49
|
+
def parse_request(self, request: PreparedRequest) -> _FileRequest:
|
|
50
|
+
url_parts = urlparse(request.url)
|
|
51
|
+
|
|
52
|
+
if url_parts.netloc and url_parts.netloc != "localhost":
|
|
53
|
+
raise TypeError(
|
|
54
|
+
"URLs with hostname components are not allowed, 'localhost' supported only"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
return _FileRequest(path=Path(str(url_parts.path)), body=request.body or b"")
|
|
58
|
+
|
|
59
|
+
def do_head(self, request: _FileRequest, response: ExtendedResponse):
|
|
60
|
+
try:
|
|
61
|
+
if request.path.exists():
|
|
62
|
+
response.send_file_info(request.path)
|
|
63
|
+
else:
|
|
64
|
+
response.send_error(
|
|
65
|
+
HTTPStatus.NOT_FOUND,
|
|
66
|
+
f"File {request.path} does not exist on the local File System",
|
|
67
|
+
)
|
|
68
|
+
except IOError as ioe:
|
|
69
|
+
match ioe.errno:
|
|
70
|
+
case errno.EACCES:
|
|
71
|
+
response.send_error(HTTPStatus.FORBIDDEN, ioe)
|
|
72
|
+
|
|
73
|
+
case errno.ENOENT:
|
|
74
|
+
response.send_error(HTTPStatus.NOT_FOUND, ioe)
|
|
75
|
+
|
|
76
|
+
case _:
|
|
77
|
+
response.send_error(HTTPStatus.BAD_REQUEST, ioe)
|
|
78
|
+
|
|
79
|
+
def do_get(self, request: _FileRequest, response: ExtendedResponse):
|
|
80
|
+
try:
|
|
81
|
+
if request.path.exists():
|
|
82
|
+
response.send_file_info(request.path)
|
|
83
|
+
|
|
84
|
+
if request.path.is_file():
|
|
85
|
+
response.raw = io.open(request.path, __DEFAULT_READ_MODE__)
|
|
86
|
+
response.raw.release_conn = response.raw.close
|
|
87
|
+
|
|
88
|
+
response.send_header(
|
|
89
|
+
HTTPHeader.CONTENT_LENGTH, str(request.path.stat().st_size)
|
|
90
|
+
)
|
|
91
|
+
else:
|
|
92
|
+
# TODO file listing
|
|
93
|
+
logger.warning("TODO: file listing is not supported yet")
|
|
94
|
+
response.send_status(HTTPStatus.NOT_IMPLEMENTED)
|
|
95
|
+
else:
|
|
96
|
+
response.send_error(
|
|
97
|
+
HTTPStatus.NOT_FOUND,
|
|
98
|
+
f"File {request.path} does not exist on the local File System",
|
|
99
|
+
)
|
|
100
|
+
except IOError as ioe:
|
|
101
|
+
match ioe.errno:
|
|
102
|
+
case errno.EACCES:
|
|
103
|
+
response.send_error(HTTPStatus.FORBIDDEN, ioe)
|
|
104
|
+
|
|
105
|
+
case errno.ENOENT:
|
|
106
|
+
response.send_error(HTTPStatus.NOT_FOUND, ioe)
|
|
107
|
+
|
|
108
|
+
case _:
|
|
109
|
+
response.send_error(HTTPStatus.BAD_REQUEST, ioe)
|
|
110
|
+
|
|
111
|
+
def do_delete(self, request: _FileRequest, response: ExtendedResponse):
|
|
112
|
+
self.do_head(request, response)
|
|
113
|
+
|
|
114
|
+
try:
|
|
115
|
+
if request.path.exists():
|
|
116
|
+
if request.path.is_dir():
|
|
117
|
+
rmtree(request.path.absolute())
|
|
118
|
+
elif request.path.is_file():
|
|
119
|
+
os.remove(request.path.absolute())
|
|
120
|
+
except IOError:
|
|
121
|
+
pass
|
|
122
|
+
|
|
123
|
+
def do_put(self, request: _FileRequest, response: ExtendedResponse):
|
|
124
|
+
request.path.parent.mkdir(parents=True, exist_ok=True)
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
with request.path.open(__DEFAULT_WRITE_MODE__) as f:
|
|
128
|
+
f.write(request.body)
|
|
129
|
+
except IOError as ioe:
|
|
130
|
+
response.send_error(HTTPStatus.INTERNAL_SERVER_ERROR, ioe)
|
|
131
|
+
|
|
132
|
+
def close(self):
|
|
133
|
+
# No persistent sockets to close beyond what botocore manages, but keep hook for API parity.
|
|
134
|
+
pass
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# Copyright 2026 Terradue
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from enum import auto, Enum
|
|
16
|
+
|
|
17
|
+
DEFAULT_ENCODING = "utf-8"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class HTTPMethod(Enum):
|
|
21
|
+
"""
|
|
22
|
+
A comprehensive Enum of HTTP methods.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def _generate_next_value_(name, start, count, last_values):
|
|
27
|
+
return name # ensures auto() = member name as string
|
|
28
|
+
|
|
29
|
+
GET = auto()
|
|
30
|
+
HEAD = auto()
|
|
31
|
+
PUT = auto()
|
|
32
|
+
DELETE = auto()
|
|
33
|
+
POST = auto()
|
|
34
|
+
OPTIONS = auto()
|
|
35
|
+
PATCH = auto()
|
|
36
|
+
CONNECT = auto()
|
|
37
|
+
TRACE = auto()
|
|
38
|
+
|
|
39
|
+
def __str__(self) -> str:
|
|
40
|
+
return self.name
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class HTTPHeader(str, Enum):
|
|
44
|
+
"""
|
|
45
|
+
A comprehensive Enum of HTTP header names, modeled after common fields from
|
|
46
|
+
IANA’s HTTP Field Name Registry and de-facto headers used on the web.
|
|
47
|
+
|
|
48
|
+
Usage:
|
|
49
|
+
from http_headers import HttpHeader
|
|
50
|
+
headers = {HttpHeader.CONTENT_TYPE: "application/json"}
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
# --- Request headers ---
|
|
54
|
+
A_IM = "A-IM"
|
|
55
|
+
ACCEPT = "Accept"
|
|
56
|
+
ACCEPT_CH = "Accept-CH"
|
|
57
|
+
ACCEPT_CH_LIFETIME = "Accept-CH-Lifetime"
|
|
58
|
+
ACCEPT_ENCODING = "Accept-Encoding"
|
|
59
|
+
ACCEPT_LANGUAGE = "Accept-Language"
|
|
60
|
+
ACCEPT_PATCH = "Accept-Patch"
|
|
61
|
+
ACCEPT_POST = "Accept-Post"
|
|
62
|
+
ACCEPT_RANGES = "Accept-Ranges"
|
|
63
|
+
ACCEPT_SIGNATURE = "Accept-Signature" # draft/non-standard in many stacks
|
|
64
|
+
ACCESS_CONTROL_REQUEST_HEADERS = "Access-Control-Request-Headers"
|
|
65
|
+
ACCESS_CONTROL_REQUEST_METHOD = "Access-Control-Request-Method"
|
|
66
|
+
AUTHORIZATION = "Authorization"
|
|
67
|
+
CACHE_CONTROL = "Cache-Control"
|
|
68
|
+
CONNECTION = "Connection"
|
|
69
|
+
CONTENT_LENGTH = "Content-Length"
|
|
70
|
+
CONTENT_TYPE = "Content-Type"
|
|
71
|
+
COOKIE = "Cookie"
|
|
72
|
+
DATE = "Date"
|
|
73
|
+
DEVICE_MEMORY = "Device-Memory" # Client Hints
|
|
74
|
+
DNT = "DNT"
|
|
75
|
+
DPR = "DPR" # Client Hints
|
|
76
|
+
EARLY_DATA = "Early-Data"
|
|
77
|
+
EXPECT = "Expect"
|
|
78
|
+
FORWARDED = "Forwarded"
|
|
79
|
+
FROM = "From"
|
|
80
|
+
HOST = "Host"
|
|
81
|
+
IF_MATCH = "If-Match"
|
|
82
|
+
IF_MODIFIED_SINCE = "If-Modified-Since"
|
|
83
|
+
IF_NONE_MATCH = "If-None-Match"
|
|
84
|
+
IF_RANGE = "If-Range"
|
|
85
|
+
IF_UNMODIFIED_SINCE = "If-Unmodified-Since"
|
|
86
|
+
KEEP_ALIVE = "Keep-Alive"
|
|
87
|
+
MAX_FORWARDS = "Max-Forwards"
|
|
88
|
+
ORIGIN = "Origin"
|
|
89
|
+
PERMISSIONS_POLICY = "Permissions-Policy" # formerly Feature-Policy
|
|
90
|
+
PRAGMA = "Pragma"
|
|
91
|
+
PRIORITY = "Priority"
|
|
92
|
+
PROXY_AUTHORIZATION = "Proxy-Authorization"
|
|
93
|
+
RANGE = "Range"
|
|
94
|
+
REFERER = "Referer"
|
|
95
|
+
REFERRER_POLICY = "Referrer-Policy"
|
|
96
|
+
SAVE_DATA = "Save-Data" # Client Hint
|
|
97
|
+
SEC_CH_UA = "Sec-CH-UA"
|
|
98
|
+
SEC_CH_UA_ARCH = "Sec-CH-UA-Arch"
|
|
99
|
+
SEC_CH_UA_BITNESS = "Sec-CH-UA-Bitness"
|
|
100
|
+
SEC_CH_UA_FULL_VERSION = "Sec-CH-UA-Full-Version"
|
|
101
|
+
SEC_CH_UA_FULL_VERSION_LIST = "Sec-CH-UA-Full-Version-List"
|
|
102
|
+
SEC_CH_UA_MOBILE = "Sec-CH-UA-Mobile"
|
|
103
|
+
SEC_CH_UA_MODEL = "Sec-CH-UA-Model"
|
|
104
|
+
SEC_CH_UA_PLATFORM = "Sec-CH-UA-Platform"
|
|
105
|
+
SEC_CH_UA_PLATFORM_VERSION = "Sec-CH-UA-Platform-Version"
|
|
106
|
+
SEC_FETCH_DEST = "Sec-Fetch-Dest"
|
|
107
|
+
SEC_FETCH_MODE = "Sec-Fetch-Mode"
|
|
108
|
+
SEC_FETCH_SITE = "Sec-Fetch-Site"
|
|
109
|
+
SEC_FETCH_USER = "Sec-Fetch-User"
|
|
110
|
+
SEC_GPC = "Sec-GPC"
|
|
111
|
+
SEC_PURPOSE = "Sec-Purpose"
|
|
112
|
+
TE = "TE"
|
|
113
|
+
TRAILER = "Trailer"
|
|
114
|
+
TRANSFER_ENCODING = "Transfer-Encoding"
|
|
115
|
+
UPGRADE = "Upgrade"
|
|
116
|
+
UPGRADE_INSECURE_REQUESTS = "Upgrade-Insecure-Requests"
|
|
117
|
+
USER_AGENT = "User-Agent"
|
|
118
|
+
VIA = "Via"
|
|
119
|
+
VIEWPORT_WIDTH = "Viewport-Width" # Client Hints
|
|
120
|
+
WIDTH = "Width" # Client Hints
|
|
121
|
+
|
|
122
|
+
# --- Response headers ---
|
|
123
|
+
ACCEPT_RANGES_RESP = "Accept-Ranges"
|
|
124
|
+
ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials"
|
|
125
|
+
ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers"
|
|
126
|
+
ACCESS_CONTROL_ALLOW_METHODS = "Access-Control-Allow-Methods"
|
|
127
|
+
ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin"
|
|
128
|
+
ACCESS_CONTROL_EXPOSE_HEADERS = "Access-Control-Expose-Headers"
|
|
129
|
+
ACCESS_CONTROL_MAX_AGE = "Access-Control-Max-Age"
|
|
130
|
+
AGE = "Age"
|
|
131
|
+
ALLOW = "Allow"
|
|
132
|
+
ALT_SVC = "Alt-Svc"
|
|
133
|
+
ALT_USED = "Alt-Used"
|
|
134
|
+
CONTENT_DISPOSITION = "Content-Disposition"
|
|
135
|
+
CONTENT_ENCODING = "Content-Encoding"
|
|
136
|
+
CONTENT_LANGUAGE = "Content-Language"
|
|
137
|
+
CONTENT_LOCATION = "Content-Location"
|
|
138
|
+
CONTENT_RANGE = "Content-Range"
|
|
139
|
+
CONTENT_SECURITY_POLICY = "Content-Security-Policy"
|
|
140
|
+
CONTENT_SECURITY_POLICY_REPORT_ONLY = "Content-Security-Policy-Report-Only"
|
|
141
|
+
ETAG = "ETag"
|
|
142
|
+
EXPIRES = "Expires"
|
|
143
|
+
LAST_MODIFIED = "Last-Modified"
|
|
144
|
+
LINK = "Link"
|
|
145
|
+
LOCATION = "Location"
|
|
146
|
+
NEL = "NEL"
|
|
147
|
+
PROXY_AUTHENTICATE = "Proxy-Authenticate"
|
|
148
|
+
REPORT_TO = "Report-To" # deprecated in favor of Reporting-Endpoints
|
|
149
|
+
REPORTING_ENDPOINTS = "Reporting-Endpoints"
|
|
150
|
+
RETRY_AFTER = "Retry-After"
|
|
151
|
+
SERVER = "Server"
|
|
152
|
+
SERVER_TIMING = "Server-Timing"
|
|
153
|
+
SET_COOKIE = "Set-Cookie"
|
|
154
|
+
SOURCE_MAP = "SourceMap"
|
|
155
|
+
STRICT_TRANSPORT_SECURITY = "Strict-Transport-Security"
|
|
156
|
+
TIMING_ALLOW_ORIGIN = "Timing-Allow-Origin"
|
|
157
|
+
VARY = "Vary"
|
|
158
|
+
WWW_AUTHENTICATE = "WWW-Authenticate"
|
|
159
|
+
X_CONTENT_TYPE_OPTIONS = "X-Content-Type-Options"
|
|
160
|
+
X_DNS_PREFETCH_CONTROL = "X-DNS-Prefetch-Control"
|
|
161
|
+
X_FRAME_OPTIONS = "X-Frame-Options"
|
|
162
|
+
X_PERMITTED_CROSS_DOMAIN_POLICIES = "X-Permitted-Cross-Domain-Policies"
|
|
163
|
+
X_POWERED_BY = "X-Powered-By"
|
|
164
|
+
X_REQUEST_ID = "X-Request-Id"
|
|
165
|
+
X_RESPONSE_TIME = "X-Response-Time"
|
|
166
|
+
X_XSS_PROTECTION = "X-XSS-Protection"
|
|
167
|
+
X_FORWARDED_FOR = "X-Forwarded-For"
|
|
168
|
+
X_FORWARDED_HOST = "X-Forwarded-Host"
|
|
169
|
+
X_FORWARDED_PROTO = "X-Forwarded-Proto"
|
|
170
|
+
|
|
171
|
+
# --- Common both-sides / misc ---
|
|
172
|
+
CONTENT_MD5 = "Content-MD5" # non-standard but seen
|
|
173
|
+
EXPECT_CT = "Expect-CT" # largely deprecated
|
|
174
|
+
# HTTP Message Signatures (RFC 9421)
|
|
175
|
+
SIGNATURE = "Signature"
|
|
176
|
+
SIGNATURE_INPUT = "Signature-Input"
|
|
177
|
+
# HTTP Representation Digest (RFC 9530)
|
|
178
|
+
CONTENT_DIGEST = "Content-Digest"
|
|
179
|
+
REPR_DIGEST = "Repr-Digest"
|
|
180
|
+
|
|
181
|
+
# Cloud/CDN/observability (non-standard but widely used)
|
|
182
|
+
CF_CACHE_STATUS = "CF-Cache-Status"
|
|
183
|
+
CF_RAY = "CF-RAY"
|
|
184
|
+
CDN_CACHE_CONTROL = "CDN-Cache-Control"
|
|
185
|
+
FLY_REQUEST_ID = "Fly-Request-Id"
|
|
186
|
+
X_AMZN_TRACE_ID = "X-Amzn-Trace-Id"
|
|
187
|
+
X_AZURE_REF = "X-Azure-Ref"
|
|
188
|
+
X_CACHE = "X-Cache"
|
|
189
|
+
X_CACHE_HIT = "X-Cache-Hit"
|
|
190
|
+
X_CORRELATION_ID = "X-Correlation-ID"
|
|
191
|
+
X_REQUESTED_WITH = "X-Requested-With"
|
|
192
|
+
|
|
193
|
+
# Security / COOP/COEP/CORP
|
|
194
|
+
CROSS_ORIGIN_EMBEDDER_POLICY = "Cross-Origin-Embedder-Policy"
|
|
195
|
+
CROSS_ORIGIN_OPENER_POLICY = "Cross-Origin-Opener-Policy"
|
|
196
|
+
CROSS_ORIGIN_RESOURCE_POLICY = "Cross-Origin-Resource-Policy"
|
|
197
|
+
|
|
198
|
+
def __str__(self) -> str:
|
|
199
|
+
return self.value
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
# Convenience: a frozenset of canonical "entity" headers
|
|
203
|
+
ENTITY_HEADER_SET = frozenset(
|
|
204
|
+
{
|
|
205
|
+
HTTPHeader.CONTENT_TYPE,
|
|
206
|
+
HTTPHeader.CONTENT_LENGTH,
|
|
207
|
+
HTTPHeader.CONTENT_ENCODING,
|
|
208
|
+
HTTPHeader.CONTENT_LANGUAGE,
|
|
209
|
+
HTTPHeader.CONTENT_DISPOSITION,
|
|
210
|
+
HTTPHeader.CONTENT_LOCATION,
|
|
211
|
+
HTTPHeader.CONTENT_RANGE,
|
|
212
|
+
HTTPHeader.CONTENT_MD5,
|
|
213
|
+
HTTPHeader.CONTENT_DIGEST,
|
|
214
|
+
}
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
class ContentType(str, Enum):
|
|
219
|
+
# --- Text ---
|
|
220
|
+
PLAIN = "text/plain"
|
|
221
|
+
HTML = "text/html"
|
|
222
|
+
CSS = "text/css"
|
|
223
|
+
CSV = "text/csv"
|
|
224
|
+
TEXT_JAVASCRIPT = "text/javascript"
|
|
225
|
+
MARKDOWN = "text/markdown"
|
|
226
|
+
XML_TEXT = "text/xml"
|
|
227
|
+
|
|
228
|
+
# --- Application / structured text ---
|
|
229
|
+
JSON = "application/json"
|
|
230
|
+
PROBLEM_JSON = "application/problem+json"
|
|
231
|
+
SCHEMA_JSON = "application/schema+json"
|
|
232
|
+
XML = "application/xml"
|
|
233
|
+
YAML = "application/x-yaml"
|
|
234
|
+
FORM_URLENCODED = "application/x-www-form-urlencoded"
|
|
235
|
+
OCTET_STREAM = "application/octet-stream"
|
|
236
|
+
PDF = "application/pdf"
|
|
237
|
+
ZIP = "application/zip"
|
|
238
|
+
GZIP = "application/gzip"
|
|
239
|
+
TAR = "application/x-tar"
|
|
240
|
+
RTF = "application/rtf"
|
|
241
|
+
APPLICATION_JAVASCRIPT = "application/javascript"
|
|
242
|
+
|
|
243
|
+
# --- Multipart ---
|
|
244
|
+
MULTIPART_FORM = "multipart/form-data"
|
|
245
|
+
MULTIPART_MIXED = "multipart/mixed"
|
|
246
|
+
MULTIPART_ALTERNATIVE = "multipart/alternative"
|
|
247
|
+
MULTIPART_RELATED = "multipart/related"
|
|
248
|
+
|
|
249
|
+
# --- Images ---
|
|
250
|
+
JPEG = "image/jpeg"
|
|
251
|
+
PNG = "image/png"
|
|
252
|
+
GIF = "image/gif"
|
|
253
|
+
WEBP = "image/webp"
|
|
254
|
+
SVG = "image/svg+xml"
|
|
255
|
+
TIFF = "image/tiff"
|
|
256
|
+
BMP = "image/bmp"
|
|
257
|
+
ICON = "image/x-icon"
|
|
258
|
+
|
|
259
|
+
# --- Audio ---
|
|
260
|
+
MP3 = "audio/mpeg"
|
|
261
|
+
OGG = "audio/ogg"
|
|
262
|
+
WAV = "audio/wav"
|
|
263
|
+
WEBM_AUDIO = "audio/webm"
|
|
264
|
+
|
|
265
|
+
# --- Video ---
|
|
266
|
+
MP4 = "video/mp4"
|
|
267
|
+
MPEG = "video/mpeg"
|
|
268
|
+
OGG_VIDEO = "video/ogg"
|
|
269
|
+
WEBM_VIDEO = "video/webm"
|
|
270
|
+
QUICKTIME = "video/quicktime"
|
|
271
|
+
|
|
272
|
+
# --- Fonts ---
|
|
273
|
+
WOFF = "font/woff"
|
|
274
|
+
WOFF2 = "font/woff2"
|
|
275
|
+
TTF = "font/ttf"
|
|
276
|
+
OTF = "font/otf"
|
|
277
|
+
|
|
278
|
+
# --- Misc / Special ---
|
|
279
|
+
ANY = "*/*"
|
|
280
|
+
|
|
281
|
+
def __str__(self) -> str:
|
|
282
|
+
return self.value
|