mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
minor
Former-commit-id: e83456ced3d00d6da3001d083e22a0568748298e
This commit is contained in:
parent
6d977dacd2
commit
46ff69e28e
4
cache/client/handler.go
vendored
4
cache/client/handler.go
vendored
|
@ -64,9 +64,7 @@ func (h *Handler) AddRule(r rule.Rule) *Handler {
|
|||
}
|
||||
|
||||
var emptyHandler = func(ctx context.Context) {
|
||||
ctx.StatusCode(500)
|
||||
ctx.WriteString("cache: empty body handler")
|
||||
ctx.StopExecution()
|
||||
ctx.StopWithText(500, "cache: empty body handler")
|
||||
}
|
||||
|
||||
func parseLifeChanger(ctx context.Context) entry.LifeChanger {
|
||||
|
|
|
@ -1900,6 +1900,16 @@ func (ctx *context) RemoteAddr() string {
|
|||
return addr
|
||||
}
|
||||
|
||||
// TrimHeaderValue returns the "v[0:first space or semicolon]".
|
||||
func TrimHeaderValue(v string) string {
|
||||
for i, char := range v {
|
||||
if char == ' ' || char == ';' {
|
||||
return v[:i]
|
||||
}
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// GetHeader returns the request header's value based on its name.
|
||||
func (ctx *context) GetHeader(name string) string {
|
||||
return ctx.request.Header.Get(name)
|
||||
|
@ -2107,7 +2117,7 @@ func (ctx *context) Header(name string, value string) {
|
|||
ctx.writer.Header().Add(name, value)
|
||||
}
|
||||
|
||||
const contentTypeContextKey = "_iris_content_type"
|
||||
const contentTypeContextKey = "iris.content_type"
|
||||
|
||||
func shouldAppendCharset(cType string) bool {
|
||||
return cType != ContentBinaryHeaderValue && cType != ContentWebassemblyHeaderValue
|
||||
|
@ -2158,16 +2168,6 @@ func (ctx *context) GetContentType() string {
|
|||
return ctx.writer.Header().Get(ContentTypeHeaderKey)
|
||||
}
|
||||
|
||||
// TrimHeaderValue returns the "v[0:first space or semicolon]".
|
||||
func TrimHeaderValue(v string) string {
|
||||
for i, char := range v {
|
||||
if char == ' ' || char == ';' {
|
||||
return v[:i]
|
||||
}
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// GetContentType returns the request's header value of "Content-Type".
|
||||
func (ctx *context) GetContentTypeRequested() string {
|
||||
return TrimHeaderValue(ctx.GetHeader(ContentTypeHeaderKey))
|
||||
|
@ -3083,6 +3083,8 @@ const (
|
|||
ContentEncodingHeaderKey = "Content-Encoding"
|
||||
// GzipHeaderValue is the header value of "gzip".
|
||||
GzipHeaderValue = "gzip"
|
||||
// FlateHeaderValue is the header value of "deflate".
|
||||
FlateHeaderValue = "deflate"
|
||||
// AcceptEncodingHeaderKey is the header key of "Accept-Encoding".
|
||||
AcceptEncodingHeaderKey = "Accept-Encoding"
|
||||
// VaryHeaderKey is the header key of "Vary".
|
||||
|
@ -3250,12 +3252,13 @@ func (ctx *context) StreamWriter(writer func(w io.Writer) bool) {
|
|||
// ClientSupportsGzip retruns true if the client supports gzip compression.
|
||||
func (ctx *context) ClientSupportsGzip() bool {
|
||||
if h := ctx.GetHeader(AcceptEncodingHeaderKey); h != "" {
|
||||
for _, v := range strings.Split(h, ";") {
|
||||
for _, v := range strings.Split(h, ",") {
|
||||
if strings.Contains(v, GzipHeaderValue) { // we do Contains because sometimes browsers has the q=, we don't use it atm. || strings.Contains(v,"deflate"){
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -3506,8 +3509,7 @@ func (ctx *context) View(filename string, optionalViewModel ...interface{}) erro
|
|||
|
||||
err := ctx.app.View(ctx, filename, layout, bindingData)
|
||||
if err != nil {
|
||||
ctx.StatusCode(http.StatusInternalServerError)
|
||||
ctx.StopExecution()
|
||||
ctx.StopWithStatus(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return err
|
||||
|
|
|
@ -114,7 +114,7 @@ func (t *Transaction) Complete(err error) {
|
|||
reason = errWstatus.Reason
|
||||
}
|
||||
// get the content type used on this transaction
|
||||
if cTypeH := t.context.ResponseWriter().Header().Get(ContentTypeHeaderKey); cTypeH != "" {
|
||||
if cTypeH := t.context.GetContentType(); cTypeH != "" {
|
||||
cType = cTypeH
|
||||
}
|
||||
|
||||
|
@ -168,8 +168,7 @@ var RequestTransactionScope = TransactionScopeFunc(func(maybeErr TransactionErrR
|
|||
ctx.ContentType(maybeErr.ContentType)
|
||||
} else {
|
||||
// else execute the registered user error and skip the next transactions and all normal flow,
|
||||
ctx.StatusCode(maybeErr.StatusCode)
|
||||
ctx.StopExecution()
|
||||
ctx.StopWithStatus(maybeErr.StatusCode)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -51,8 +51,7 @@ func New() context.Handler {
|
|||
logMessage += fmt.Sprintf("\n%s", stacktrace)
|
||||
ctx.Application().Logger().Warn(logMessage)
|
||||
|
||||
ctx.StatusCode(500)
|
||||
ctx.StopExecution()
|
||||
ctx.StopWithStatus(500)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user