Skip to content
🛠️ToolsShed

HTTP Cookie Parser

Parse Set-Cookie headers and cookie strings into structured key-value pairs with attribute details.

Paste a Set-Cookie header or cookie string to parse.

About this tool

HTTP cookies are fundamental to modern web development, managing user sessions, preferences, and authentication tokens. However, reading and parsing raw Set-Cookie headers or Cookie strings can be tedious and error-prone, especially when dealing with multiple attributes like Path, Domain, HttpOnly, Secure, and SameSite. This HTTP Cookie Parser tool instantly decodes these strings into organized, human-readable tables, making it simple to inspect cookie structure and understand exactly what each attribute does.

Use this tool to paste a Set-Cookie header (typically from HTTP response headers) or a Cookie string (from HTTP requests or browser DevTools), and the parser will immediately extract the cookie name, value, and all associated attributes with descriptions. This is particularly helpful when debugging authentication issues, verifying security settings, testing cookie handling in APIs, or learning how cookies work under the hood. Both server-side developers and front-end engineers benefit from quickly auditing cookie configurations.

Frequently Asked Questions

Code Implementation

from http.cookies import SimpleCookie
from datetime import datetime

def parse_set_cookie(header: str) -> dict:
    """Parse a Set-Cookie header string."""
    cookie = SimpleCookie()
    cookie.load(header)

    result = {}
    for name, morsel in cookie.items():
        result[name] = {
            "value": morsel.value,
            "path": morsel["path"] or "/",
            "domain": morsel["domain"],
            "expires": morsel["expires"],
            "max_age": morsel["max-age"],
            "secure": morsel["secure"],
            "httponly": morsel["httponly"],
            "samesite": morsel["samesite"],
        }
    return result

# Example
header = "session=abc123; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=3600"
parsed = parse_set_cookie(header)
print(parsed)

# Build a cookie header
def build_set_cookie(name: str, value: str, **attrs) -> str:
    parts = [f"{name}={value}"]
    for k, v in attrs.items():
        if v is True:
            parts.append(k.replace('_', '-'))
        elif v:
            parts.append(f"{k.replace('_', '-')}={v}")
    return "; ".join(parts)

cookie = build_set_cookie("token", "xyz789",
    Path="/", Max_Age=3600, HttpOnly=True, Secure=True, SameSite="Lax")
print(cookie)

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.