Commits

Donald Stufft committed 2f7fca8

Move the /packages/* url into Werkzeug

Comments (0)

Files changed (1)

             ]),
             routing.Rule("/serversig/<package>/",
                 endpoint="serversig", methods=["GET"]),
+            routing.Rule("/packages/<path:filename>",
+                endpoint="packages", methods=["GET"]),
         ])
 
     def run(self, request):
             return getattr(self, "do_%s" % endpoint)(request, database, **args)
 
 
-            # See if this is the "simple" pages and signatures
-            if script_name == '/packages':
-                return self.packages(request, database)
             if script_name == '/mirrors':
                 return self.mirrors(request, database)
             if script_name == '/security':
             },
         )
 
-    def packages(self):
-        path = self.env.get('PATH_INFO')
-
-        # I expect that nginx will do the right thing if it doesn't find the
-        # actual file when resolving the X-accel headers.
-        self.handler.send_response(200, 'OK')
-
-        package = packages_path_to_package_name.match(path)
+    def do_packages(self, request, database, filename):
+        filename = "/" + filename
+        headers = {}
+
+        package = packages_path_to_package_name.match(filename)
         if package:
-            # Make sure that we associate the delivered file with the serial this
-            # is valid for. Intended to support mirrors to more easily achieve
-            # consistency with files that are newer than they may expect.
+            # Make sure that we associate the delivered file with the serial
+            #   this is valid for. Intended to support mirrors to more easily
+            #   achieve consistency with files that are newer than they may
+            #   expect.
             package = package.group(2)
-            serial = self.store.last_serial_for_package(package)
+            serial = database.last_serial_for_package(package)
+
             if serial is not None:
-                self.handler.send_header("X-PYPI-LAST-SERIAL", str(serial))
-
-            self.handler.send_header(
-                                "Surrogate-Key", "package pkg~%s" % safe_name(package).lower())
+                headers["X-PYPI-LAST-SERIAL"] = serial
+
+            headers["Surrogate-Key"] = ("package pkg~%s" %
+                                        safe_name(package).lower())
 
         # we expect nginx to have configured a location named
         # '/packages_raw/...' that aliases the original path correctly, see
         #    internal;
         #    autoindex on;
         # }
-        self.handler.send_header("X-Accel-Redirect", self.config.raw_package_prefix + path)
-
-        self.handler.end_headers()
+        headers["X-Accel-Redirect"] = self.config.raw_package_prefix + filename
+
+        return Response(headers=headers)
 
     def run_id(self):
         path = self.env.get('PATH_INFO')