cookieflag

package module
v0.0.0-...-c749657 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

caddy-cookieflag

Build and test GoDoc Go Report Card

This is a caddy plugin. Needs >= 2.8.0. Adds or removes flags (Secure and HttpOnly, etc) from the cookies set by the upstream.

Usage

One line usage
:8881 {

    cookieflag +secure
    cookieflag -httponly

    reverse_proxy localhost:8889 {
        header_down -Server
    }
}

:8889 {
    header Content-Type "text/html; charset=utf-8"
    header +Set-Cookie "samesite-ex1=aaa; SameSite=Lax"
    header +Set-Cookie "max-age-ex1=bbb; Max-Age=0"
    header +Set-Cookie "secure-ex1=ccc; Secure"
    header +Set-Cookie "httponly-ex1=ddd; HttpOnly"
    header +Set-Cookie "path-ex1=eee; Path=/"
    header +Set-Cookie "haveitall-ex1=fff; HttpOnly; Secure; Path=/; Max-Age=0; SameSite=Lax; haveitall-ex2=ggg"
    respond "{host}{uri}"
}
Block usage
:8881 {

    cookieflag {
        +secure
        -httponly
    }

    reverse_proxy localhost:8889 {
        header_down -Server
    }
}

:8889 {
    header Content-Type "text/html; charset=utf-8"
    header +Set-Cookie "samesite-ex1=aaa; SameSite=Lax"
    header +Set-Cookie "max-age-ex1=bbb; Max-Age=0"
    header +Set-Cookie "secure-ex1=ccc; Secure"
    header +Set-Cookie "httponly-ex1=ddd; HttpOnly"
    header +Set-Cookie "path-ex1=eee; Path=/"
    header +Set-Cookie "haveitall-ex1=fff; HttpOnly; Secure; Path=/; Max-Age=0; SameSite=Lax; haveitall-ex2=ggg"
    respond "{host}{uri}"
}

Documentation

Overview

Package cookieflag provides a Caddy module that modifies various flags (Secure, HttpOnly, ...) in Set-Cookie headers. It allows users to customize these flags based on their needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CookieFlag

type CookieFlag struct {
	// The list of cookie flags to be modified.
	//
	// Prepend the flag name with a `+` to add that flag or with `-` to remove it
	//
	// Flag | Description
	// ------------|-------------
	// secure | The `Secure` flag
	// httponly | The `HttpOnly` flag
	Flags []string `json:"flags,omitempty"`
}

CookieFlag manipulate various flags (Secure, HttpOnly, ...) in the Set-Cookie reponse headers.

Syntax:

cookieflag [<matcher>] [(+|-)<field>] {
	+<field>
	-<field>
}

func (CookieFlag) CaddyModule

func (CookieFlag) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (CookieFlag) ServeHTTP

func (cf CookieFlag) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*CookieFlag) UnmarshalCaddyfile

func (cf *CookieFlag) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile sets up the handler from Caddyfile tokens.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL