session

package
v3.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2025 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

User settings (Using HTTP cookies)

Index

Constants

This section is empty.

Variables

Go can't make this a const...

Functions

func ClearAllCookies

func ClearAllCookies(w http.ResponseWriter, r *http.Request)

func ClearCookie

func ClearCookie(w http.ResponseWriter, r *http.Request, name CookieName)

func GetCookie

func GetCookie(r *http.Request, name CookieName) string

func GetImageProxy

func GetImageProxy(r *http.Request) url.URL

GetImageProxy returns the content proxy URL for i.pximg.net content.

The proxy URL is retrieved from cookies if available, otherwise falls back to the default configuration.

func GetStaticProxy

func GetStaticProxy(r *http.Request) url.URL

GetStaticProxy returns the content proxy URL for s.pximg.net content.

The proxy URL is retrieved from cookies if available, otherwise falls back to the default configuration.

func GetUgoiraProxy

func GetUgoiraProxy(r *http.Request) url.URL

GetUgoiraProxy returns the content proxy URL for ugoira.com content.

The proxy URL is retrieved from cookies if available, otherwise falls back to the default configuration.

func GetUserToken

func GetUserToken(r *http.Request) string

GetUserToken retrieves an authentication token for the pixiv API from the request's 'pixivfe-Token' cookie.

func SetCookie

func SetCookie(w http.ResponseWriter, r *http.Request, name CookieName, value string)

func ShouldCookieBeSecure

func ShouldCookieBeSecure(r *http.Request) bool

ShouldCookieBeSecure determines if a cookie should have the Secure attribute.

Target environments are (containerized and bare metal):

  • Internet -> reverse proxy (e.g. cloudflare) -> reverse proxy -> application
  • Internet -> reverse proxy -> application
  • LAN -> reverse proxy -> application
  • LAN -> application
  • localhost -> application

This function will incorrectly return false if the last reverse proxy in the chain has a public IP address, but this is expected to be a small minority of deployments.

Types

type CookieName

type CookieName string
const (
	// Authentication and user identity cookies.
	TokenCookie      CookieName = "Token" // #nosec:G101 - false positive
	CSRFCookie       CookieName = "CSRF"
	YUIDBCookie      CookieName = "YUID-B"
	PAbDIDCookie     CookieName = "P-AB-D-ID"
	PAbIDCookie      CookieName = "P-AB-ID"
	PAbID2Cookie     CookieName = "P-AB-ID-2"
	UsernameCookie   CookieName = "Username"
	UserIDCookie     CookieName = "UserID"
	UserAvatarCookie CookieName = "UserAvatar"

	// User preference and settings cookies.
	ImageProxyCookie             CookieName = "ImageProxy"
	StaticProxyCookie            CookieName = "StaticProxy"
	UgoiraProxyCookie            CookieName = "UgoiraProxy"
	NovelFontTypeCookie          CookieName = "NovelFontType"
	NovelViewModeCookie          CookieName = "NovelViewMode"
	ThumbnailToNewTabCookie      CookieName = "ThumbnailToNewTab"
	SeasonalEffectsEnabledCookie CookieName = "SeasonalEffectsEnabled"
	VisibilityArtR18Cookie       CookieName = "VisibilityArtR18"
	VisibilityArtR18GCookie      CookieName = "VisibilityArtR18G"
	VisibilityArtAICookie        CookieName = "VisibilityArtAI"
	LocaleCookie                 CookieName = "Locale"
	LogoStyleCookie              CookieName = "LogoStyle"
	BlacklistArtistCookie        CookieName = "BlacklistArtist"
	BlacklistTagCookie           CookieName = "BlacklistTag"
	ThumbnailNavVisibleCookie    CookieName = "ThumbnailNavVisible"
	OpenAllButtonCookie          CookieName = "OpenAllButton"

	// Limiter cookie.
	PingCookie CookieName = "Ping"
)

Cookie names defined as constants.

NOTE: We don't use the `__Host-` prefix to avoid login issues on non-HTTPS deployments where the localhost exemption doesn't apply (ref: https://codeberg.org/PixivFE/PixivFE/issues/132).

Jump to

Keyboard shortcuts

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