Ejemplo n.º 1
0
    def handle_single(self):
        """Handle a single HTTP request"""
        self.raw_requestline = self.rfile.readline(65537)
        if len(self.raw_requestline) > 65536:
            self.requestline = ''
            self.request_version = ''
            self.command = ''
            self.close_connection = 1
            self.send_error(414)
            return

        if not self.parse_request():  # An error code has been sent, just exit
            return

        handler = ServerHandler(self.rfile, self.wfile, self.get_stderr(),
                                self.get_environ())
        handler.http_version = "1.1"
        handler.request_handler = self  # backpointer for logging

        # eNodeB will sometimes close connection to enodebd.
        # The cause of this is unknown, but we can safely ignore the
        # closed connection, and continue as normal otherwise.
        #
        # While this throws a BrokenPipe exception in wsgi server,
        # it also causes an AttributeError to be raised because of a
        # bug in the wsgi server.
        # https://bugs.python.org/issue27682
        try:
            handler.run(self.server.get_app())
        except BrokenPipeError:
            self.log_error(
                "eNodeB has unexpectedly closed the TCP connection.")
Ejemplo n.º 2
0
def monkeypatch_wsgiref_on_windows():
    """
    On windows Django live test cases have the bad habbit of spewing Error 10045 into the console.
    This monkeypatch makes wsgiref's server (used in live test cases) handle 10045 properly.
    """
    if platform.system() != "Windows":
        return

    import socket
    from wsgiref.simple_server import ServerHandler, WSGIRequestHandler

    def monkeypatch_handle(self):
        """Handle a single HTTP request"""

        try:
            self.raw_requestline = self.rfile.readline()
        except socket.error, err:
            if err.errno == 10054:
                return
            else:
                raise

        if not self.parse_request():  # An error code has been sent, just exit
            return

        handler = ServerHandler(self.rfile, self.wfile, self.get_stderr(),
                                self.get_environ())
        handler.request_handler = self  # backpointer for logging
        handler.run(self.server.get_app())
Ejemplo n.º 3
0
    def handle(self):
        """Handle a single HTTP request"""

        self.raw_requestline = self.rfile.readline(65537)
        if len(self.raw_requestline) > 65536:
            self.requestline = ''
            self.request_version = ''
            self.command = ''
            self.send_error(414)
            return

        if not self.parse_request():  # An error code has been sent, just exit
            return

        handler = ServerHandler(
            self.rfile,
            self.wfile,
            self.get_stderr(),
            self.get_environ(),
            multithread=False,
            multiprocess=False,
        )

        handler.request_handler = self  # backpointer for logging
        handler.run(self.server.get_app())
Ejemplo n.º 4
0
    def handle(self):
        """
        Handle:
          /xmlrpc => SimpleXMLRPCServer
          /upload => self._handle_upload
          all else => WSGI app for Web UI
        """
        self.raw_requestline = self.rfile.readline()
        if not self.parse_request(): # An error code has been sent, just exit
            return

        content_length = self.headers.getheader('content-length')
        if not content_length:
            content_length = 0
        content_length = int(content_length)

        print 'content length is:', content_length

        if content_length > self.MAX_CONTENT_LENGTH:
            message = too_big_message % (content_length,
                                         self.MAX_CONTENT_LENGTH)
            self._send_html_response(403, message)
            return

        if SimpleXMLRPCRequestHandler.is_rpc_path_valid(self):
            return SimpleXMLRPCRequestHandler.do_POST(self)
        
        elif self.path.startswith('/upload?'):
            return self._handle_upload()

        ## else:

        handler = ServerHandler(
            self.rfile, self.wfile, self.get_stderr(), self.get_environ(),
            multithread=False, multiprocess=False
        )
        handler.request_handler = self      # backpointer for logging
        handler.run(self.server.get_app())
Ejemplo n.º 5
0
 def handle_write(self):
     self._can_write = False
     handler = ServerHandler(self._input_stream, self.wfile,
                             self.get_stderr(), self.get_environ())
     handler.server_software = self.server_version
     handler.http_version = self.protocol_version[5:]
     handler.request_handler = self  # backpointer for logging
     handler.wsgi_multiprocess = False
     handler.wsgi_multithread = False
     try:
         handler.run(self.server.get_app())
     except Exception:
         self.handle_error()
         return
     if self.close_connection:
         self.handle_close()
     else:
         try:
             self.wfile.flush()
         except socket.error:
             self.handle_error()
         else:
             self._can_read = True