File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -58,3 +58,28 @@ def get_all_request_data(request):
58
58
return combined_data
59
59
except Exception as e :
60
60
raise ParseError (f"Error extracting all request data: { str (e )} " )
61
+
62
+ def get_request_headers (request ):
63
+ """
64
+ Gets all headers from the request object.
65
+
66
+ :param request: Petra request object
67
+ :return: Dictionary containing all request headers
68
+ """
69
+ try :
70
+ # META keys starting with 'HTTP_' contain the HTTP headers
71
+ headers = {
72
+ key [5 :].lower ().replace ('_' , '-' ): value
73
+ for key , value in request .META .items ()
74
+ if key .startswith ('HTTP_' )
75
+ }
76
+
77
+ # Special handling for Content-Type and Content-Length as they don't have HTTP_ prefix
78
+ if 'CONTENT_TYPE' in request .META :
79
+ headers ['content-type' ] = request .META ['CONTENT_TYPE' ]
80
+ if 'CONTENT_LENGTH' in request .META :
81
+ headers ['content-length' ] = request .META ['CONTENT_LENGTH' ]
82
+
83
+ return headers
84
+ except Exception as e :
85
+ raise ParseError (f"Error extracting request headers: { str (e )} " )
You can’t perform that action at this time.
0 commit comments