Below are the points to be considered.
-
Get the first header value for the name.
-
Trim the leading and trailing white spaces.
-
Replace all repeated white spaces with a single space.
-
Concatenate the name, value pairs with the tab (\t)separator(name field is all in lower case).
-
Terminate the headers with another tab (\t) separator.
import re
headers ={
"Accept" : "application/vnd.accept_header-status.v11+json",
"Content-Type" : "application/vnd.content-type_header.v11+json"
}canonicalize_headers=’\t’.join(h for h in headers)
print(canonicalize_headers)
Sample input:
Host: akaa-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx.aa-dev.net.net
x-a: va
x-c: " xc "
x-b: w b
Sample Output:
POST\thttp\takaa-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx.aa-dev.net\t
/sample-api/v1/property/?fields=x&format=json&cpcode=1234\tx-a:va\tx-b:w b\tx-c:" xc "\t\t\t
need to create a post request with signing headers, link for documentation:
https://developer.akamai.com/legacy/introduction/Client_Auth.html
>Solution :
From what I have understood, what you are looking for is:
def clean(headers):
for k, v in headers.items:
k = re.sub(r"\s+", " ", k.strip())
yield f"{k.lower()}\t{v}"
canonicalize_headers = "\t".join(clean(headers))