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( parser.add_argument(
"-c", dest='craftanchor', default="/p/", type=str, "-c", dest='craftanchor', default="/p", type=str,
help='Anchorpoint for URL crafting commands. (/p/)' help='Anchorpoint for URL crafting commands. (/p)'
) )
parser.add_argument( parser.add_argument(
"--confdir", "--confdir",

View File

@ -201,11 +201,12 @@ class PathodHandler(tcp.BaseHandler):
self.addlog(retlog) self.addlog(retlog)
return again 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) key = websockets.check_client_handshake(headers)
if key: self.settings.websocket_key = key
self.settings.websocket_key = key if key and not spec:
spec = urllib.unquote(path)[len(self.server.craftanchor):] spec = "ws"
self.info("crafting spec: %s" % spec) self.info("crafting spec: %s" % spec)
try: try:
crafted = language.parse_response(spec) crafted = language.parse_response(spec)
@ -301,7 +302,7 @@ class Pathod(tcp.TCPServer):
addr, addr,
ssl=False, ssl=False,
ssloptions=None, ssloptions=None,
craftanchor="/p/", craftanchor="/p",
staticdir=None, staticdir=None,
anchors=(), anchors=(),
sizelimit=None, 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(si.fileno(), sys.stdin.fileno())
os.dup2(so.fileno(), sys.stdout.fileno()) os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.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): def test_websocket(self):
r = self.pathoc("ws:/p/") r = self.pathoc("ws:/p/")
assert r.status_code == 101
class TestDaemon(CommonTests): class TestDaemon(CommonTests):