Skip to content

Commit

Permalink
Merge pull request #15 from Sharkkkk/patch-1
Browse files Browse the repository at this point in the history
Update simple_http_server.py
  • Loading branch information
freelamb committed Mar 16, 2022
2 parents 4359834 + ee8cb04 commit 888b33b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions simple_http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def do_POST(self):
f.write(b"<strong>Success:</strong>")
else:
f.write(b"<strong>Failed:</strong>")
f.write(info.encode('ascii'))
f.write(b"<br><a href=\"%s\">back</a>" % self.headers['referer'].encode('ascii'))
f.write(info.encode('utf-8'))
f.write(b"<br><a href=\"%s\">back</a>" % self.headers['referer'].encode('utf-8'))
f.write(b"<hr><small>Powered By: freelamb, check new version at ")
f.write(b"<a href=\"https://github.com/freelamb/simple_http_server\">")
f.write(b"here</a>.</small></body>\n</html>\n")
Expand All @@ -92,15 +92,15 @@ def do_POST(self):
f.close()

def deal_post_data(self):
boundary = self.headers["Content-Type"].split("=")[1].encode('ascii')
boundary = self.headers["Content-Type"].split("=")[1].encode('utf-8')
remain_bytes = int(self.headers['content-length'])
line = self.rfile.readline()
remain_bytes -= len(line)
if boundary not in line:
return False, "Content NOT begin with boundary"
line = self.rfile.readline()
remain_bytes -= len(line)
fn = re.findall(r'Content-Disposition.*name="file"; filename="(.*)"', str(line))
fn = re.findall(r'Content-Disposition.*name="file"; filename="(.*)"', line.decode('utf-8'))
if not fn:
return False, "Can't find out file name..."
path = translate_path(self.path)
Expand Down Expand Up @@ -188,8 +188,8 @@ def list_directory(self, path):
f = BytesIO()
display_path = escape(unquote(self.path))
f.write(b'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">')
f.write(b"<html>\n<title>Directory listing for %s</title>\n" % display_path.encode('ascii'))
f.write(b"<body>\n<h2>Directory listing for %s</h2>\n" % display_path.encode('ascii'))
f.write(b"<html>\n<title>Directory listing for %s</title>\n" % display_path.encode('utf-8'))
f.write(b"<body>\n<h2>Directory listing for %s</h2>\n" % display_path.encode('utf-8'))
f.write(b"<hr>\n")
f.write(b"<form ENCTYPE=\"multipart/form-data\" method=\"post\">")
f.write(b"<input name=\"file\" type=\"file\"/>")
Expand All @@ -206,7 +206,7 @@ def list_directory(self, path):
display_name = name + "@"
# Note: a link to a directory displays with @ and links with /
f.write(b'<li><a href="%s">%s</a>\n' %
(quote(linkname).encode('ascii'), escape(display_name).encode('ascii')))
(quote(linkname).encode('utf-8'), escape(display_name).encode('utf-8')))
f.write(b"</ul>\n<hr>\n</body>\n</html>\n")
length = f.tell()
f.seek(0)
Expand Down

0 comments on commit 888b33b

Please sign in to comment.