2019-05-08 13:47:52 +03:00
|
|
|
#!/usr/bin/env python
|
2019-03-19 15:26:29 +03:00
|
|
|
|
|
|
|
"""
|
2023-01-03 01:24:59 +03:00
|
|
|
Copyright (c) 2006-2023 sqlmap developers (https://sqlmap.org/)
|
2019-03-19 15:26:29 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
|
|
|
"""
|
|
|
|
|
2019-03-19 16:07:39 +03:00
|
|
|
from lib.core.data import conf
|
2020-12-01 01:33:08 +03:00
|
|
|
from lib.core.enums import HTTP_HEADER
|
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-06-17 17:40:08 +03:00
|
|
|
host = request.get_host() if hasattr(request, "get_host") else request.host
|
2019-03-19 15:26:29 +03:00
|
|
|
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
|
|
|
|
2019-06-17 17:40:08 +03:00
|
|
|
if request.data is not None: # POST
|
|
|
|
data = request.data
|
2020-12-01 01:33:08 +03:00
|
|
|
if not request.has_header(HTTP_HEADER.CONTENT_TYPE):
|
|
|
|
request.add_unredirected_header(HTTP_HEADER.CONTENT_TYPE, "application/x-www-form-urlencoded")
|
|
|
|
if not request.has_header(HTTP_HEADER.CONTENT_LENGTH) and not conf.chunked:
|
|
|
|
request.add_unredirected_header(HTTP_HEADER.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
|
|
|
|
2020-12-01 01:33:08 +03:00
|
|
|
if not request.has_header(HTTP_HEADER.HOST):
|
|
|
|
request.add_unredirected_header(HTTP_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
|