本文整理汇总了Python中w3af.core.data.dc.headers.Headers.iget方法的典型用法代码示例。如果您正苦于以下问题:Python Headers.iget方法的具体用法?Python Headers.iget怎么用?Python Headers.iget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类w3af.core.data.dc.headers.Headers
的用法示例。
在下文中一共展示了Headers.iget方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_all_headers
# 需要导入模块: from w3af.core.data.dc.headers import Headers [as 别名]
# 或者: from w3af.core.data.dc.headers.Headers import iget [as 别名]
def get_all_headers(self):
"""
:return: Calls get_default_headers to get the default framework headers,
get_post_data_headers to get the DataContainer headers, merges that info
with the user specified headers (which live in self._headers) and
returns a Headers instance which will be sent to the wire.
"""
wire_headers = Headers()
for k, v in chain(self._headers.items(),
self.get_post_data_headers().items()):
# Please note that here we're overwriting the headers from the
# fuzzable request with the headers from the data container,
# the overwriting is done in this order due to the order in the
# chain() items above
#
# I found a bug where I loaded a request from spider_man, saved
# it using dump() and then tried to load it again and failed because
# of this overwriting not being done (the multipart boundary was
# incorrect).
#
# Keep that in mind in case you want to change this overwriting!
#
# Overwrite the existing one, case insensitive style
_, stored_header_name = wire_headers.iget(k, None)
if stored_header_name is not None:
wire_headers[stored_header_name] = v
else:
wire_headers[k] = v
return wire_headers
示例2: test_headers_iget
# 需要导入模块: from w3af.core.data.dc.headers import Headers [as 别名]
# 或者: from w3af.core.data.dc.headers.Headers import iget [as 别名]
def test_headers_iget(self):
upper_headers = Headers([('Abc', 'b')])
value, real_header = upper_headers.iget('abc')
self.assertEqual(value, 'b')
self.assertEqual(real_header, 'Abc')
示例3: dc_from_hdrs_post
# 需要导入模块: from w3af.core.data.dc.headers import Headers [as 别名]
# 或者: from w3af.core.data.dc.headers.Headers import iget [as 别名]
def dc_from_hdrs_post(headers, post_data):
"""
:param headers: HTTP request headers, most importantly containing the
content-type info.
:param post_data: The HTTP request post-data as a string
:return: The best-match from POST_DATA_CONTAINERS to hold the information
in self._post_data @ FuzzableRequest
"""
if headers is None:
headers = Headers()
for pdc_klass in POST_DATA_CONTAINERS:
try:
return pdc_klass.from_postdata(headers, post_data)
except (ValueError, TypeError) as e:
pass
else:
content_type, _ = headers.iget("content-type", "None")
msg = 'Unknown post-data. Content-type: "%s" and/or post-data "%s"'
om.out.debug(msg % (content_type, post_data[:50]))
# These lines are for debugging
# import traceback
# traceback.print_stack()
return PlainContainer.from_postdata(headers, post_data)
示例4: get_headers
# 需要导入模块: from w3af.core.data.dc.headers import Headers [as 别名]
# 或者: from w3af.core.data.dc.headers.Headers import iget [as 别名]
def get_headers(self):
"""
Query the spec / operation and return the headers, including the
content-type, which will be used later to know how to serialize the
body.
"""
request_dict = self._bravado_construct_request()
headers = Headers(request_dict['headers'].items())
# First, we try to extract content type from a 'consumes'
# if the operation has one.
content_type = self.get_consuming_content_type()
if content_type is not None:
headers['Content-Type'] = content_type
content_type, _ = headers.iget('content-type', None)
if content_type is None and self.parameters:
# Content-Type is not set yet.
#
# There are some specification documents where the consumes
# section might be empty. This is because the operation doesn't
# receive anything or because the specification is wrong.
#
# If there are parameters then we opt for serializing them as
# JSON, which is a safe default
headers['Content-Type'] = self.DEFAULT_CONTENT_TYPE
return headers
示例5: get_all_headers
# 需要导入模块: from w3af.core.data.dc.headers import Headers [as 别名]
# 或者: from w3af.core.data.dc.headers.Headers import iget [as 别名]
def get_all_headers(self):
"""
:return: Calls get_default_headers to get the default framework headers,
get_post_data_headers to get the DataContainer headers, merges that info
with the user specified headers (which live in self._headers) and
returns a Headers instance which will be sent to the wire.
"""
wire_headers = Headers()
for k, v in chain(self._headers.items(),
self.get_post_data_headers().items()):
# Ignore any keys which are already defined in the user-specified
# headers
kvalue, kreal = wire_headers.iget(k, None)
if kvalue is not None:
continue
wire_headers[k] = v
return wire_headers
示例6: http_request_parser
# 需要导入模块: from w3af.core.data.dc.headers import Headers [as 别名]
# 或者: from w3af.core.data.dc.headers.Headers import iget [as 别名]
def http_request_parser(head, postdata):
"""
This function parses HTTP Requests from a string to a FuzzableRequest.
:param head: The head of the request.
:param postdata: The post data of the request
:return: A FuzzableRequest object with all the corresponding information
that was sent in head and postdata
:author: Andres Riancho ([email protected])
"""
# Parse the request head, the strip() helps us deal with the \r (if any)
split_head = head.split("\n")
split_head = [h.strip() for h in split_head if h]
if not split_head:
msg = "The HTTP request is invalid."
raise BaseFrameworkException(msg)
# Get method, uri, version
method_uri_version = split_head[0]
first_line = method_uri_version.split(" ")
if len(first_line) == 3:
# Ok, we have something like "GET /foo HTTP/1.0". This is the best case
# for us!
method, uri, version = first_line
elif len(first_line) < 3:
msg = 'The HTTP request has an invalid <method> <uri> <version>: "%s"'
raise BaseFrameworkException(msg % method_uri_version)
elif len(first_line) > 3:
# GET /hello world.html HTTP/1.0
# Mostly because we are permissive... we are going to try to parse
# the request...
method = first_line[0]
version = first_line[-1]
uri = " ".join(first_line[1:-1])
check_version_syntax(version)
# If we got here, we have a nice method, uri, version first line
# Now we parse the headers (easy!) and finally we send the request
headers_str = split_head[1:]
headers_inst = Headers()
for header in headers_str:
one_split_header = header.split(":", 1)
if len(one_split_header) == 1:
msg = 'The HTTP request has an invalid header: "%s".'
raise BaseFrameworkException(msg % header)
header_name = one_split_header[0].strip()
header_value = one_split_header[1].strip()
if header_name in headers_inst:
headers_inst[header_name] += ", " + header_value
else:
headers_inst[header_name] = header_value
host, _ = headers_inst.iget("host", None)
try:
uri = URL(check_uri_syntax(uri, host))
except ValueError, ve:
raise BaseFrameworkException(str(ve))
示例7: HTTPResponse
# 需要导入模块: from w3af.core.data.dc.headers import Headers [as 别名]
# 或者: from w3af.core.data.dc.headers.Headers import iget [as 别名]
#.........这里部分代码省略.........
def get_redir_url(self):
return self._redirected_url
def set_redir_uri(self, ru):
self._redirected_uri = ru
def get_redir_uri(self):
return self._redirected_uri
def get_headers(self):
if self._headers is None:
self.headers = self._info
assert self._headers is not None
return self._headers
def set_headers(self, headers):
"""
Sets the headers and also analyzes them in order to get the response
mime type (text/html , application/pdf, etc).
:param headers: The headers dict.
"""
# Fix lowercase in header names from HTTPMessage
if isinstance(headers, httplib.HTTPMessage):
self._headers = Headers()
for header in headers.headers:
key, value = header.split(':', 1)
self._headers[key.strip()] = value.strip()
else:
self._headers = headers
find_word = lambda w: content_type.find(w) != -1
content_type_hvalue, _ = self._headers.iget(CONTENT_TYPE, None)
# we need exactly content type but not charset
if content_type_hvalue is not None:
try:
self._content_type = content_type_hvalue.split(';', 1)[0].strip().lower()
except:
msg = 'Invalid Content-Type value "%s" sent in HTTP response.'
om.out.debug(msg % (content_type_hvalue,))
else:
content_type = self._content_type
# Set the doc_type
if content_type.count('image'):
self._doc_type = HTTPResponse.DOC_TYPE_IMAGE
elif content_type.count('pdf'):
self._doc_type = HTTPResponse.DOC_TYPE_PDF
elif content_type.count('x-shockwave-flash'):
self._doc_type = HTTPResponse.DOC_TYPE_SWF
elif any(imap(find_word,
('text', 'html', 'xml', 'txt', 'javascript'))):
self._doc_type = HTTPResponse.DOC_TYPE_TEXT_OR_HTML
# Check if the doc type is still None, that would mean that none of the
# previous if statements matched.
#
# Note that I'm doing this here and not before the other if statements
# because that triggered a race condition with threads asking if the
# _doc_type was != None (which it was because I was setting it to
# DOC_TYPE_OTHER) and that raised all types of errors.