Skip to content

Commit

Permalink
use xid. xid is good performance
Browse files Browse the repository at this point in the history
  • Loading branch information
kazeburo committed Jun 11, 2019
1 parent 1ae5552 commit 6e09573
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
17 changes: 4 additions & 13 deletions proxy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"sync"

"github.com/kazeburo/chocon/upstream"
"github.com/renstrom/shortuuid"
"github.com/rs/xid"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -65,7 +65,7 @@ func New(transport *http.RoundTripper, version string, upstream *upstream.Upstre
func (proxy *Proxy) ServeHTTP(writer http.ResponseWriter, originalRequest *http.Request) {
proxyID := originalRequest.Header.Get(proxyIDHeader)
if proxyID == "" {
proxyID = shortuuid.New()
proxyID = xid.New().String()
originalRequest.Header.Set(proxyIDHeader, proxyID)
}
writer.Header().Set(proxyIDHeader, proxyID)
Expand Down Expand Up @@ -129,9 +129,8 @@ func (proxy *Proxy) ServeHTTP(writer http.ResponseWriter, originalRequest *http.

buf := pool.Get().([]byte)
defer func() {
defer response.Body.Close()
// Ensure a response body from upstream will be always closed.
defer pool.Put(buf)
response.Body.Close()
pool.Put(buf)
}()

// Copy all header fields.
Expand Down Expand Up @@ -216,13 +215,5 @@ func (proxy *Proxy) copyRequest(originalRequest *http.Request) *http.Request {
sv = sv[n:]
}

// Append this machine's host name into X-Forwarded-For.
// if requestHost, _, err := net.SplitHostPort(originalRequest.RemoteAddr); err == nil {
// if originalValues, ok := proxyRequest.Header["X-Forwarded-For"]; ok {
// requestHost = strings.Join(originalValues, ", ") + ", " + requestHost
// }
// proxyRequest.Header.Set("X-Forwarded-For", requestHost)
// }

return proxyRequest
}
1 change: 0 additions & 1 deletion upstream/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ func (u *Upstream) Get() (string, *IPwc, error) {
ipwc := &IPwc{
ip: u.ipwcs[0].ip,
version: u.ipwcs[0].version,
busy: 0, // dummy
}
return h, ipwc, nil
}
Expand Down

0 comments on commit 6e09573

Please sign in to comment.