Python3将原始http请求解析为dict或HTTPRequest对象

时间:2018-06-05 03:25:52

标签: python-3.x http request

我有一个我从BurpSuite导出的原始请求文件:

POST <some_url> HTTP/1.1
Host: <some_website>
Connection: close
Content-Length: 47
Cache-Control: max-age=0
Origin: https://<some_website>
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: https://<some_website>/<some_url>
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8
Cookie: <cookie>

param=value

我希望能够获取此原始文本并将其转换为字典或HTTPRequest对象,并将其访问为:

with open('request.txt', r) as r:
    req = BurpSuiteRequest(r.readlines())

method = req['method']  # Inherits from dict
# or
method = req.method  # Inherits from HTTPRequest

分别。我发现this看起来很有希望。但是,它是为Python2编写的,而且由于这些库已经在Python3中移动了,我在转换它时遇到了麻烦。我可以在标准库中使用哪些内容更快,更容易出错,自己解析整个问题?

0 个答案:

没有答案