made create_application usage allow for both defer and non-defer

This commit is contained in:
Anders Jensen 2018-07-19 10:14:21 +02:00
parent 49a693afd3
commit 682e5442a9
3 changed files with 3 additions and 5 deletions

View File

@ -3,7 +3,7 @@ import time
import traceback import traceback
from urllib.parse import unquote from urllib.parse import unquote
from twisted.internet.defer import inlineCallbacks from twisted.internet.defer import inlineCallbacks, maybeDeferred
from twisted.internet.interfaces import IProtocolNegotiationFactory from twisted.internet.interfaces import IProtocolNegotiationFactory
from twisted.protocols.policies import ProtocolWrapper from twisted.protocols.policies import ProtocolWrapper
from twisted.web import http from twisted.web import http
@ -146,7 +146,7 @@ class WebRequest(http.Request):
logger.debug("HTTP %s request for %s", self.method, self.client_addr) logger.debug("HTTP %s request for %s", self.method, self.client_addr)
self.content.seek(0, 0) self.content.seek(0, 0)
# Work out the application scope and create application # Work out the application scope and create application
self.application_queue = yield self.server.create_application(self, { self.application_queue = yield maybeDeferred(self.server.create_application, self, {
"type": "http", "type": "http",
# TODO: Correctly say if it's 1.1 or 1.0 # TODO: Correctly say if it's 1.1 or 1.0
"http_version": self.clientproto.split(b"/")[-1].decode("ascii"), "http_version": self.clientproto.split(b"/")[-1].decode("ascii"),

View File

@ -24,7 +24,6 @@ from concurrent.futures import CancelledError
from twisted.internet import defer, reactor from twisted.internet import defer, reactor
from twisted.internet.endpoints import serverFromString from twisted.internet.endpoints import serverFromString
from twisted.internet.threads import deferToThread
from twisted.logger import STDLibLogObserver, globalLogBeginner from twisted.logger import STDLibLogObserver, globalLogBeginner
from twisted.web import http from twisted.web import http
@ -171,7 +170,6 @@ class Server(object):
### Internal event/message handling ### Internal event/message handling
@defer.inlineCallbacks
def create_application(self, protocol, scope): def create_application(self, protocol, scope):
""" """
Creates a new application instance that fronts a Protocol instance Creates a new application instance that fronts a Protocol instance

View File

@ -66,7 +66,7 @@ class WebSocketProtocol(WebSocketServerProtocol):
] ]
# Make new application instance with scope # Make new application instance with scope
self.path = request.path.encode("ascii") self.path = request.path.encode("ascii")
self.application_deferred = self.server.create_application(self, { self.application_deferred = defer.maybeDeferred(self.server.create_application, self, {
"type": "websocket", "type": "websocket",
"path": unquote(self.path.decode("ascii")), "path": unquote(self.path.decode("ascii")),
"headers": self.clean_headers, "headers": self.clean_headers,