Ticket #5525: distrib_server_response_code_message.patch

File distrib_server_response_code_message.patch, 2.1 KB (added by tom.prince, 4 years ago)

Add missing message parameter

  • twisted/web/server.py

    diff --git a/twisted/web/server.py b/twisted/web/server.py
    index 8edab18..e7e528e 100644
    class Request(pb.Copyable, http.Request, components.Componentized): 
    286286        """
    287287        self.setETag(tag)
    288288
    289     def view_setResponseCode(self, issuer, code):
     289    def view_setResponseCode(self, issuer, code, message = None):
    290290        """Remote version of setResponseCode; same interface.
    291291        """
    292         self.setResponseCode(code)
     292        self.setResponseCode(code, message)
    293293
    294294    def view_registerProducer(self, issuer, producer, streaming):
    295295        """Remote version of registerProducer; same interface.
  • twisted/web/test/test_distrib.py

    diff --git a/twisted/web/test/test_distrib.py b/twisted/web/test/test_distrib.py
    index 172dab3..421f821 100755
    class DistribTest(unittest.TestCase): 
    145145        request.addCallback(cbRequested)
    146146        return request
    147147
     148    def test_requestResponseCode(self):
     149        """
     150        The response code can be set by the request object passed to a
     151        distributed resource's C{render} method.
     152        """
     153        class SetResponseCode(resource.Resource):
     154            def render(self, request):
     155                request.setResponseCode(200)
     156                return ""
     157
     158        request = self._requestTest(SetResponseCode())
     159        def cbRequested(result):
     160            self.assertEqual(result, "")
     161        request.addCallback(cbRequested)
     162        return request
     163
     164    def test_requestResponseCode_message(self):
     165        """
     166        The response code and message can be set by the request object passed to a
     167        distributed resource's C{render} method.
     168        """
     169        class SetResponseCode(resource.Resource):
     170            def render(self, request):
     171                request.setResponseCode(200, "OK")
     172                return ""
     173
     174        request = self._requestTest(SetResponseCode())
     175        def cbRequested(result):
     176            self.assertEqual(result, "")
     177        request.addCallback(cbRequested)
     178        return request
    148179
    149180    def test_largeWrite(self):
    150181        """