diff --git a/web.py b/web.py index dbb6c5e..9043868 100644 --- a/web.py +++ b/web.py @@ -67,15 +67,17 @@ def parse_request(request): class MyServer(BaseHTTPRequestHandler): def do_GET(self): - if re.match(r'/data/\w+\.pdf', self.path) is not None: - if not os.path.exists(self.path): + match = re.match(r'/data/(\w+\.pdf)', self.path) + if match is not None: + pdf_path = os.path.join(OUT_DIR, match.groups()[0]) + if not os.path.exists(pdf_path): self.send_response(404) self.end_headers() return self.send_response(200) self.send_header("Content-type", "application/pdf") self.end_headers() - with open(self.path, 'rb') as f: + with open(pdf_path, 'rb') as f: self.wfile.write(f.read()) return