From 4a8aba4bab1dccd28f356f001c4c130509195d32 Mon Sep 17 00:00:00 2001 From: Paul Mathieu Date: Tue, 26 Jul 2022 17:27:22 +0200 Subject: [PATCH] Fix pdf retrieval --- web.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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