mirror of
https://github.com/kataras/iris.git
synced 2026-05-14 18:13:49 +00:00
implement #1536 with (SetRegisterRule(iris.RouteOverlap))
Former-commit-id: 2b5523ff3e2aab60dd83faa3c520b16a34916fbe
This commit is contained in:
@@ -169,7 +169,6 @@ type Context interface {
|
||||
SetHandlers(Handlers)
|
||||
// Handlers keeps tracking of the current handlers.
|
||||
Handlers() Handlers
|
||||
|
||||
// HandlerIndex sets the current index of the
|
||||
// current context's handlers chain.
|
||||
// If n < 0 or the current handlers length is 0 then it just returns the
|
||||
|
||||
@@ -192,6 +192,7 @@ func (w *GzipResponseWriter) Body() []byte {
|
||||
}
|
||||
|
||||
// ResetBody resets the response body.
|
||||
// Implements the `ResponseWriterBodyReseter`.
|
||||
func (w *GzipResponseWriter) ResetBody() {
|
||||
w.chunks = w.chunks[0:0]
|
||||
}
|
||||
@@ -202,6 +203,26 @@ func (w *GzipResponseWriter) Disable() {
|
||||
w.disabled = true
|
||||
}
|
||||
|
||||
// Reset disables the gzip content writer, clears headers, sets the status code to 200
|
||||
// and clears the cached body.
|
||||
//
|
||||
// Implements the `ResponseWriterReseter`.
|
||||
func (w *GzipResponseWriter) Reset() bool {
|
||||
// disable gzip content writer.
|
||||
w.Disable()
|
||||
// clear headers.
|
||||
h := w.ResponseWriter.Header()
|
||||
for k := range h {
|
||||
h[k] = nil
|
||||
}
|
||||
// restore status code.
|
||||
w.WriteHeader(defaultStatusCode)
|
||||
// reset body.
|
||||
w.ResetBody()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// FlushResponse validates the response headers in order to be compatible with the gzip written data
|
||||
// and writes the data to the underline ResponseWriter.
|
||||
func (w *GzipResponseWriter) FlushResponse() {
|
||||
|
||||
@@ -139,11 +139,15 @@ func (w *ResponseRecorder) ClearHeaders() {
|
||||
}
|
||||
}
|
||||
|
||||
// Reset resets the response body, headers and the status code header.
|
||||
func (w *ResponseRecorder) Reset() {
|
||||
// Reset clears headers, sets the status code to 200
|
||||
// and clears the cached body.
|
||||
//
|
||||
// Implements the `ResponseWriterReseter`.
|
||||
func (w *ResponseRecorder) Reset() bool {
|
||||
w.ClearHeaders()
|
||||
w.WriteHeader(defaultStatusCode)
|
||||
w.ResetBody()
|
||||
return true
|
||||
}
|
||||
|
||||
// FlushResponse the full body, headers and status code to the underline response writer
|
||||
|
||||
@@ -105,6 +105,32 @@ type ResponseWriter interface {
|
||||
CloseNotifier() (http.CloseNotifier, bool)
|
||||
}
|
||||
|
||||
// ResponseWriterBodyReseter can be implemented by
|
||||
// response writers that supports response body overriding
|
||||
// (e.g. recorder and compressed).
|
||||
type ResponseWriterBodyReseter interface {
|
||||
// ResetBody should reset the body and reports back if it could reset successfully.
|
||||
ResetBody()
|
||||
}
|
||||
|
||||
// ResponseWriterDisabler can be implemented
|
||||
// by response writers that can be disabled and restored to their previous state
|
||||
// (e.g. compressed).
|
||||
type ResponseWriterDisabler interface {
|
||||
// Disable should disable this type of response writer and fallback to the default one.
|
||||
Disable()
|
||||
}
|
||||
|
||||
// ResponseWriterReseter can be implemented
|
||||
// by response writers that can clear the whole response
|
||||
// so a new handler can write into this from the beginning.
|
||||
// E.g. recorder, compressed (full) and common writer (status code and headers).
|
||||
type ResponseWriterReseter interface {
|
||||
// Reset should reset the whole response and reports
|
||||
// whether it could reset successfully.
|
||||
Reset() bool
|
||||
}
|
||||
|
||||
// +------------------------------------------------------------+
|
||||
// | Response Writer Implementation |
|
||||
// +------------------------------------------------------------+
|
||||
@@ -167,6 +193,25 @@ func (w *responseWriter) EndResponse() {
|
||||
releaseResponseWriter(w)
|
||||
}
|
||||
|
||||
// Reset clears headers, sets the status code to 200
|
||||
// and clears the cached body.
|
||||
//
|
||||
// Implements the `ResponseWriterReseter`.
|
||||
func (w *responseWriter) Reset() bool {
|
||||
if w.written > 0 {
|
||||
return false // if already written we can't reset this type of response writer.
|
||||
}
|
||||
|
||||
h := w.Header()
|
||||
for k := range h {
|
||||
h[k] = nil
|
||||
}
|
||||
|
||||
w.written = NoWritten
|
||||
w.statusCode = defaultStatusCode
|
||||
return true
|
||||
}
|
||||
|
||||
// SetWritten sets manually a value for written, it can be
|
||||
// NoWritten(-1) or StatusCodeWritten(0), > 0 means body length which is useless here.
|
||||
func (w *responseWriter) SetWritten(n int) {
|
||||
|
||||
Reference in New Issue
Block a user