diff --git a/libpathod/cmdline.py b/libpathod/cmdline.py index 58202ea65..cce02d993 100644 --- a/libpathod/cmdline.py +++ b/libpathod/cmdline.py @@ -233,8 +233,8 @@ def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr): """ ) parser.add_argument( - "-c", dest='craftanchor', default="/p/", type=str, - help='Anchorpoint for URL crafting commands. (/p/)' + "-c", dest='craftanchor', default="/p", type=str, + help='Anchorpoint for URL crafting commands. (/p)' ) parser.add_argument( "--confdir", diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 2e93a3304..dbcb807d6 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -201,11 +201,12 @@ class PathodHandler(tcp.BaseHandler): self.addlog(retlog) return again - if not self.server.nocraft and path.startswith(self.server.craftanchor): + if not self.server.nocraft and utils.matchpath(path, self.server.craftanchor): + spec = urllib.unquote(path)[len(self.server.craftanchor) + 1:] key = websockets.check_client_handshake(headers) - if key: - self.settings.websocket_key = key - spec = urllib.unquote(path)[len(self.server.craftanchor):] + self.settings.websocket_key = key + if key and not spec: + spec = "ws" self.info("crafting spec: %s" % spec) try: crafted = language.parse_response(spec) @@ -301,7 +302,7 @@ class Pathod(tcp.TCPServer): addr, ssl=False, ssloptions=None, - craftanchor="/p/", + craftanchor="/p", staticdir=None, anchors=(), sizelimit=None, diff --git a/libpathod/utils.py b/libpathod/utils.py index 39e61eac4..431ba747f 100644 --- a/libpathod/utils.py +++ b/libpathod/utils.py @@ -136,3 +136,8 @@ def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): # prag os.dup2(si.fileno(), sys.stdin.fileno()) os.dup2(so.fileno(), sys.stdout.fileno()) os.dup2(se.fileno(), sys.stderr.fileno()) + + +def matchpath(path, spec): + if path == spec or path.startswith(spec + "/"): + return True diff --git a/test/test_pathod.py b/test/test_pathod.py index 266f41abd..18b546e42 100644 --- a/test/test_pathod.py +++ b/test/test_pathod.py @@ -186,6 +186,7 @@ class CommonTests(tutils.DaemonTests): def test_websocket(self): r = self.pathoc("ws:/p/") + assert r.status_code == 101 class TestDaemon(CommonTests):