Skip to content

Is it possible to modify the request header cookies before cherrypy tries to load those cookies? #1998

Answered by debo07
debo07 asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks @webknjaz for your review comments. :)
This is the final snippet as per your review comments. Hope this is fine, I'm just testing it out.

class CookieModifierTool(cherrypy.Tool):
    """
    Modifying the request header cookie value if it has space.
    """

    def __init__(self):
        super().__init__(
            'on_start_resource',
            self.modify_cookie,
            priority=1,
        )

    def modify_cookie(self):
        cookie_header = cherrypy.request.headers.get("Cookie")
        if not cookie_header:
            return
        modified_cookie_header = cookie_header.replace(" ", "")
        cherrypy.request.headers["Cookie"] = modified_cookie_header
        #…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
6 replies
@debo07
Comment options

@webknjaz
Comment options

@webknjaz
Comment options

@debo07
Comment options

@webknjaz
Comment options

Comment options

You must be logged in to vote
1 reply
@webknjaz
Comment options

Answer selected by debo07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants