Skip to content

Commit

Permalink
Try parsing boundary from content-type
Browse files Browse the repository at this point in the history
  • Loading branch information
tw4l committed Nov 7, 2024
1 parent 63fa925 commit b738a65
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions cdxj_indexer/postquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from urllib.parse import unquote_plus, urlencode
from io import BytesIO

from multipart import parse_options_header, MultipartParser
from multipart import MultipartParser
from warcio.utils import to_native_str

from cdxj_indexer.amf import amf_parse
Expand Down Expand Up @@ -95,19 +95,18 @@ 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)
boundary = params["boundary"]
boundary = mime.split("boundary=")[1]
parser = MultipartParser(stream, boundary, charset="utf8")
except ValueError:
except (ValueError, IndexError):
# Content-Type multipart/form-data may lack "boundary" info
query = handle_binary(query_data)
else:
Expand Down

0 comments on commit b738a65

Please sign in to comment.