Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring httpContext & httpResponse make methods signature as same as interfaces declared. #416

Merged
merged 2 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/context/contexttest/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (c *MockedHTTPContext) ClientDisconnected() bool {
}

// OnFinish mocks the OnFinish function of HTTPContext
func (c *MockedHTTPContext) OnFinish(fn func()) {
func (c *MockedHTTPContext) OnFinish(fn context.FinishFunc) {
if c.MockedFinish != nil {
c.MockedOnFinish(fn)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/context/contexttest/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package contexttest

import (
"github.com/megaease/easegress/pkg/context"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -33,7 +34,7 @@ type MockedHTTPResponse struct {
MockedSetCookie func(cookie *http.Cookie)
MockedSetBody func(body io.Reader)
MockedBody func() io.Reader
MockedOnFlushBody func(func(body []byte, complete bool) (newBody []byte))
MockedOnFlushBody func(fn context.BodyFlushFunc)
MockedStd func() http.ResponseWriter
MockedSize func() uint64
}
Expand Down Expand Up @@ -84,7 +85,7 @@ func (r *MockedHTTPResponse) Body() io.Reader {
}

// OnFlushBody registers a callback function on flush body
func (r *MockedHTTPResponse) OnFlushBody(fn func(body []byte, complete bool) (newBody []byte)) {
func (r *MockedHTTPResponse) OnFlushBody(fn context.BodyFlushFunc) {
if r.MockedOnFlushBody != nil {
r.MockedOnFlushBody(fn)
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/context/httpcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ type (
Cancelled() bool
ClientDisconnected() bool

OnFinish(func()) // For setting final client statistics, etc.
AddTag(tag string) // For debug, log, etc.
OnFinish(FinishFunc) // For setting final client statistics, etc.
AddTag(tag string) // For debug, log, etc.

StatMetric() *httpstat.Metric

Expand Down Expand Up @@ -116,7 +116,7 @@ type (

SetBody(body io.Reader)
Body() io.Reader
OnFlushBody(func(body []byte, complete bool) (newBody []byte))
OnFlushBody(BodyFlushFunc)

Std() http.ResponseWriter

Expand All @@ -127,6 +127,10 @@ type (
// when HTTPContext is finishing.
FinishFunc = func()

// BodyFlushFunc is the type of function to be called back
// when body is flushing.
BodyFlushFunc = func(body []byte, complete bool) (newBody []byte)

httpContext struct {
mutex sync.Mutex

Expand Down
4 changes: 0 additions & 4 deletions pkg/context/httpresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ import (
var bodyFlushBuffSize = 8 * int64(os.Getpagesize())

type (
// BodyFlushFunc is the type of function to be called back
// when body is flushing.
BodyFlushFunc = func(body []byte, complete bool) (newBody []byte)

httpResponse struct {
stdr *http.Request
std http.ResponseWriter
Expand Down