forked from dotX12/fastapi-gateway
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathheaders.py
More file actions
36 lines (30 loc) · 988 Bytes
/
Copy pathheaders.py
File metadata and controls
36 lines (30 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from starlette.datastructures import MutableHeaders, Headers
from typing import Dict, Any
def inheritance_service_headers(
gateway_headers: MutableHeaders,
service_headers: MutableHeaders,
) -> Dict[str, Any]:
forced_gateway_headers = [
"server",
"date",
"content-encoding",
"content-type",
"content-length",
]
return {
key: service_headers[key]
for key in service_headers
if key not in gateway_headers and key.lower() not in forced_gateway_headers
}
def generate_headers_for_microservice(headers: Headers) -> MutableHeaders:
new_headers = headers.mutablecopy()
gateway_host = headers.get("host")
new_headers.append("gateway_host", gateway_host)
forced_gateway_headers = [
"host",
"content-type",
"accept-encoding",
"content-length",
]
[new_headers.__delitem__(key_header) for key_header in forced_gateway_headers]
return new_headers