sqlmap/lib/request/chunkedhandler.py

44 lines
1.5 KiB
Python
Raw Normal View History

2019-05-08 13:47:52 +03:00
#!/usr/bin/env python
"""
Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
See the file 'LICENSE' for copying permission
"""
2019-03-19 16:07:39 +03:00
from lib.core.data import conf
from thirdparty.six.moves import urllib as _urllib
class ChunkedHandler(_urllib.request.HTTPHandler):
"""
Ensures that HTTPHandler is working properly in case of Chunked Transfer-Encoding
"""
2019-03-19 16:07:39 +03:00
def _http_request(self, request):
2019-06-17 17:40:08 +03:00
host = request.get_host() if hasattr(request, "get_host") else request.host
if not host:
raise _urllib.error.URLError("no host given")
2019-06-17 17:40:08 +03:00
if request.data is not None: # POST
data = request.data
if not request.has_header("Content-type"):
request.add_unredirected_header(
"Content-type",
"application/x-www-form-urlencoded")
if not request.has_header("Content-length") and not conf.chunked:
request.add_unredirected_header(
"Content-length", "%d" % len(data))
sel_host = host
if request.has_proxy():
sel_host = _urllib.parse.urlsplit(request.get_selector()).netloc
if not request.has_header("Host"):
request.add_unredirected_header("Host", sel_host)
for name, value in self.parent.addheaders:
name = name.capitalize()
if not request.has_header(name):
request.add_unredirected_header(name, value)
return request
2019-03-19 16:07:39 +03:00
http_request = _http_request