Skip to content

Commit

Permalink
Implemented DisablePathNormalizing in PipelineClient (#977)
Browse files Browse the repository at this point in the history
  • Loading branch information
TwoAbove authored Feb 24, 2021
1 parent 0880335 commit a4b0703
Showing 1 changed file with 45 additions and 26 deletions.
71 changes: 45 additions & 26 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,15 @@ type PipelineClient struct {
// since unfortunately ipv6 remains broken in many networks worldwide :)
DialDualStack bool

// Path values are sent as-is without normalization
//
// Disabled path normalization may be useful for proxying incoming requests
// to servers that are expecting paths to be forwarded as-is.
//
// By default path values are normalized, i.e.
// extra slashes are removed, special characters are encoded.
DisablePathNormalizing bool

// Whether to use TLS (aka SSL or HTTPS) for host connections.
IsTLS bool

Expand Down Expand Up @@ -2189,19 +2198,20 @@ type PipelineClient struct {
type pipelineConnClient struct {
noCopy noCopy //nolint:unused,structcheck

Addr string
MaxPendingRequests int
MaxBatchDelay time.Duration
Dial DialFunc
DialDualStack bool
IsTLS bool
TLSConfig *tls.Config
MaxIdleConnDuration time.Duration
ReadBufferSize int
WriteBufferSize int
ReadTimeout time.Duration
WriteTimeout time.Duration
Logger Logger
Addr string
MaxPendingRequests int
MaxBatchDelay time.Duration
Dial DialFunc
DialDualStack bool
DisablePathNormalizing bool
IsTLS bool
TLSConfig *tls.Config
MaxIdleConnDuration time.Duration
ReadBufferSize int
WriteBufferSize int
ReadTimeout time.Duration
WriteTimeout time.Duration
Logger Logger

workPool sync.Pool

Expand Down Expand Up @@ -2275,6 +2285,10 @@ func (c *pipelineConnClient) DoDeadline(req *Request, resp *Response, deadline t
return ErrTimeout
}

if c.DisablePathNormalizing {
req.URI().DisablePathNormalizing = true
}

w := acquirePipelineWork(&c.workPool, timeout)
w.req = &w.reqCopy
w.resp = &w.respCopy
Expand Down Expand Up @@ -2332,6 +2346,10 @@ func (c *PipelineClient) Do(req *Request, resp *Response) error {
func (c *pipelineConnClient) Do(req *Request, resp *Response) error {
c.init()

if c.DisablePathNormalizing {
req.URI().DisablePathNormalizing = true
}

w := acquirePipelineWork(&c.workPool, 0)
w.req = req
if resp != nil {
Expand Down Expand Up @@ -2410,19 +2428,20 @@ func (c *PipelineClient) getConnClientUnlocked() *pipelineConnClient {

func (c *PipelineClient) newConnClient() *pipelineConnClient {
cc := &pipelineConnClient{
Addr: c.Addr,
MaxPendingRequests: c.MaxPendingRequests,
MaxBatchDelay: c.MaxBatchDelay,
Dial: c.Dial,
DialDualStack: c.DialDualStack,
IsTLS: c.IsTLS,
TLSConfig: c.TLSConfig,
MaxIdleConnDuration: c.MaxIdleConnDuration,
ReadBufferSize: c.ReadBufferSize,
WriteBufferSize: c.WriteBufferSize,
ReadTimeout: c.ReadTimeout,
WriteTimeout: c.WriteTimeout,
Logger: c.Logger,
Addr: c.Addr,
MaxPendingRequests: c.MaxPendingRequests,
MaxBatchDelay: c.MaxBatchDelay,
Dial: c.Dial,
DialDualStack: c.DialDualStack,
DisablePathNormalizing: c.DisablePathNormalizing,
IsTLS: c.IsTLS,
TLSConfig: c.TLSConfig,
MaxIdleConnDuration: c.MaxIdleConnDuration,
ReadBufferSize: c.ReadBufferSize,
WriteBufferSize: c.WriteBufferSize,
ReadTimeout: c.ReadTimeout,
WriteTimeout: c.WriteTimeout,
Logger: c.Logger,
}
c.connClients = append(c.connClients, cc)
return cc
Expand Down

0 comments on commit a4b0703

Please sign in to comment.