Add preliminary support for opening files
This commit is contained in:
parent
0ffdc0ad6d
commit
59f8fac26f
1 changed files with 10 additions and 3 deletions
13
neomi.py
13
neomi.py
|
@ -521,14 +521,21 @@ class Serve(threading.Thread):
|
||||||
try:
|
try:
|
||||||
full_path = get_full_path(path, config = self.config)
|
full_path = get_full_path(path, config = self.config)
|
||||||
mimetype = get_mimetype(full_path, config = self.config)
|
mimetype = get_mimetype(full_path, config = self.config)
|
||||||
|
file = open(str(full_path), 'rb')
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
reader = StringReader('%s not found\n' % path)
|
reader = StringReader('%s not found\n' % path)
|
||||||
send_header(self.sock, protocol, Status.notfound, 'text/plain', config = self.config)
|
send_header(self.sock, protocol, Status.notfound, 'text/plain', config = self.config)
|
||||||
send_file(self.sock, reader, protocol, 'text/plain', config = self.config)
|
send_file(self.sock, reader, protocol, 'text/plain', config = self.config)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
reader = StringReader('Path: %s\nProtocol: %s\nRest of header data: %s\nMime type: %s\n' % (path, protocol, rest, mimetype))
|
reader = FileReader(file)
|
||||||
send_header(self.sock, protocol, Status.ok, 'text/plain', config = self.config)
|
|
||||||
send_file(self.sock, reader, protocol, 'text/plain', config = self.config)
|
send_header(self.sock, protocol, Status.ok, mimetype, config = self.config)
|
||||||
|
send_file(self.sock, reader, protocol, mimetype, config = self.config)
|
||||||
|
|
||||||
|
file.close()
|
||||||
|
|
||||||
except BaseException as err:
|
except BaseException as err:
|
||||||
reader = StringReader('Internal server error\n')
|
reader = StringReader('Internal server error\n')
|
||||||
send_header(self.sock, protocol, Status.error, 'text/plain', config = self.config)
|
send_header(self.sock, protocol, Status.error, 'text/plain', config = self.config)
|
||||||
|
|
Loading…
Reference in a new issue