Exemplo n.º 1
0
    def parse_request(self):
        u"""リクエストの解析を行う."""

        # リクエストされているパスが
        #     GET HTTP/1.0
        # のように空白の場合は
        #     GET / HTTP/1.0
        # になるように修正する
        words = self.raw_requestline.rstrip().split()
        if len(words) == 2 and words[1].startswith("HTTP/"):
            self.raw_requestline = "%s / %s\n" % tuple(words)

        r = BaseHTTPRequestHandler.parse_request(self)
        if not r:
            logging.warning("%s can't parse the request." % self)
            return

        self.parse_pragma()

        # リクエストヘッダーをログ出力
        logging.debug("%s received the request:\n%s\n%s %s %s\n%s\n%s" %
                      (self,
                       "-" * 40,
                       self.command, self.path, self.request_version,
                       "".join(self.headers.headers).strip(),
                       "-" * 40))
        return r
Exemplo n.º 2
0
    def parse_request(self):
        self.raw_requestline = self.raw_requestline.replace("RTSP/1.0", "HTTP/1.1")

        r = BaseHTTPRequestHandler.parse_request(self)
        self.protocol_version = "RTSP/1.0"
        self.close_connection = 0
        return r
Exemplo n.º 3
0
    def parse_request(self):
        if not BaseHTTPRequestHandler.parse_request(self):
            return False

        logging.debug("parsed request <%s> <%s> <%s>" % (self.command, self.path, self.request_version))

        parsed_path = urlparse(self.path)
        if self.headers["Host"]:
            logging.debug("host is %s" % (self.headers["Host"],))
            parsed_host = urlparse(self.headers["Host"])
            if parsed_host.scheme:
                parsed_path.scheme = parsed_host.scheme
            if parsed_host.netloc:
                parsed_path.netloc = parsed_path.netloc
        host, colon, port = parsed_path.netloc.partition(":")
        if colon:
            port = int(port)
        else:
            port = 80

        self.root_scheme = parsed_path.scheme
        self.root_host = host
        self.root_port = port
        self.root_path = parsed_path.path
        return True
Exemplo n.º 4
0
    def parse_request(self):
        """Parse request as WebSocket handshake and pass stream to
        handle_stream(). 
        Overrides BaseHTTPRequestHandler.parse_request().
        """

        # Sets self.headers, self.path etc. for do_handshake()
        BaseHTTPRequestHandler.parse_request(self)

        request = StandaloneRequest(self)

        try:
            handshake.do_handshake(request, BaseWSRequestHandler._Dispatcher())
        except (handshake.VersionException, handshake.HandshakeException), e:
            # TODO: error handling
            print "Handshake failed:", e
            return False
Exemplo n.º 5
0
 def parse_request(self):
     retval = BaseHTTPRequestHandler.parse_request(self)
     # Add support for proxy-connection before the
     conntype = self.headers.get('proxy-connection', "")
     if conntype.lower() == 'close':
         self.close_connection = 1
     elif (conntype.lower() == 'keep-alive'
           and self.protocol_version >= "HTTP/1.1"):
         self.close_connection = 0
     return retval
Exemplo n.º 6
0
 def parse_request(self):
     retval = BaseHTTPRequestHandler.parse_request(self)
     # Add support for proxy-connection before the
     conntype = self.headers.get('proxy-connection', "")
     if conntype.lower() == 'close':
         self.close_connection = 1
     elif (conntype.lower() == 'keep-alive' and
           self.protocol_version >= "HTTP/1.1"):
         self.close_connection = 0
     return retval
 def parse_request(self):
     idx = -1
     for i in range(0, len(self.raw_requestline)):
         if self.raw_requestline[i] in "GPH":
             idx = i
             self.raw_requestline = self.raw_requestline[idx:]
             break
     if idx == -1:
         raise Exception("Wrong request %s..." % self.raw_requestline[:256])
     return BaseHTTPRequestHandler.parse_request(self)
Exemplo n.º 8
0
 def parse_request(self):
     result = BaseHTTPRequestHandler.parse_request(self)
     # Adaptation to Python 3.
     if sys.version_info.major == 2 and result == True:
         expect = self.headers.get("Expect", "")
         if (expect.lower() == "100-continue"
                 and self.protocol_version >= "HTTP/1.1"
                 and self.request_version >= "HTTP/1.1"):
             if not self.handle_expect_100():
                 return False
     return result
Exemplo n.º 9
0
 def parse_request(self):
     idx = -1
     for i in range(len(self.raw_requestline)):
         if self.raw_requestline[i:i + 4] == 'POST':
             idx = i
             break
         elif self.raw_requestline[i:i + 3] == 'GET':
             idx = i
             break
     if idx > 0:
         self.raw_requestline = self.raw_requestline[idx:]
     if idx == -1:
         printDBG("Wrong request %s..." % self.raw_requestline[:256])
         #sys.exit(-1)
         #raise Exception("Wrong request %s..." % self.raw_requestline[:256])
     return BaseHTTPRequestHandler.parse_request(self)
Exemplo n.º 10
0
    def parse_request(self, *args, **kwargs):
        if not BaseHTTPRequestHandler.parse_request(self, *args, **kwargs):
            return False

        # after basic parsing also use urlparse to retrieve individual
        # elements of a request.
        url = urlparse(self.path)

        # Yes, override path with the path part only
        self.path = unquote(url.path)

        # Create dict out of query
        self.query = parse_qs(url.query)

        # keep the rest into the 'url' element in case someone needs it
        self.url = url

        return True
Exemplo n.º 11
0
    def parse_request(self, *args, **kwargs):
        if not BaseHTTPRequestHandler.parse_request(self, *args, **kwargs):
            return False

        # grab the loginuid from `/proc` as soon as possible
        creds = self.peer_creds
        if creds is not None:
            self.loginuid = self._get_loginuid(creds['pid'])

        # after basic parsing also use urlparse to retrieve individual
        # elements of a request.
        url = urlparse(self.path)

        # Yes, override path with the path part only
        self.path = unquote(url.path)

        # Create dict out of query
        self.query = parse_qs(url.query)

        # keep the rest into the 'url' element in case someone needs it
        self.url = url

        return True
Exemplo n.º 12
0
    def parse_request(self, *args, **kwargs):
        if not BaseHTTPRequestHandler.parse_request(self, *args, **kwargs):
            return False

        # grab the loginuid from `/proc` as soon as possible
        creds = self.peer_creds
        if creds is not None:
            self.loginuid = self._get_loginuid(creds['pid'])

        # after basic parsing also use urlparse to retrieve individual
        # elements of a request.
        url = urlparse(self.path)

        # Yes, override path with the path part only
        self.path = url.path

        # Create dict out of query
        self.query = parse_qs(url.query)

        # keep the rest into the 'url' element in case someone needs it
        self.url = url

        return True
Exemplo n.º 13
0
    def parse_request(self):

	# Make sure it's well-formed
	res = BaseHTTPRequestHandler.parse_request(self)
	if not res:
	    return False

	# Check whether this request can proceed
	if not hasattr(self, "authenticate"):
	    return True

	# Authentication is present, go ask
	res = self.authenticate()

	# Supplied body is the completion of the request
	if isinstance(res, str):
	    res = self.send_result(res, "text/html")
	    # self.base_op hasn't been decoded yet, so
	    #  just snoop the operation type directly
	    if not self.requestline.startswith("HEAD"):
		self.wfile.write(res)
            # We did the whole request, so don't have
            #  handle_one_request() try also
	    return False

	# HTML error; code and message
	if isinstance(res, (tuple,list)):
	    self.send_error(res[0], res[1])
	    return False

	# Only other valid return format is True; keep
	#  going
	if res is not True:
            raise Exception, "TBD, check this code path"
	assert res is True
	return True
 def parse_request(self):
     return BaseHTTPRequestHandler.parse_request(self)
Exemplo n.º 15
0
 def parse_request(self):
     ret = BaseHTTPRequestHandler.parse_request(self)
     self.parse_GET()
     if self.command.upper() == 'POST':
         self.parse_POST()
     return ret
Exemplo n.º 16
0
 def parse_request(self):
     return BaseHTTPRequestHandler.parse_request(self)
Exemplo n.º 17
0
 def parse_request(self):
     ret = BaseHTTPRequestHandler.parse_request(self)
     self.parse_GET()
     if self.command.upper() == 'POST':
         self.parse_POST()
     return ret