Skip to content

Commit

Permalink
Parse full headers
Browse files Browse the repository at this point in the history
  • Loading branch information
tw4l committed Oct 28, 2024
1 parent aacac30 commit 8efb4c6
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions cdxj_indexer/postquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ def append_method_query_from_req_resp(req, resp):

url = req.rec_headers.get_header("WARC-Target-URI")
method = req.http_headers.protocol
return append_method_query(method, content_type, len_, stream, url)
return append_method_query(method, content_type, len_, stream, url, req.http_headers)


# ============================================================================
def append_method_query(method, content_type, len_, stream, url):
def append_method_query(method, content_type, len_, stream, url, request_headers):
# if method == 'GET':
# return '', ''

if method == "POST" or method == "PUT":
query = query_extract(content_type, len_, stream, url)
query = query_extract(content_type, len_, stream, url, request_headers)
else:
query = ""

Expand All @@ -49,7 +49,7 @@ def append_method_query(method, content_type, len_, stream, url):


# ============================================================================
def query_extract(mime, length, stream, url):
def query_extract(mime, length, stream, url, request_headers):
"""
Extract a url-encoded form POST/PUT from stream
content length, return None
Expand Down Expand Up @@ -95,19 +95,19 @@ def handle_binary(query_data):
query = handle_binary(query_data)

elif mime.startswith("multipart/"):
env = {
"REQUEST_METHOD": "POST",
"CONTENT_TYPE": mime,
"CONTENT_LENGTH": len(query_data),
}
# env = {
# "REQUEST_METHOD": "POST",
# "CONTENT_TYPE": mime,
# "CONTENT_LENGTH": len(query_data),
# }

args = dict(fp=BytesIO(query_data), environ=env, keep_blank_values=True)
# args = dict(fp=BytesIO(query_data), environ=env, keep_blank_values=True)

try:
_, params = parse_options_header(mime)
_, params = parse_options_header(request_headers)
boundary = params["boundary"]
parser = MultipartParser(stream, boundary, charset="utf8")
except ValueError:
except KeyError:
# Content-Type multipart/form-data may lack "boundary" info
query = handle_binary(query_data)
else:
Expand Down

0 comments on commit 8efb4c6

Please sign in to comment.