Documentation
¶
Overview ¶
User settings (Using HTTP cookies)
Index ¶
- Variables
- func ClearAllCookies(w http.ResponseWriter, r *http.Request)
- func ClearCookie(w http.ResponseWriter, r *http.Request, name CookieName)
- func GetCookie(r *http.Request, name CookieName) string
- func GetImageProxy(r *http.Request) url.URL
- func GetStaticProxy(r *http.Request) url.URL
- func GetUgoiraProxy(r *http.Request) url.URL
- func GetUserToken(r *http.Request) string
- func SetCookie(w http.ResponseWriter, r *http.Request, name CookieName, value string)
- func ShouldCookieBeSecure(r *http.Request) bool
- type CookieName
Constants ¶
This section is empty.
Variables ¶
var ( AllCookieNames = []CookieName{ TokenCookie, CSRFCookie, YUIDBCookie, PAbDIDCookie, PAbIDCookie, PAbID2Cookie, UsernameCookie, UserIDCookie, UserAvatarCookie, ImageProxyCookie, StaticProxyCookie, UgoiraProxyCookie, NovelFontTypeCookie, NovelViewModeCookie, ThumbnailToNewTabCookie, SeasonalEffectsEnabledCookie, VisibilityArtR18Cookie, VisibilityArtR18GCookie, VisibilityArtAICookie, LocaleCookie, LogoStyleCookie, BlacklistArtistCookie, BlacklistTagCookie, ThumbnailNavVisibleCookie, OpenAllButtonCookie, } )
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 GetImageProxy ¶
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 ¶
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 ¶
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 ¶
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 ¶
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" 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).