Merge pull request #166 from EDCD/fix/165/bad-formencoded-detection

Gateway: Revert non-gzip form encoded check
This commit is contained in:
Athanasius 2022-01-11 15:39:01 +00:00 committed by GitHub
commit a4eb7548d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 48 additions and 24 deletions

View File

@ -29,7 +29,7 @@ with open(sys.argv[1], 'r') as f:
# This apparently causes compression to actually happen
s.headers['Content-Encoding'] = 'gzip'
r = s.post(
'https://beta.eddn.edcd.io:4431/upload/',
'https://dev.eddn.edcd.io:4432/upload/',
data=msg,
)

View File

@ -3,4 +3,4 @@
# python `requests` appears to perform compression when you set the
# 'Content-Encoding: gzip' header, so do this with curl.
curl --verbose -d 'wegiuweuygtfawgep9aqe8fpq2387lfbr;iufvypq38764tpgf' -H 'Content-Encoding: gzip' 'https://beta.eddn.edcd.io:4431/upload/'
curl --verbose -d 'wegiuweuygtfawgep9aqe8fpq2387lfbr;iufvypq38764tpgf' -H 'Content-Encoding: gzip' 'https://dev.eddn.edcd.io:4432/upload/'

View File

@ -25,7 +25,7 @@ with open(sys.argv[1], 'r') as f:
# Send that compressed data as a POST body
r = http.request(
'POST',
'https://beta.eddn.edcd.io:4431/upload/',
'https://dev.eddn.edcd.io:4432/upload/',
headers={
'Content-Encoding': 'gzip'
},

View File

@ -25,7 +25,7 @@ with open(sys.argv[1], 'r') as f:
# Send that compressed data as a POST body
r = http.request(
'POST',
'https://beta.eddn.edcd.io:4431/upload/',
'https://dev.eddn.edcd.io:4432/upload/',
headers={
'Content-Encoding': 'gzip'
},

View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
import json
import requests
import sys
import urllib3
import zlib
if len(sys.argv) != 2:
print('test-sender.py <filename>')
sys.exit(-1)
with open(sys.argv[1], 'r') as f:
# Read from provided file
msg = f.read()
# Compress it
msg_gzip = zlib.compress(msg.encode('utf-8'))
http = urllib3.PoolManager()
# Send that compressed data as a POST body
r = http.request(
'POST',
'https://dev.eddn.edcd.io:4432/upload/',
headers={
'Content-Encoding': 'gzip'
},
body=msg_gzip
)
print(f'Response: {r.status!r}')
print(f'Body:\n{r.data.decode()}\n')

View File

@ -20,7 +20,7 @@ with open(sys.argv[1], 'r') as f:
# Send that data as a POST body
r = http.request(
'POST',
'https://beta.eddn.edcd.io:4431/upload/',
'https://dev.eddn.edcd.io:4432/upload/',
body=msg
)

View File

@ -20,7 +20,7 @@ with open(sys.argv[1], 'r') as f:
# Send that data as a POST body
r = http.request(
'POST',
'https://beta.eddn.edcd.io:4431/upload/',
'https://dev.eddn.edcd.io:4432/upload/',
body=msg
)

View File

@ -13,7 +13,7 @@ with open(sys.argv[1], 'r') as f:
s = requests.Session()
r = s.post('https://beta.eddn.edcd.io:4431/upload/', data=msg)
r = s.post('https://dev.eddn.edcd.io:4432/upload/', data=msg)
print(f'Response: {r!r}')
print(f'Body: {r.content.decode()}')

View File

@ -166,23 +166,13 @@ def get_decompressed_message():
else:
logger.debug('Content-Encoding indicates *not* compressed...')
form_enc_parsed = urlparse.parse_qs(request.body.read())
if form_enc_parsed:
logger.debug('Request is form-encoded')
# 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."
)
# 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:
logger.debug('Plain POST request detected...')