Changes between and of Version 1Version 3Ticket #2983


Ignore:
Timestamp:
01/07/2008 08:54:10 PM (7 years ago)
Author:
radix
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #2983

    • Property Branch changed from to branches/web-concerns-2983
    • Property Author changed from to radix
  • Ticket #2983 – Description

    v1 v3  
    55This is kind of a major change for twisted.web, but we would like to do it without breaking backwards compatibility. 
    66 
    7 Here's an initial pass at some (incomplete) interfaces for this change. I might modify the specifics while maintaining the spirit of the refactoring. The idea is that the HTTP Channel will pass requests off to its "HTTP Request Receiver" object. This will likely be the L{twisted.web.server.Site}. This will look up a resource for the request, render it, and return a Response object. The channel will then tell the response to give it the data by calling sendResponse on it; the response will write the data (optionally registering itself as a producer) to the channel in a protocol-agnostic manner (i.e., chunking and stuff will be the responsibility of the channel).  
     7The idea is that the HTTP Channel will pass requests off to its "HTTP Request Receiver" object. This will likely be the L{twisted.web.server.Site}. This will look up a resource for the request, render it, and return a Response object. The channel will then tell the response to write its body to the channel; the response will write the data (optionally registering itself as a producer) to the channel in a protocol-agnostic manner (i.e., chunking and stuff will be the responsibility of the channel).  
    88 
    99At the end of this change, Request should have no required parameters. Of course, it will still remain compatible with guys who pass arguments to it, and directly call request.write and request.finish; these will be implemented by creating a BackwardsCompatibilityResponse at request._bcResponse. request.write and request.finish will probably require having a request that had a channel passed to it.  
    10  
    11 {{{ 
    12 class IHTTPResponse(Interface): 
    13  
    14     def sendResponse(channel): 
    15         """ 
    16         Send data to the given C{channel} by calling its C{writeHeader}, 
    17         C{write} and C{finish} methods. 
    18  
    19         @param channel: L{IHTTPChannel} provider. 
    20         """ 
    21  
    22  
    23  
    24 class IHTTPChannel(Interface): 
    25  
    26     def writeHeader(self, key, value): 
    27         """ 
    28         Write a header. 
    29  
    30         Once any of the other methods in this interface are called, this method 
    31         can no longer be called. 
    32         """ 
    33  
    34  
    35     def writeBody(self, data): 
    36         """ 
    37         Write a chunk of body data. 
    38         """ 
    39  
    40  
    41     def finishRequest(self): 
    42         """ 
    43         Finish the current request. 
    44         """ 
    45  
    46  
    47     def registerProducerForResponseBody(self, producer): 
    48         """ 
    49         Register the given C{producer} to receive events as per the 
    50         L{twisted.internet.interfaces.IProducer} interface. 
    51         """ 
    52  
    53  
    54     def setHTTPRequestReceiver(self, receiver): 
    55         """ 
    56         @param receiver: The request receiver that will be notified when 
    57             requests are made. 
    58         @type receiver: L{IHTTPRequestReceiver}. 
    59         """ 
    60  
    61  
    62  
    63 class IHTTPRequestReceiver(Interface): 
    64  
    65     def requestReceived(self, request): 
    66         """ 
    67         Process a request and return an L{IHTTPResponse}. 
    68  
    69         @param request: The request to respond to 
    70         @type request: L{IHTTPRequest} 
    71  
    72         @return: The HTTP response object that will be asked to send its 
    73             response to the channel. 
    74         @rtype: L{IHTTPResponse} 
    75         """ 
    76 }}}