Skip to content

Commit

Permalink
Merge pull request #37 from w3c/jgraham/abs_url_rewriter
Browse files Browse the repository at this point in the history
Fix url rewriter to deal with absolute URLs and those with query strings...
  • Loading branch information
jgraham committed Jul 16, 2014
2 parents c542801 + e5ec62b commit cb76946
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions wptserve/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from request import Server, Request
from response import Response
from router import Router
import routes
import routes as default_routes
from utils import HTTPException


Expand Down Expand Up @@ -91,12 +91,16 @@ def rewrite(self, request_handler):
:param request_handler: BaseHTTPRequestHandler for which to
rewrite the request.
"""
if request_handler.path in self.rules:
methods, destination = self.rules[request_handler.path]
split_url = urlparse.urlsplit(request_handler.path)
if split_url.path in self.rules:
methods, destination = self.rules[split_url.path]
if "*" in methods or request_handler.command in methods:
logger.debug("Rewriting request path %s to %s" %
(request_handler.path, destination))
request_handler.path = destination
new_url = list(split_url)
new_url[2] = destination
new_url = urlparse.urlunsplit(new_url)
request_handler.path = new_url


class WebTestServer(ThreadingMixIn, BaseHTTPServer.HTTPServer):
Expand Down Expand Up @@ -275,7 +279,7 @@ class WebTestHttpd(object):
HTTP server designed for testing scenarios.
Takes a router class which provides one method get_handler which takes a Request
and returns a handler function."
and returns a handler function.
.. attribute:: host
Expand Down Expand Up @@ -305,10 +309,13 @@ class WebTestHttpd(object):
def __init__(self, host="127.0.0.1", port=8000,
server_cls=None, handler_cls=WebTestRequestHandler,
use_ssl=False, certificate=None, router_cls=Router,
doc_root=os.curdir, routes=routes.routes,
doc_root=os.curdir, routes=None,
rewriter_cls=RequestRewriter, bind_hostname=True, rewrites=None,
config=None):

if routes is None:
routes = default_routes.routes

self.host = host

self.router = router_cls(doc_root, routes)
Expand Down

0 comments on commit cb76946

Please sign in to comment.