mirror of
https://github.com/EDCD/EDDN.git
synced 2025-06-15 06:42:26 +03:00
Gateway: Properly report 'not compressed, badly form-encoded' to uploaders
* This code worked if the request was *properly* form-encoded, with a 'data' key whose value was a valid message. * It failed to detect where the request was form-encoded, with without a 'data' key. It would just assume 'not form-encoded' in that case, then fail later on JSON parsing. Thus, re-use the `urlparse.parse_qs()` check for form-encoded format. This passes: 1. Properly, `data` key, form-encoded with valid value is fully JSON parsed, schema checked and accepted. 2. *NOT* compressed *or* form-encoded valid message is properly parsed and accepted. 2. Uncompressed, form-encoded, but no `data` key correctly returns the same error status and body as the compressed+form-encoded+no data key path.
This commit is contained in:
parent
872af7f594
commit
10d70bfe77
@ -164,13 +164,28 @@ def get_decompressed_message():
|
|||||||
logger.debug('Request is *NOT* form-encoded')
|
logger.debug('Request is *NOT* form-encoded')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Uncompressed request. Bottle handles all of the parsing of the
|
logger.debug('Content-Encoding indicates *not* compressed...')
|
||||||
# POST key/vals, or un-encoded body.
|
|
||||||
data_key = request.forms.get('data')
|
form_enc_parsed = urlparse.parse_qs(request.body.read())
|
||||||
if data_key:
|
if form_enc_parsed:
|
||||||
# This is a form-encoded POST. Support the silly people.
|
logger.debug('Request is form-encoded')
|
||||||
message_body = data_key
|
|
||||||
|
# Uncompressed request. Bottle handles all of the parsing of the
|
||||||
|
# POST key/vals, or un-encoded body.
|
||||||
|
data_key = request.forms.get('data')
|
||||||
|
if data_key:
|
||||||
|
logger.debug('form-encoded POST request detected...')
|
||||||
|
# This is a form-encoded POST. Support the silly people.
|
||||||
|
message_body = data_key
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise MalformedUploadError(
|
||||||
|
"No 'data' POST key/value found. Check your POST key "
|
||||||
|
"name for spelling, and make sure you're passing a value."
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
logger.debug('Plain POST request detected...')
|
||||||
# This is a non form-encoded POST body.
|
# This is a non form-encoded POST body.
|
||||||
message_body = request.body.read()
|
message_body = request.body.read()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user