mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
parent
08e23c1e55
commit
04cdefb2a6
@ -10,7 +10,7 @@ type (
|
||||
// response references, path parameters, data and registered handler.
|
||||
Context struct {
|
||||
Request *http.Request
|
||||
Response *response
|
||||
Response *Response
|
||||
pnames []string
|
||||
pvalues []string
|
||||
store store
|
||||
|
@ -27,7 +27,7 @@ func TestContext(t *testing.T) {
|
||||
b, _ := json.Marshal(u1)
|
||||
r, _ := http.NewRequest(POST, "/users/1", bytes.NewReader(b))
|
||||
c := &Context{
|
||||
Response: &response{Writer: httptest.NewRecorder()},
|
||||
Response: &Response{Writer: httptest.NewRecorder()},
|
||||
Request: r,
|
||||
pvalues: make([]string, 5),
|
||||
store: make(store),
|
||||
|
2
echo.go
2
echo.go
@ -114,7 +114,7 @@ func New() (e *Echo) {
|
||||
e.Router = NewRouter(e)
|
||||
e.pool.New = func() interface{} {
|
||||
return &Context{
|
||||
Response: &response{},
|
||||
Response: &Response{},
|
||||
pnames: make([]string, e.maxParam),
|
||||
pvalues: make([]string, e.maxParam),
|
||||
store: make(store),
|
||||
|
14
response.go
14
response.go
@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
response struct {
|
||||
Response struct {
|
||||
Writer http.ResponseWriter
|
||||
status int
|
||||
size int
|
||||
@ -16,11 +16,11 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (r *response) Header() http.Header {
|
||||
func (r *Response) Header() http.Header {
|
||||
return r.Writer.Header()
|
||||
}
|
||||
|
||||
func (r *response) WriteHeader(n int) {
|
||||
func (r *Response) WriteHeader(n int) {
|
||||
if r.committed {
|
||||
// TODO: Warning
|
||||
log.Printf("echo: %s", color.Yellow("response already committed"))
|
||||
@ -31,21 +31,21 @@ func (r *response) WriteHeader(n int) {
|
||||
r.committed = true
|
||||
}
|
||||
|
||||
func (r *response) Write(b []byte) (n int, err error) {
|
||||
func (r *Response) Write(b []byte) (n int, err error) {
|
||||
n, err = r.Writer.Write(b)
|
||||
r.size += n
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (r *response) Status() int {
|
||||
func (r *Response) Status() int {
|
||||
return r.status
|
||||
}
|
||||
|
||||
func (r *response) Size() int {
|
||||
func (r *Response) Size() int {
|
||||
return r.size
|
||||
}
|
||||
|
||||
func (r *response) reset(w http.ResponseWriter) {
|
||||
func (r *Response) reset(w http.ResponseWriter) {
|
||||
r.Writer = w
|
||||
r.committed = false
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func TestResponse(t *testing.T) {
|
||||
r := &response{Writer: httptest.NewRecorder()}
|
||||
r := &Response{Writer: httptest.NewRecorder()}
|
||||
|
||||
// Header
|
||||
if r.Header() == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user