Documentation
¶
Index ¶
- Constants
- func GetClientRedirectURL(w http.ResponseWriter) string
- type Proxy
- func (p *Proxy) AddHeadEls(els *headels.HeadEls)
- func (p *Proxy) AddHeader(key, value string)
- func (p *Proxy) ApplyToResponseWriter(w http.ResponseWriter, r *http.Request)
- func (p *Proxy) GetCookies() []*http.Cookie
- func (p *Proxy) GetHeadEls() *headels.HeadEls
- func (p *Proxy) GetHeader(key string) string
- func (p *Proxy) GetHeaders(key string) []string
- func (p *Proxy) GetLocation() string
- func (p *Proxy) GetStatus() (int, string)
- func (p *Proxy) IsError() bool
- func (p *Proxy) IsRedirect() bool
- func (p *Proxy) IsSuccess() bool
- func (p *Proxy) Redirect(r *http.Request, url string, code ...int) (bool, error)
- func (p *Proxy) SetCookie(cookie *http.Cookie)
- func (p *Proxy) SetHeader(key, value string)
- func (p *Proxy) SetStatus(status int, errorStatusText ...string)
- type Response
- func (res *Response) AddHeader(key, value string)
- func (res *Response) BadRequest(reasons ...string)
- func (res *Response) ClientRedirect(url string) error
- func (res *Response) Error(status int, reasons ...string)
- func (res *Response) Forbidden(reasons ...string)
- func (res *Response) HTML(html string)
- func (res *Response) HTMLBytes(bytes []byte)
- func (res *Response) InternalServerError(reasons ...string)
- func (res *Response) IsCommitted() bool
- func (res *Response) JSON(v any)
- func (res *Response) JSONBytes(bytes []byte)
- func (res *Response) MethodNotAllowed(reasons ...string)
- func (res *Response) NotFound()
- func (res *Response) NotModified()
- func (res *Response) OK()
- func (res *Response) OKText()
- func (res *Response) Redirect(r *http.Request, url string, code ...int) (usedClientRedirect bool, err error)
- func (res *Response) ServerRedirect(r *http.Request, url string, code ...int)
- func (res *Response) SetHeader(key, value string)
- func (res *Response) SetStatus(status int)
- func (res *Response) Text(text string)
- func (res *Response) TooManyRequests(reasons ...string)
- func (res *Response) Unauthorized(reasons ...string)
Constants ¶
const ( ClientRedirectHeader = "X-Client-Redirect" ClientAcceptsRedirectHeader = "X-Accepts-Client-Redirect" )
Variables ¶
This section is empty.
Functions ¶
func GetClientRedirectURL ¶
func GetClientRedirectURL(w http.ResponseWriter) string
Types ¶
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
For usage in JSON API handlers that may run in parallel or do not have direct access to the http.ResponseWriter. Proxy instances are not meant to be shared. Rather, they should exist inside a single function/handler scope, and afterwards should be used by a parent scope to actually de-duplicate, determine priority, and write to the real http.ResponseWriter.
Concurrency model: Proxy instances are NOT thread-safe and must not be shared across goroutines. The intended usage pattern is:
- Create one Proxy per goroutine/task
- Each goroutine writes only to its own Proxy
- After all goroutines complete, merge proxies on a single goroutine using MergeProxyResponses
- Apply the merged result to the ResponseWriter
Do not instantiate directly. Use NewProxy().
func MergeProxyResponses ¶
Consumers should deduplicate head els after calling MergeProxyResponses by using headels.ToHeadEls(proxy.GetHeadElements())
func (*Proxy) AddHeadEls ¶ added in v0.83.0
func (*Proxy) ApplyToResponseWriter ¶
func (p *Proxy) ApplyToResponseWriter(w http.ResponseWriter, r *http.Request)
func (*Proxy) GetCookies ¶
func (*Proxy) GetHeadEls ¶ added in v0.83.0
func (*Proxy) GetHeaders ¶
func (*Proxy) GetLocation ¶
func (*Proxy) IsRedirect ¶
type Response ¶
type Response struct {
Writer http.ResponseWriter
// contains filtered or unexported fields
}
func New ¶
func New(w http.ResponseWriter) Response
func (*Response) BadRequest ¶
func (*Response) ClientRedirect ¶
ClientRedirect sets a client-side redirect header and status 200. Returns an error if the response is already committed.
func (*Response) InternalServerError ¶
func (*Response) IsCommitted ¶
func (*Response) MethodNotAllowed ¶
func (*Response) NotModified ¶
func (res *Response) NotModified()