Change the semantics of the craft anchor point specification

The anchor point is now defined as /p (rather than /p/), with the specification
for a request just to /p or /p/ being empty.
This commit is contained in:
Aldo Cortesi 2015-04-23 17:35:22 +12:00
parent dacb350040
commit b0ab5297d1
4 changed files with 14 additions and 7 deletions

View File

@ -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",

View File

@ -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,

View File

@ -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

View File

@ -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):