aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libpathod/cmdline.py4
-rw-r--r--libpathod/pathod.py11
-rw-r--r--libpathod/utils.py5
-rw-r--r--test/test_pathod.py1
4 files changed, 14 insertions, 7 deletions
diff --git a/libpathod/cmdline.py b/libpathod/cmdline.py
index 58202ea6..cce02d99 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 2e93a330..dbcb807d 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 39e61eac..431ba747 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 266f41ab..18b546e4 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):