Receiving POST from lynx

main
Bob Mottram 2022-07-10 18:36:37 +01:00
parent 00203624f5
commit f32d31464a
1 changed files with 40 additions and 33 deletions

View File

@ -4918,25 +4918,27 @@ class PubServer(BaseHTTPRequestHandler):
users_path = users_path.split('/tags/')[0] users_path = users_path.split('/tags/')[0]
actor_str = self._get_instance_url(calling_domain) + users_path actor_str = self._get_instance_url(calling_domain) + users_path
tag_screen_str = actor_str + '/tags/' + hashtag tag_screen_str = actor_str + '/tags/' + hashtag
boundary = None
if ' boundary=' in self.headers['Content-type']: if ' boundary=' in self.headers['Content-type']:
boundary = self.headers['Content-type'].split('boundary=')[1] boundary = self.headers['Content-type'].split('boundary=')[1]
if ';' in boundary: if ';' in boundary:
boundary = boundary.split(';')[0] boundary = boundary.split(';')[0]
# get the nickname # get the nickname
nickname = get_nickname_from_actor(actor_str) nickname = get_nickname_from_actor(actor_str)
editor = None editor = None
if nickname: if nickname:
editor = is_editor(base_dir, nickname) editor = is_editor(base_dir, nickname)
if not hashtag or not editor: if not hashtag or not editor:
if not nickname: if not nickname:
print('WARN: nickname not found in ' + actor_str) print('WARN: nickname not found in ' + actor_str)
else: else:
print('WARN: nickname is not a moderator' + actor_str) print('WARN: nickname is not a moderator' + actor_str)
self._redirect_headers(tag_screen_str, cookie, calling_domain) self._redirect_headers(tag_screen_str, cookie, calling_domain)
self.server.postreq_busy = False self.server.postreq_busy = False
return return
if self.headers.get('Content-length'):
length = int(self.headers['Content-length']) length = int(self.headers['Content-length'])
# check that the POST isn't too large # check that the POST isn't too large
@ -4946,27 +4948,32 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postreq_busy = False self.server.postreq_busy = False
return return
try: try:
# read the bytes of the http form POST # read the bytes of the http form POST
post_bytes = self.rfile.read(length) post_bytes = self.rfile.read(length)
except SocketError as ex: except SocketError as ex:
if ex.errno == errno.ECONNRESET: if ex.errno == errno.ECONNRESET:
print('EX: connection was reset while ' + print('EX: connection was reset while ' +
'reading bytes from http form POST') 'reading bytes from http form POST')
else: else:
print('EX: error while reading bytes ' + print('EX: error while reading bytes ' +
'from http form POST') 'from http form POST')
self.send_response(400) self.send_response(400)
self.end_headers() self.end_headers()
self.server.postreq_busy = False self.server.postreq_busy = False
return return
except ValueError as ex: except ValueError as ex:
print('EX: failed to read bytes for POST, ' + str(ex)) print('EX: failed to read bytes for POST, ' + str(ex))
self.send_response(400) self.send_response(400)
self.end_headers() self.end_headers()
self.server.postreq_busy = False self.server.postreq_busy = False
return return
if not boundary:
if b'--LYNX' in post_bytes:
boundary = '--LYNX'
if boundary:
# extract all of the text fields into a dict # extract all of the text fields into a dict
fields = \ fields = \
extract_text_fields_in_post(post_bytes, boundary, debug) extract_text_fields_in_post(post_bytes, boundary, debug)