-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
self.transport.location not available from wrapped connectionMade #14
Comments
Here's one way to hack around it by monkey patching validateHeaders to make a callback. This is helpful in a RESTful streaming API where there's really no need for the client to send anything to the server. Once the server knows the path it can determine the appropriate resource and begin streaming it. class MyProtocol(Protocol):
def connectionMade(self):
# monkey patch txws to notify us after it parses the location field
oldValidateHeaders = self.transport.validateHeaders
def wrap(*args, **kwargs):
r = oldValidateHeaders(*args, **kwargs)
if r: self.headersValidated()
return r
self.transport.validateHeaders = wrap
def headersValidated(self):
log.msg("Websocket headers validated, loc: %r" %
self.transport.location) |
Sorry, but |
When a websocket connection is made, the client sends the URI it is requesting, and somewhere in the server some code has to look at that URI and branch based on it, e.g. to route the request to the appropriate Resource. Is that code already in txWS and I just missed it? If not, how would you suggest implementing that? |
Urgh, no, it's in Twisted #4173 (http://tm.tl/4173/) but not in txWS. Not sure how to do that here, since txWS is emphatically not HTTP. |
I think, I've implemented something like n1ywb suggests: caveats:
Nevertheless, the example shows a way the task can be done. It's lighter to finish this approach, instead of using autobahn's WAMP or something like that. |
It seems that within the context of the wrapped connectionMade method, the contents of self.transport.location are not yet set to the correct value, but rather the default '/'.
It would be nice if the call to the wrapped connectionMade method were made after the websockets connection was fully negotiated.
The text was updated successfully, but these errors were encountered: