Mercurial > libervia-web
comparison libervia/server/server.py @ 1203:251eba911d4d
server (websockets): fixed websocket handling on HTTPS connections:
Original request used to retrieve a page was stored on dynamic pages, but after the end of
it, the channel was deleted, resulting in a isSecure() always returning False, and
troubles in chain leading to the the use of the wrong session object. This patch fixes
this by reworking the way original request is used, and creating a new wrapping class
allowing to keep an API similar to iweb.IRequest, with data coming from both the original
request and the websocket request.
fix 327
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 14 Jul 2019 14:45:51 +0200 |
parents | 3f791fbc1643 |
children | a2df53dfbf46 |
comparison
equal
deleted
inserted
replaced
1202:3f791fbc1643 | 1203:251eba911d4d |
---|---|
25 import shutil | 25 import shutil |
26 import uuid | 26 import uuid |
27 import urlparse | 27 import urlparse |
28 import urllib | 28 import urllib |
29 import time | 29 import time |
30 import copy | |
30 from twisted.application import service | 31 from twisted.application import service |
31 from twisted.internet import reactor, defer, inotify | 32 from twisted.internet import reactor, defer, inotify |
32 from twisted.web import server | 33 from twisted.web import server |
33 from twisted.web import static | 34 from twisted.web import static |
34 from twisted.web import resource as web_resource | 35 from twisted.web import resource as web_resource |
2656 scheme = u"ws" | 2657 scheme = u"ws" |
2657 | 2658 |
2658 return self.getExtBaseURL(request, path=scheme, scheme=scheme) | 2659 return self.getExtBaseURL(request, path=scheme, scheme=scheme) |
2659 | 2660 |
2660 def registerWSToken(self, token, page, request): | 2661 def registerWSToken(self, token, page, request): |
2661 websockets.LiberviaPageWSProtocol.registerToken(token, page, request) | 2662 # we make a shallow copy of request to avoid losing request.channel when |
2663 # connection is lost (which would result as request.isSecure() being always | |
2664 # False). See #327 | |
2665 request._signal_id = id(request) | |
2666 websockets.LiberviaPageWSProtocol.registerToken(token, page, copy.copy(request)) | |
2662 | 2667 |
2663 ## Various utils ## | 2668 ## Various utils ## |
2664 | 2669 |
2665 def getHTTPDate(self, timestamp=None): | 2670 def getHTTPDate(self, timestamp=None): |
2666 now = time.gmtime(timestamp) | 2671 now = time.gmtime(timestamp) |