Documentation ¶
Index ¶
- Constants
- Variables
- func BindJSONBody(r *http.Request, w http.ResponseWriter, v *validation.SchemaValidator, ...) error
- func CSPJoin(directives []string) string
- func CheckContentType(raws []string) httproute.MiddlewareFunc
- func CookieDomainWithoutPort(host string) string
- func GetHost(r *http.Request, trustProxy bool) string
- func GetIP(r *http.Request, trustProxy bool) (ip string)
- func GetProto(r *http.Request, trustProxy bool) string
- func GetRedirectURI(r *http.Request, trustProxy bool) (out string, err error)
- func HealthCheckHandler(w http.ResponseWriter, r *http.Request)
- func HostRelative(u *url.URL) *url.URL
- func IsJSONContentType(contentType string) bool
- func NewExternalClient(timeout time.Duration) *http.Client
- func NewExternalClientWithOptions(timeout time.Duration, opts ExternalClientOptions) *http.Client
- func NoCache(next http.Handler) http.Handler
- func NoStore(next http.Handler) http.Handler
- func ParseJSONBody(r *http.Request, w http.ResponseWriter, ...) error
- func ShouldSendSameSiteNone(useragent string, secure bool) bool
- func StaticSecurityHeaders(next http.Handler) http.Handler
- func UpdateCookie(w http.ResponseWriter, cookie *http.Cookie)
- type BodyDefaulter
- type CookieDef
- type CookieManager
- type ExternalClientOptions
- type FileServer
- type FilesystemCache
- type FlashMessage
- type FlashMessageCookieManager
- type HTTPHost
- type HTTPProto
- type JSONResponseWriter
- type JSONResponseWriterLogger
- type RemoteIP
- type Result
- type ResultRedirect
- type StaticCSPHeader
- type TutorialCookie
- type TutorialCookieManager
- type TutorialCookieName
- type UserAgentString
Constants ¶
const BodyMaxSize = 1024 * 1024 * 10
Variables ¶
var DependencySet = wire.NewSet( NewJSONResponseWriterLogger, wire.Struct(new(JSONResponseWriter), "*"), wire.Struct(new(FlashMessage), "*"), wire.Struct(new(TutorialCookie), "*"), )
var FlashMessageTypeCookieDef = &CookieDef{ NameSuffix: "flash_message_type", Path: "/", SameSite: http.SameSiteNoneMode, }
FlashMessageTypeCookieDef is a HTTP session cookie.
var TutorialCookieNames = []TutorialCookieName{ SignupLoginTutorialCookieName, SettingsTutorialCookieName, }
Functions ¶
func BindJSONBody ¶
func BindJSONBody(r *http.Request, w http.ResponseWriter, v *validation.SchemaValidator, payload interface{}) error
func CheckContentType ¶
func CheckContentType(raws []string) httproute.MiddlewareFunc
func CookieDomainWithoutPort ¶
CookieDomainWithoutPort derives host from r. If host has port, the port is removed. If host-1 is longer than ETLD+1, host-1 is returned. If ETLD+1 cannot be derived, an empty string is returned. The return value never have port.
func HealthCheckHandler ¶
func HealthCheckHandler(w http.ResponseWriter, r *http.Request)
HealthCheckHandler is basic handler for server health check
func IsJSONContentType ¶
func NewExternalClientWithOptions ¶
func NewExternalClientWithOptions(timeout time.Duration, opts ExternalClientOptions) *http.Client
func NoCache ¶
NoCache allows caches to store a response but requires them to revalidate it before reuse.
func ParseJSONBody ¶
func ShouldSendSameSiteNone ¶
func UpdateCookie ¶
func UpdateCookie(w http.ResponseWriter, cookie *http.Cookie)
Types ¶
type BodyDefaulter ¶
type BodyDefaulter interface {
SetDefaults()
}
type CookieManager ¶
type CookieManager struct { Request *http.Request TrustProxy bool CookiePrefix string CookieDomain string }
func (*CookieManager) ClearCookie ¶
func (f *CookieManager) ClearCookie(def *CookieDef) *http.Cookie
ClearCookie generates a cookie that when set, the cookie is clear.
func (*CookieManager) CookieName ¶
func (f *CookieManager) CookieName(def *CookieDef) string
CookieName returns the full name, that is, CookiePrefix followed by NameSuffix.
func (*CookieManager) GetCookie ¶
GetCookie is wrapper around http.Request.Cookie, taking care of cookie name.
func (*CookieManager) ValueCookie ¶
func (f *CookieManager) ValueCookie(def *CookieDef, value string) *http.Cookie
ValueCookie generates a cookie that when set, the cookie is set to the specified value.
type ExternalClientOptions ¶
type ExternalClientOptions struct {
FollowRedirect bool
}
type FileServer ¶
type FileServer struct { FileSystem http.FileSystem FallbackToIndexHTML bool }
FileServer is a specialized version of http.FileServer that assumes files rooted at FileSystem are name-hashed. cache-control are written specifically for index.html and name-hashed files.
func (*FileServer) ServeHTTP ¶
func (s *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
type FilesystemCache ¶
type FilesystemCache struct {
// contains filtered or unexported fields
}
FilesystemCache is a helper to write the response into the tmp directory. The response is then served with http.FileServer, with the advantage of supporting range request and cache validation. If the file is not modified, the response is a 304. For even better performance, we need to add Cache-Control header to take advantage of the fact that the filename is hashed. However, http.FileServer does not support Cache-Control. Unconditionally adding Cache-Control for non-existent file is problematic.
func NewFilesystemCache ¶
func NewFilesystemCache() *FilesystemCache
func (*FilesystemCache) Clear ¶
func (c *FilesystemCache) Clear() error
type FlashMessage ¶
type FlashMessage struct {
Cookies FlashMessageCookieManager
}
func (*FlashMessage) Flash ¶
func (f *FlashMessage) Flash(rw http.ResponseWriter, messageType string)
func (*FlashMessage) Pop ¶
func (f *FlashMessage) Pop(r *http.Request, rw http.ResponseWriter) string
type JSONResponseWriter ¶
type JSONResponseWriter struct {
Logger JSONResponseWriterLogger
}
func (*JSONResponseWriter) WriteResponse ¶
func (w *JSONResponseWriter) WriteResponse(rw http.ResponseWriter, resp *api.Response)
type JSONResponseWriterLogger ¶
func NewJSONResponseWriterLogger ¶
func NewJSONResponseWriterLogger(lf *log.Factory) JSONResponseWriterLogger
type Result ¶
type Result interface { WriteResponse(rw http.ResponseWriter, r *http.Request) IsInternalError() bool }
type ResultRedirect ¶
type ResultRedirect struct {
URL string
}
func (ResultRedirect) IsInternalError ¶
func (re ResultRedirect) IsInternalError() bool
func (ResultRedirect) WriteResponse ¶
func (re ResultRedirect) WriteResponse(rw http.ResponseWriter, r *http.Request)
type StaticCSPHeader ¶
type StaticCSPHeader struct {
CSPDirectives []string
}
type TutorialCookie ¶
type TutorialCookie struct {
Cookies FlashMessageCookieManager
}
func (*TutorialCookie) Pop ¶
func (t *TutorialCookie) Pop(r *http.Request, rw http.ResponseWriter, name TutorialCookieName) bool
func (*TutorialCookie) SetAll ¶
func (t *TutorialCookie) SetAll(rw http.ResponseWriter)
type TutorialCookieManager ¶
type TutorialCookieName ¶
type TutorialCookieName string
const ( SignupLoginTutorialCookieName TutorialCookieName = "signup_login_tutorial" SettingsTutorialCookieName TutorialCookieName = "settings_tutorial" )
type UserAgentString ¶
type UserAgentString string