Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
package context
|
2017-01-02 20:20:17 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
2019-10-24 17:57:05 +02:00
|
|
|
"errors"
|
2020-07-30 19:13:59 +02:00
|
|
|
"io"
|
2017-01-02 20:20:17 +01:00
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
2017-01-04 14:16:53 +01:00
|
|
|
// ResponseWriter interface is used by the context to serve an HTTP handler to
|
2017-01-02 20:20:17 +01:00
|
|
|
// construct an HTTP response.
|
|
|
|
//
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// Note: Only this ResponseWriter is an interface in order to be able
|
|
|
|
// for developers to change the response writer of the Context via `context.ResetResponseWriter`.
|
2020-07-10 22:21:09 +02:00
|
|
|
// The rest of the response writers implementations (ResponseRecorder & CompressResponseWriter)
|
|
|
|
// are coupled to the internal ResponseWriter implementation(*responseWriter).
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
//
|
|
|
|
// A ResponseWriter may not be used after the Handler
|
2017-01-02 20:20:17 +01:00
|
|
|
// has returned.
|
2017-01-04 14:16:53 +01:00
|
|
|
type ResponseWriter interface {
|
|
|
|
http.ResponseWriter
|
|
|
|
|
2017-08-01 21:25:08 +02:00
|
|
|
// Naive returns the simple, underline and original http.ResponseWriter
|
|
|
|
// that backends this response writer.
|
|
|
|
Naive() http.ResponseWriter
|
2020-07-19 09:26:59 +02:00
|
|
|
// SetWriter sets the underline http.ResponseWriter
|
|
|
|
// that this responseWriter should write on.
|
|
|
|
SetWriter(underline http.ResponseWriter)
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// BeginResponse receives an http.ResponseWriter
|
|
|
|
// and initialize or reset the response writer's field's values.
|
|
|
|
BeginResponse(http.ResponseWriter)
|
|
|
|
// EndResponse is the last function which is called right before the server sent the final response.
|
|
|
|
//
|
|
|
|
// Here is the place which we can make the last checks or do a cleanup.
|
|
|
|
EndResponse()
|
|
|
|
|
2019-02-23 06:23:10 +01:00
|
|
|
// IsHijacked reports whether this response writer's connection is hijacked.
|
|
|
|
IsHijacked() bool
|
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// StatusCode returns the status code header value.
|
2017-01-04 14:16:53 +01:00
|
|
|
StatusCode() int
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
|
|
|
|
// Written should returns the total length of bytes that were being written to the client.
|
2017-07-10 17:32:42 +02:00
|
|
|
// In addition iris provides some variables to help low-level actions:
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// NoWritten, means that nothing were written yet and the response writer is still live.
|
2019-06-21 18:43:25 +02:00
|
|
|
// StatusCodeWritten, means that status code was written but no other bytes are written to the client, response writer may closed.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// > 0 means that the reply was written and it's the total number of bytes were written.
|
|
|
|
Written() int
|
|
|
|
|
2017-10-09 14:26:46 +02:00
|
|
|
// SetWritten sets manually a value for written, it can be
|
|
|
|
// NoWritten(-1) or StatusCodeWritten(0), > 0 means body length which is useless here.
|
|
|
|
SetWritten(int)
|
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// SetBeforeFlush registers the unique callback which called exactly before the response is flushed to the client.
|
2017-01-04 14:16:53 +01:00
|
|
|
SetBeforeFlush(cb func())
|
2019-06-07 20:07:08 +02:00
|
|
|
// GetBeforeFlush returns (not execute) the before flush callback, or nil if not set by SetBeforeFlush.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
GetBeforeFlush() func()
|
|
|
|
// FlushResponse should be called only once before EndResponse.
|
|
|
|
// it tries to send the status code if not sent already
|
|
|
|
// and calls the before flush callback, if any.
|
|
|
|
//
|
|
|
|
// FlushResponse can be called before EndResponse, but it should
|
|
|
|
// be the last call of this response writer.
|
|
|
|
FlushResponse()
|
|
|
|
|
|
|
|
// clone returns a clone of this response writer
|
|
|
|
// it copies the header, status code, headers and the beforeFlush finally returns a new ResponseRecorder.
|
|
|
|
Clone() ResponseWriter
|
|
|
|
|
2020-07-30 19:13:59 +02:00
|
|
|
// CopyTo writes a response writer (temp: status code, headers and body) to another response writer
|
|
|
|
CopyTo(ResponseWriter)
|
2018-08-02 16:46:35 +02:00
|
|
|
|
|
|
|
// Flusher indicates if `Flush` is supported by the client.
|
|
|
|
//
|
|
|
|
// The default HTTP/1.x and HTTP/2 ResponseWriter implementations
|
|
|
|
// support Flusher, but ResponseWriter wrappers may not. Handlers
|
|
|
|
// should always test for this ability at runtime.
|
|
|
|
//
|
|
|
|
// Note that even for ResponseWriters that support Flush,
|
|
|
|
// if the client is connected through an HTTP proxy,
|
|
|
|
// the buffered data may not reach the client until the response
|
|
|
|
// completes.
|
|
|
|
Flusher() (http.Flusher, bool)
|
2020-07-16 07:03:55 +02:00
|
|
|
// Flush sends any buffered data to the client.
|
|
|
|
Flush() // required by compress writer.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
}
|
|
|
|
|
2020-06-14 07:09:42 +02:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2020-07-30 19:13:59 +02:00
|
|
|
// ResponseWriterWriteTo can be implemented
|
|
|
|
// by response writers that needs a special
|
|
|
|
// encoding before writing to their buffers.
|
|
|
|
// E.g. a custom recorder that wraps a custom compressed one.
|
|
|
|
//
|
|
|
|
// Not used by the framework itself.
|
|
|
|
type ResponseWriterWriteTo interface {
|
|
|
|
WriteTo(dest io.Writer, p []byte)
|
|
|
|
}
|
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// +------------------------------------------------------------+
|
|
|
|
// | Response Writer Implementation |
|
|
|
|
// +------------------------------------------------------------+
|
|
|
|
|
|
|
|
var rpool = sync.Pool{New: func() interface{} { return &responseWriter{} }}
|
|
|
|
|
|
|
|
// AcquireResponseWriter returns a new *ResponseWriter from the pool.
|
|
|
|
// Releasing is done automatically when request and response is done.
|
|
|
|
func AcquireResponseWriter() ResponseWriter {
|
|
|
|
return rpool.Get().(*responseWriter)
|
2017-01-04 14:16:53 +01:00
|
|
|
}
|
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
func releaseResponseWriter(w ResponseWriter) {
|
|
|
|
rpool.Put(w)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ResponseWriter is the basic response writer,
|
2017-01-04 14:16:53 +01:00
|
|
|
// it writes directly to the underline http.ResponseWriter
|
|
|
|
type responseWriter struct {
|
|
|
|
http.ResponseWriter
|
2020-07-16 07:03:55 +02:00
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
statusCode int // the saved status code which will be used from the cache service
|
|
|
|
// statusCodeSent bool // reply header has been (logically) written | no needed any more as we have a variable to catch total len of written bytes
|
|
|
|
written int // the total size of bytes were written
|
|
|
|
// yes only one callback, we need simplicity here because on FireStatusCode the beforeFlush events should NOT be cleared
|
2017-01-02 20:20:17 +01:00
|
|
|
// but the response is cleared.
|
|
|
|
// Sometimes is useful to keep the event,
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// so we keep one func only and let the user decide when he/she wants to override it with an empty func before the FireStatusCode (context's behavior)
|
2017-01-02 20:20:17 +01:00
|
|
|
beforeFlush func()
|
|
|
|
}
|
|
|
|
|
2017-12-17 23:16:10 +01:00
|
|
|
var _ ResponseWriter = (*responseWriter)(nil)
|
2017-01-02 20:20:17 +01:00
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
const (
|
|
|
|
defaultStatusCode = http.StatusOK
|
|
|
|
// NoWritten !=-1 => when nothing written before
|
|
|
|
NoWritten = -1
|
|
|
|
// StatusCodeWritten != 0 => when only status code written
|
|
|
|
StatusCodeWritten = 0
|
|
|
|
)
|
|
|
|
|
2017-08-01 21:25:08 +02:00
|
|
|
// Naive returns the simple, underline and original http.ResponseWriter
|
|
|
|
// that backends this response writer.
|
|
|
|
func (w *responseWriter) Naive() http.ResponseWriter {
|
|
|
|
return w.ResponseWriter
|
|
|
|
}
|
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// BeginResponse receives an http.ResponseWriter
|
|
|
|
// and initialize or reset the response writer's field's values.
|
|
|
|
func (w *responseWriter) BeginResponse(underline http.ResponseWriter) {
|
|
|
|
w.beforeFlush = nil
|
|
|
|
w.written = NoWritten
|
|
|
|
w.statusCode = defaultStatusCode
|
2020-07-19 09:26:59 +02:00
|
|
|
w.SetWriter(underline)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetWriter sets the underline http.ResponseWriter
|
|
|
|
// that this responseWriter should write on.
|
|
|
|
func (w *responseWriter) SetWriter(underline http.ResponseWriter) {
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
w.ResponseWriter = underline
|
2017-01-02 20:20:17 +01:00
|
|
|
}
|
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// EndResponse is the last function which is called right before the server sent the final response.
|
2017-01-02 20:20:17 +01:00
|
|
|
//
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// Here is the place which we can make the last checks or do a cleanup.
|
|
|
|
func (w *responseWriter) EndResponse() {
|
|
|
|
releaseResponseWriter(w)
|
2017-01-04 14:16:53 +01:00
|
|
|
}
|
|
|
|
|
2020-06-14 07:09:42 +02:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2017-10-09 14:26:46 +02:00
|
|
|
// 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) {
|
|
|
|
if n >= NoWritten && n <= StatusCodeWritten {
|
|
|
|
w.written = n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// Written should returns the total length of bytes that were being written to the client.
|
2017-07-10 17:32:42 +02:00
|
|
|
// In addition iris provides some variables to help low-level actions:
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// NoWritten, means that nothing were written yet and the response writer is still live.
|
|
|
|
// StatusCodeWritten, means that status code were written but no other bytes are written to the client, response writer may closed.
|
|
|
|
// > 0 means that the reply was written and it's the total number of bytes were written.
|
|
|
|
func (w *responseWriter) Written() int {
|
|
|
|
return w.written
|
|
|
|
}
|
|
|
|
|
|
|
|
// WriteHeader sends an HTTP response header with status code.
|
|
|
|
// If WriteHeader is not called explicitly, the first call to Write
|
|
|
|
// will trigger an implicit WriteHeader(http.StatusOK).
|
|
|
|
// Thus explicit calls to WriteHeader are mainly used to
|
|
|
|
// send error codes.
|
|
|
|
func (w *responseWriter) WriteHeader(statusCode int) {
|
|
|
|
w.statusCode = statusCode
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *responseWriter) tryWriteHeader() {
|
|
|
|
if w.written == NoWritten { // before write, once.
|
|
|
|
w.written = StatusCodeWritten
|
|
|
|
w.ResponseWriter.WriteHeader(w.statusCode)
|
|
|
|
}
|
2017-01-04 14:16:53 +01:00
|
|
|
}
|
|
|
|
|
2019-02-23 06:23:10 +01:00
|
|
|
// IsHijacked reports whether this response writer's connection is hijacked.
|
|
|
|
func (w *responseWriter) IsHijacked() bool {
|
|
|
|
// Note:
|
|
|
|
// A zero-byte `ResponseWriter.Write` on a hijacked connection will
|
|
|
|
// return `http.ErrHijacked` without any other side effects.
|
|
|
|
_, err := w.ResponseWriter.Write(nil)
|
|
|
|
return err == http.ErrHijacked
|
|
|
|
}
|
|
|
|
|
2017-01-04 14:16:53 +01:00
|
|
|
// Write writes to the client
|
2017-01-02 20:20:17 +01:00
|
|
|
// If WriteHeader has not yet been called, Write calls
|
|
|
|
// WriteHeader(http.StatusOK) before writing the data. If the Header
|
|
|
|
// does not contain a Content-Type line, Write adds a Content-Type set
|
|
|
|
// to the result of passing the initial 512 bytes of written data to
|
|
|
|
// DetectContentType.
|
|
|
|
//
|
|
|
|
// Depending on the HTTP protocol version and the client, calling
|
|
|
|
// Write or WriteHeader may prevent future reads on the
|
|
|
|
// Request.Body. For HTTP/1.x requests, handlers should read any
|
|
|
|
// needed request body data before writing the response. Once the
|
|
|
|
// headers have been flushed (due to either an explicit Flusher.Flush
|
|
|
|
// call or writing enough data to trigger a flush), the request body
|
|
|
|
// may be unavailable. For HTTP/2 requests, the Go HTTP server permits
|
|
|
|
// handlers to continue to read the request body while concurrently
|
|
|
|
// writing the response. However, such behavior may not be supported
|
|
|
|
// by all HTTP/2 clients. Handlers should read before writing if
|
|
|
|
// possible to maximize compatibility.
|
2017-01-04 14:16:53 +01:00
|
|
|
func (w *responseWriter) Write(contents []byte) (int, error) {
|
|
|
|
w.tryWriteHeader()
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
n, err := w.ResponseWriter.Write(contents)
|
|
|
|
w.written += n
|
|
|
|
return n, err
|
2017-01-02 20:20:17 +01:00
|
|
|
}
|
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// StatusCode returns the status code header value
|
|
|
|
func (w *responseWriter) StatusCode() int {
|
|
|
|
return w.statusCode
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *responseWriter) GetBeforeFlush() func() {
|
|
|
|
return w.beforeFlush
|
2017-01-02 20:20:17 +01:00
|
|
|
}
|
|
|
|
|
2017-01-04 14:16:53 +01:00
|
|
|
// SetBeforeFlush registers the unique callback which called exactly before the response is flushed to the client
|
|
|
|
func (w *responseWriter) SetBeforeFlush(cb func()) {
|
|
|
|
w.beforeFlush = cb
|
|
|
|
}
|
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
func (w *responseWriter) FlushResponse() {
|
2017-01-04 14:16:53 +01:00
|
|
|
if w.beforeFlush != nil {
|
|
|
|
w.beforeFlush()
|
|
|
|
}
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
|
2017-01-04 14:16:53 +01:00
|
|
|
w.tryWriteHeader()
|
|
|
|
}
|
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// Clone returns a clone of this response writer
|
|
|
|
// it copies the header, status code, headers and the beforeFlush finally returns a new ResponseRecorder.
|
|
|
|
func (w *responseWriter) Clone() ResponseWriter {
|
|
|
|
wc := &responseWriter{}
|
|
|
|
wc.ResponseWriter = w.ResponseWriter
|
|
|
|
wc.statusCode = w.statusCode
|
|
|
|
wc.beforeFlush = w.beforeFlush
|
|
|
|
wc.written = w.written
|
|
|
|
return wc
|
2017-01-04 14:16:53 +01:00
|
|
|
}
|
|
|
|
|
2020-07-30 19:13:59 +02:00
|
|
|
// CopyTo writes a response writer (temp: status code, headers and body) to another response writer.
|
|
|
|
func (w *responseWriter) CopyTo(to ResponseWriter) {
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// set the status code, failure status code are first class
|
|
|
|
if w.statusCode >= 400 {
|
|
|
|
to.WriteHeader(w.statusCode)
|
|
|
|
}
|
2017-01-02 20:20:17 +01:00
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// append the headers
|
2023-08-21 19:12:22 +02:00
|
|
|
for k, values := range w.Header() {
|
|
|
|
for _, v := range values {
|
|
|
|
if to.Header().Get(v) == "" {
|
|
|
|
to.Header().Add(k, v)
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// the body is not copied, this writer doesn't support recording
|
2017-01-02 20:20:17 +01:00
|
|
|
}
|
|
|
|
|
2020-06-25 12:04:36 +02:00
|
|
|
// ErrHijackNotSupported is returned by the Hijack method to
|
|
|
|
// indicate that Hijack feature is not available.
|
|
|
|
var ErrHijackNotSupported = errors.New("hijack is not supported by this ResponseWriter")
|
|
|
|
|
2017-01-02 20:20:17 +01:00
|
|
|
// Hijack lets the caller take over the connection.
|
|
|
|
// After a call to Hijack(), the HTTP server library
|
|
|
|
// will not do anything else with the connection.
|
|
|
|
//
|
|
|
|
// It becomes the caller's responsibility to manage
|
|
|
|
// and close the connection.
|
|
|
|
//
|
|
|
|
// The returned net.Conn may have read or write deadlines
|
|
|
|
// already set, depending on the configuration of the
|
|
|
|
// Server. It is the caller's responsibility to set
|
|
|
|
// or clear those deadlines as needed.
|
2017-01-04 14:16:53 +01:00
|
|
|
func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
2017-01-02 20:20:17 +01:00
|
|
|
if h, isHijacker := w.ResponseWriter.(http.Hijacker); isHijacker {
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
w.written = StatusCodeWritten
|
2017-01-02 20:20:17 +01:00
|
|
|
return h.Hijack()
|
|
|
|
}
|
|
|
|
|
2020-06-25 12:04:36 +02:00
|
|
|
return nil, nil, ErrHijackNotSupported
|
2017-01-02 20:20:17 +01:00
|
|
|
}
|
|
|
|
|
2018-08-02 16:46:35 +02:00
|
|
|
// Flusher indicates if `Flush` is supported by the client.
|
|
|
|
//
|
|
|
|
// The default HTTP/1.x and HTTP/2 ResponseWriter implementations
|
|
|
|
// support Flusher, but ResponseWriter wrappers may not. Handlers
|
|
|
|
// should always test for this ability at runtime.
|
|
|
|
//
|
|
|
|
// Note that even for ResponseWriters that support Flush,
|
|
|
|
// if the client is connected through an HTTP proxy,
|
|
|
|
// the buffered data may not reach the client until the response
|
|
|
|
// completes.
|
|
|
|
func (w *responseWriter) Flusher() (http.Flusher, bool) {
|
|
|
|
flusher, canFlush := w.ResponseWriter.(http.Flusher)
|
|
|
|
return flusher, canFlush
|
|
|
|
}
|
|
|
|
|
2017-01-02 20:20:17 +01:00
|
|
|
// Flush sends any buffered data to the client.
|
2017-01-04 14:16:53 +01:00
|
|
|
func (w *responseWriter) Flush() {
|
2018-08-02 16:46:35 +02:00
|
|
|
if flusher, ok := w.Flusher(); ok {
|
2021-01-27 03:09:46 +01:00
|
|
|
// Flow: WriteHeader -> Flush -> Write -> Write -> Write....
|
|
|
|
w.tryWriteHeader()
|
|
|
|
|
2018-08-02 16:46:35 +02:00
|
|
|
flusher.Flush()
|
2017-01-02 20:20:17 +01:00
|
|
|
}
|
|
|
|
}
|