Ticket #6927: 6972-3.diff

File 6972-3.diff, 5.6 KB (added by Adi Roiban, 7 years ago)
  • twisted/web/http.py

    diff --git twisted/web/http.py twisted/web/http.py
    index d69a02f..85d79c2 100644
    class HTTPChannel(basic.LineReceiver, policies.TimeoutMixin): 
    15871587    """
    15881588    A receiver for HTTP requests.
    15891589
    1590     Maximum length for initial request line and each header is defined by
    1591     L{basic.LineReceiver.MAX_LENGTH}.
     1590    @ivar MAX_LENGTH: Maximum length for initial request line and each line
     1591        from the header.
    15921592
    15931593    @ivar _transferDecoder: C{None} or a decoder instance if the request body
    15941594        uses the I{chunked} Transfer-Encoding.
    class HTTPChannel(basic.LineReceiver, policies.TimeoutMixin): 
    16691669            self._command = command
    16701670            self._path = request
    16711671            self._version = version
     1672        # End of headers.
    16721673        elif line == b'':
    16731674            if self.__header:
    16741675                self.headerReceived(self.__header)
    class HTTPChannel(basic.LineReceiver, policies.TimeoutMixin): 
    16781679                self.allContentReceived()
    16791680            else:
    16801681                self.setRawMode()
     1682        # Continuation of a multi line header.
    16811683        elif line[0] in b' \t':
    16821684            self.__header = self.__header + '\n' + line
     1685        # Regular header line.
     1686        # Processing of header line is delayed to allow accumulating multi
     1687        # line headers.
    16831688        else:
    16841689            if self.__header:
    16851690                self.headerReceived(self.__header)
  • twisted/web/test/test_http.py

    diff --git twisted/web/test/test_http.py twisted/web/test/test_http.py
    index 9563c7a..71507ef 100644
    class ParsingTestCase(unittest.TestCase): 
    661661
    662662
    663663    def runRequest(
    664             self, httpRequest, requestFactory=None, channel=None,
    665             success=False):
     664            self, httpRequest, requestFactory=None, success=True,
     665             channel=None,
     666             ):
    666667        """
    667668        Execute a web request based on plain text content.
    668669
    class ParsingTestCase(unittest.TestCase): 
    672673        @param requestFactory: Request factory used for the channel.
    673674        @type requestFactory: L{Request}
    674675
     676        @param success: Value to compare against I{self.didRequest}.
     677        @type success: C{bool}
     678
    675679        @param channel: Channel instance over which the request is processed.
    676680        @type channel: L{HTTPChannel}
    677681
    678         @param success: Value to compare agains I{self.didRequest}.
    679         @type success: C{bool}
    680 
    681682        @return: Returns the channel used for processing the request.
    682683        @rtype: L{HTTPChannel}
    683684        """
    class ParsingTestCase(unittest.TestCase): 
    839840        channel.totalHeadersSize = 10
    840841        httpRequest = b'GET /path/longer/than/10 HTTP/1.1\n'
    841842
    842         channel = self.runRequest(httpRequest=httpRequest, channel=channel)
     843        channel = self.runRequest(
     844            httpRequest=httpRequest, channel=channel, success=False)
    843845
    844846        self.assertEqual(
    845847            channel.transport.value(),
    class ParsingTestCase(unittest.TestCase): 
    859861            b'Some-Header: less-than-40\n'
    860862            )
    861863
    862         channel = self.runRequest(httpRequest=httpRequest, channel=channel)
     864        channel = self.runRequest(
     865            httpRequest=httpRequest, channel=channel, success=False)
    863866
    864867        self.assertEqual(
    865868            channel.transport.value(),
    class ParsingTestCase(unittest.TestCase): 
    887890            )
    888891
    889892        channel = self.runRequest(
    890             httpRequest=httpRequest, channel=channel)
     893            httpRequest=httpRequest, channel=channel, success=False)
    891894
    892895        self.assertEqual(
    893896            channel.transport.value(),
    Cookie: rabbit="eat carrot"; ninja=secret; spam="hey 1=1!" 
    922925                testcase.didRequest = True
    923926                self.finish()
    924927
    925         self.runRequest(httpRequest, MyRequest, success=True)
     928        self.runRequest(httpRequest, MyRequest)
    926929
    927930        self.assertEqual(
    928931            cookies, {
    GET /?key=value&multiple=two+words&multiple=more%20words&empty= HTTP/1.0 
    949952                testcase.didRequest = True
    950953                self.finish()
    951954
    952         self.runRequest(httpRequest, MyRequest, success=True)
     955        self.runRequest(httpRequest, MyRequest)
    953956        self.assertEqual(method, [b"GET"])
    954957        self.assertEqual(
    955958            args, [[b"value"], [b""], [b"two words", b"more words"]])
    GET /?key=value&multiple=two+words&multiple=more%20words&empty= HTTP/1.0 
    975978                testcase.didRequest = True
    976979                self.finish()
    977980
    978         self.runRequest(httpRequest, MyRequest, success=True)
     981        self.runRequest(httpRequest, MyRequest)
    979982        self.assertEqual(method, [b'GET'])
    980983        self.assertEqual(path, [b'/foo'])
    981984        self.assertEqual(args, [[b'?'], [b'quux']])
    Content-Type: application/x-www-form-urlencoded 
    10111014                testcase.didRequest = True
    10121015                self.finish()
    10131016
    1014         self.runRequest(httpRequest, MyRequest, success=True)
     1017        self.runRequest(httpRequest, MyRequest)
    10151018        self.assertEqual(method, [b"POST"])
    10161019        self.assertEqual(
    10171020            args, [[b"value"], [b""], [b"two words", b"more words"]])
    Hello, 
    10721075                testcase.didRequest = True
    10731076                self.finish()
    10741077
    1075         self.runRequest(httpRequest, MyRequest, success=True)
     1078        self.runRequest(httpRequest, MyRequest)
    10761079        # The tempfile API used to create content returns an
    10771080        # instance of a different type depending on what platform
    10781081        # we're running on.  The point here is to verify that the