Skip to content

Commit

Permalink
Merge pull request #312 from mark4z/remove_writer
Browse files Browse the repository at this point in the history
  • Loading branch information
mark4z authored Dec 6, 2021
2 parents 53413df + 50dde71 commit aa3a55c
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 175 deletions.
1 change: 0 additions & 1 deletion pkg/common/http/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func (hcm *HttpConnectionManager) OnData(hc *pch.HttpContext) error {
func (hcm *HttpConnectionManager) handleHTTPRequest(c *pch.HttpContext) {
if len(c.Filters) > 0 {
c.Next()
c.WriteHeaderNow()
return
}
// TODO redirect
Expand Down
21 changes: 2 additions & 19 deletions pkg/context/http/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ type HttpContext struct {
Route *model.RouteAction
Api *router.API

Request *http.Request
writermem responseWriter
Writer ResponseWriter
Request *http.Request
Writer http.ResponseWriter
}

type (
Expand All @@ -89,7 +88,6 @@ func (hc *HttpContext) Next() {

// Reset reset http context
func (hc *HttpContext) Reset() {
hc.Writer = &hc.writermem
hc.Ctx = nil
hc.Index = -1
hc.Filters = []FilterFunc{}
Expand All @@ -116,21 +114,11 @@ func (hc *HttpContext) GetRouteEntry() *model.RouteAction {
return hc.Route
}

// StatusCode get header status code
func (hc *HttpContext) StatusCode() int {
return hc.Writer.Status()
}

// Write write body data
func (hc *HttpContext) Write(b []byte) (int, error) {
return hc.Writer.Write(b)
}

// WriteHeaderNow write header now
func (hc *HttpContext) WriteHeaderNow() {
hc.writermem.WriteHeaderNow()
}

// WriteWithStatus status must set first
func (hc *HttpContext) WriteWithStatus(code int, b []byte) (int, error) {
hc.Writer.WriteHeader(code)
Expand Down Expand Up @@ -245,11 +233,6 @@ func (hc *HttpContext) doWrite(h map[string]string, code int, d interface{}) {
}
}

// ResetWritermen reset writermen
func (hc *HttpContext) ResetWritermen(w http.ResponseWriter) {
hc.writermem.reset(w)
}

// API sets the API to http context
func (hc *HttpContext) API(api router.API) {
hc.Timeout = api.Timeout
Expand Down
147 changes: 0 additions & 147 deletions pkg/context/http/writer.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/context/mock/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func GetMockHTTPContext(r *http.Request, fc ...filter.HttpFilter) *contexthttp.H
}

w := mockWriter{header: map[string][]string{}}
result.ResetWritermen(&w)
result.Writer = &w
result.Reset()
result.Ctx = context.Background()
for i := range fc {
Expand Down
3 changes: 2 additions & 1 deletion pkg/filter/metric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ func (f *Filter) Handle(c *http.HttpContext) {
atomic.AddInt64(&totalElapsed, latency.Nanoseconds())
atomic.AddInt64(&totalCount, 1)

logger.Infof("[dubbo go server] [UPSTREAM] receive request | %d | %s | %s | %s | ", c.StatusCode(), latency, c.GetMethod(), c.GetUrl())
//todo status code
logger.Infof("[dubbo go server] [UPSTREAM] receive request | %d | %s | %s | %s | ", nil, latency, c.GetMethod(), c.GetUrl())
}

func registerOtelMetric() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (s *DefaultHttpWorker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer s.pool.Put(hc)

hc.Request = r
hc.ResetWritermen(w)
hc.Writer = w
hc.Reset()

// now only one filter http_connection_manager, so just get it and call
Expand Down
5 changes: 0 additions & 5 deletions pkg/server/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

package server

import (
"net/http/httptest"
)

import (
ctxHttp "github.com/apache/dubbo-go-pixiu/pkg/context/http"
"github.com/apache/dubbo-go-pixiu/pkg/model"
Expand All @@ -45,7 +41,6 @@ func getTestContext() *ctxHttp.HttpContext {
Listener: l.cfg,
Filters: []ctxHttp.FilterFunc{},
}
hc.ResetWritermen(httptest.NewRecorder())
hc.Reset()
return hc
}

0 comments on commit aa3a55c

Please sign in to comment.