Skip to content

Commit 352be45

Browse files
authored
Fix bug in http server for serving files (#3995)
1 parent 790d6d9 commit 352be45

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/clusterfuzz/_internal/bot/webserver/http_server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ def do_GET(self): # pylint: disable=invalid-name
101101
return
102102

103103
try:
104-
with open(absolute_path) as file_handle:
104+
# It is necessary to open the file as binary because `self.wfile` is now
105+
# an `io.BufferedIOBase` since python3.6, and thus expects binary input
106+
# in the `self.wfile.write` call below.
107+
with open(absolute_path, 'rb') as file_handle:
105108
data = file_handle.read()
106109
except OSError:
107110
self.send_response(403)

src/clusterfuzz/_internal/tests/core/bot/webserver/http_server_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def __init__(self):
3232
self.contents = ''
3333

3434
def write(self, data):
35-
self.contents += data
35+
# Since the fake files are being created with simple contents, we can
36+
# just decode that as 'utf-8'.
37+
self.contents += data.decode("utf-8")
3638

3739
def __init__(self, path): # pylint: disable=super-init-not-called
3840
self.response_code = 0

0 commit comments

Comments
 (0)