clysto / simple-httpd

A simple http server.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

query params解析不正确导致运行错误

clysto opened this issue · comments

解析的时候应该将query params去除后作为url

# request.py
class Request:
    def __init__(self, request_txt):
        tmp = request_txt.split("\r\n\r\n")
        head = tmp[0]
        body = tmp[1] if len(tmp) > 1 else ""
        head = head.split("\r\n")
        request_line = head[0]

        #### there ####
        [method, url, protocol] = request_line.split(" ")


        self.method = method
        self.url = url
        self.protocol = protocol
        self.body = body
        self.header = {}
        for i in range(1, len(head)):
            line = head[i]
            [k, v] = line.split(": ")
            self.header[k] = v

    def __str__(self):
        return str(
            {
                "method": self.method,
                "url": self.url,
                "protocol": self.protocol,
                "body": self.body,
                "header": self.header,
            }
        )

批注 2020-07-02 005556