2019-03-21 16:00:09 +03:00
|
|
|
#!/usr/bin/env python2
|
2019-03-19 15:26:29 +03:00
|
|
|
|
|
|
|
"""
|
|
|
|
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
|
2019-03-27 15:33:46 +03:00
|
|
|
from thirdparty.six.moves import urllib as _urllib
|
2019-03-19 15:26:29 +03:00
|
|
|
|
2019-03-27 15:33:46 +03:00
|
|
|
class ChunkedHandler(_urllib.request.HTTPHandler):
|
2019-03-19 15:26:29 +03:00
|
|
|
"""
|
2019-03-27 15:33:46 +03:00
|
|
|
Ensures that HTTPHandler is working properly in case of Chunked Transfer-Encoding
|
2019-03-19 15:26:29 +03:00
|
|
|
"""
|
|
|
|
|
2019-03-19 16:07:39 +03:00
|
|
|
def _http_request(self, request):
|
2019-03-19 15:26:29 +03:00
|
|
|
host = request.get_host()
|
|
|
|
if not host:
|
2019-03-27 15:33:46 +03:00
|
|
|
raise _urllib.error.URLError("no host given")
|
2019-03-19 15:26:29 +03:00
|
|
|
|
|
|
|
if request.has_data(): # POST
|
|
|
|
data = request.get_data()
|
2019-03-27 15:33:46 +03:00
|
|
|
if not request.has_header("Content-type"):
|
2019-03-19 15:26:29 +03:00
|
|
|
request.add_unredirected_header(
|
2019-03-27 15:33:46 +03:00
|
|
|
"Content-type",
|
|
|
|
"application/x-www-form-urlencoded")
|
|
|
|
if not request.has_header("Content-length") and not conf.chunked:
|
2019-03-19 15:26:29 +03:00
|
|
|
request.add_unredirected_header(
|
2019-03-27 15:33:46 +03:00
|
|
|
"Content-length", "%d" % len(data))
|
2019-03-19 15:26:29 +03:00
|
|
|
|
|
|
|
sel_host = host
|
|
|
|
if request.has_proxy():
|
2019-03-27 15:33:46 +03:00
|
|
|
sel_host = _urllib.parse.urlsplit(request.get_selector()).netloc
|
2019-03-19 15:26:29 +03:00
|
|
|
|
2019-03-27 15:33:46 +03:00
|
|
|
if not request.has_header("Host"):
|
|
|
|
request.add_unredirected_header("Host", sel_host)
|
2019-03-19 15:26:29 +03:00
|
|
|
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
|