Beispiel #1
0
    def makeRequest(self, request):
        """Connect to the remote HTTP server and send request"""
        self.tcpclient = None
        self.httpparser = None
        port = intval(request.requestobject.get("uri-port", ""))
        if port == None:
            port = 80

        self.tcpclient = self.connectionclass(
            request.requestobject["uri-server"], port)
        self.httpparser = HTTPParser(mode="response")

        self.link((self, "_tcpoutbox"), (self.tcpclient, "inbox"))
        self.link((self, "_tcpsignal"), (self.tcpclient, "control"))
        self.link((self.tcpclient, "signal"), (self, "_tcpcontrol"))

        self.link((self.tcpclient, "outbox"),
                  (self.httpparser,
                   "inbox"))  #incoming TCP data -> HTTPParser directly

        self.link((self, "_parsersignal"), (self.httpparser, "control"))
        self.link((self.httpparser, "outbox"), (self, "_parserinbox"))
        self.link((self.httpparser, "signal"), (self, "_parsercontrol"))

        self.addChildren(self.tcpclient, self.httpparser)
        self.tcpclient.activate()
        self.httpparser.activate()
        self.response = ""
        if isinstance(request.requestobject["request"], str):
            self.send(request.requestobject["request"], "_tcpoutbox")
        else:
            for part in request.requestobject["request"]:
                self.send(part, "_tcpoutbox")
Beispiel #2
0
    def initialiseComponent(self):
        """Create an HTTPParser component to convert the requests we receive
        into a more convenient form and a HTTPRequestHandler component to
        sort out the correct response to requests received. Then link them
        together and to the TCP component"""
        
        self.mimehandler = HTTPParser()
        self.httphandler = HTTPRequestHandler(self.createRequestHandler)
        
        self.link( (self,"mime-control"), (self.mimehandler,"control") )
        self.link( (self.mimehandler, "signal"), (self, "mime-signal") )

        self.link( (self.mimehandler, "outbox"), (self.httphandler, "inbox") )
        
        self.link( (self, "http-control"), (self.httphandler, "control") )
        self.link( (self.httphandler, "signal"), (self, "http-signal") )
        
        self.addChildren(self.mimehandler, self.httphandler)
        self.httphandler.activate()
        self.mimehandler.activate()

        self.link((self.httphandler, "outbox"), (self, "outbox"), passthrough=2)
        self.link((self, "inbox"), (self.mimehandler, "inbox"), passthrough=1)