(items=None)
return headers
Prepare HTTP Cookie, HTTP User-Agent and HTTP Referer headers to use when performing
    the HTTP requests
Prepare HTTP Cookie, HTTP User-Agent and HTTP Referer headers to use when performing
    the HTTP requests
Prepare HTTP Cookie HTTP User - Agent and HTTP Referer headers to use when performing the HTTP requests
def forgeHeaders(items=None):
    """
    Prepare HTTP Cookie, HTTP User-Agent and HTTP Referer headers to use when performing
    the HTTP requests
    """

    items = items or {}

    for _ in items.keys():
        if items[_] is None:
            del items[_]

    headers = OrderedDict(conf.httpHeaders)
    headers.update(items.items())

    class _str(str):
        def capitalize(self):
            return _str(self)

        def title(self):
            return _str(self)

    _ = headers
    headers = OrderedDict()
    for key, value in _.items():
        success = False

        for _ in headers:
            if _.upper() == key.upper():
                del headers[_]
                break

        if key.upper() not in (_.upper() for _ in getPublicTypeMembers(HTTP_HEADER, True)):
            try:
                headers[_str(key)] = value  # dirty hack for http://bugs.python.org/issue12455
            except UnicodeEncodeError:      # don't do the hack on non-ASCII header names (they have to be properly encoded later on)
                pass
            else:
                success = True
        if not success:
            key = '-'.join(_.capitalize() for _ in key.split('-'))
            headers[key] = value

    if conf.cj:
        if HTTP_HEADER.COOKIE in headers:
            for cookie in conf.cj:
                if cookie.domain_specified and not conf.hostname.endswith(cookie.domain):
                    continue

                if ("%s=" % cookie.name) in headers[HTTP_HEADER.COOKIE]:
                    if conf.loadCookies:
                        conf.httpHeaders = filter(None, ((item if item[0] != HTTP_HEADER.COOKIE else None) for item in conf.httpHeaders))
                    elif kb.mergeCookies is None:
                        message = "you provided a HTTP %s header value. " % HTTP_HEADER.COOKIE
                        message += "The target URL provided its own cookies within "
                        message += "the HTTP %s header which intersect with yours. " % HTTP_HEADER.SET_COOKIE
                        message += "Do you want to merge them in futher requests? [Y/n] "
                        _ = readInput(message, default="Y")
                        kb.mergeCookies = not _ or _[0] in ("y", "Y")

                    if kb.mergeCookies and kb.injection.place != PLACE.COOKIE:
                        _ = lambda x: re.sub(r"(?i)\b%s=[^%s]+" % (re.escape(cookie.name), conf.cookieDel or DEFAULT_COOKIE_DELIMITER), "%s=%s" % (cookie.name, getUnicode(cookie.value)), x)
                        headers[HTTP_HEADER.COOKIE] = _(headers[HTTP_HEADER.COOKIE])

                        if PLACE.COOKIE in conf.parameters:
                            conf.parameters[PLACE.COOKIE] = _(conf.parameters[PLACE.COOKIE])

                        conf.httpHeaders = [(item[0], item[1] if item[0] != HTTP_HEADER.COOKIE else _(item[1])) for item in conf.httpHeaders]

                elif not kb.testMode:
                    headers[HTTP_HEADER.COOKIE] += "%s %s=%s" % (conf.cookieDel or DEFAULT_COOKIE_DELIMITER, cookie.name, getUnicode(cookie.value))

        if kb.testMode and not conf.csrfToken:
            resetCookieJar(conf.cj)

    return headers
def forgeHeaders ( items = None ) : items = items or { } for _ in items . keys ( ) : if items [ _ ] is None : del items [ _ ] headers = OrderedDict ( conf . httpHeaders ) headers . update ( items . items ( ) ) class _str ( str ) : def capitalize ( self ) : return _str ( self ) def title ( self ) : return _str ( self ) _ = headers headers = OrderedDict ( ) for key , value in _ . items ( ) : success = False for _ in headers : if _ . upper ( ) == key . upper ( ) : del headers [ _ ] break if key . upper ( ) not in ( _ . upper ( ) for _ in getPublicTypeMembers ( HTTP_HEADER , True ) ) : try : headers [ _str ( key ) ] = value # dirty hack for http://bugs.python.org/issue12455 except UnicodeEncodeError : # don't do the hack on non-ASCII header names (they have to be properly encoded later on) pass else : success = True if not success : key = '-' . join ( _ . capitalize ( ) for _ in key . split ( '-' ) ) headers [ key ] = value if conf . cj : if HTTP_HEADER . COOKIE in headers : for cookie in conf . cj : if cookie . domain_specified and not conf . hostname . endswith ( cookie . domain ) : continue if ( "%s=" % cookie . name ) in headers [ HTTP_HEADER . COOKIE ] : if conf . loadCookies : conf . httpHeaders = filter ( None , ( ( item if item [ 0 ] != HTTP_HEADER . COOKIE else None ) for item in conf . httpHeaders ) ) elif kb . mergeCookies is None : message = "you provided a HTTP %s header value. " % HTTP_HEADER . COOKIE message += "The target URL provided its own cookies within " message += "the HTTP %s header which intersect with yours. " % HTTP_HEADER . SET_COOKIE message += "Do you want to merge them in futher requests? [Y/n] " _ = readInput ( message , default = "Y" ) kb . mergeCookies = not _ or _ [ 0 ] in ( "y" , "Y" ) if kb . mergeCookies and kb . injection . place != PLACE . COOKIE : _ = lambda x : re . sub ( r"(?i)\b%s=[^%s]+" % ( re . escape ( cookie . name ) , conf . cookieDel or DEFAULT_COOKIE_DELIMITER ) , "%s=%s" % ( cookie . name , getUnicode ( cookie . value ) ) , x ) headers [ HTTP_HEADER . COOKIE ] = _ ( headers [ HTTP_HEADER . COOKIE ] ) if PLACE . COOKIE in conf . parameters : conf . parameters [ PLACE . COOKIE ] = _ ( conf . parameters [ PLACE . COOKIE ] ) conf . httpHeaders = [ ( item [ 0 ] , item [ 1 ] if item [ 0 ] != HTTP_HEADER . COOKIE else _ ( item [ 1 ] ) ) for item in conf . httpHeaders ] elif not kb . testMode : headers [ HTTP_HEADER . COOKIE ] += "%s %s=%s" % ( conf . cookieDel or DEFAULT_COOKIE_DELIMITER , cookie . name , getUnicode ( cookie . value ) ) if kb . testMode and not conf . csrfToken : resetCookieJar ( conf . cj ) return headers