@@ -67,62 +67,62 @@ const (
6767 hostConfigKey contextKey = "host config"
6868)
6969
70- // director is a custom internal function for altering a http.Request
71- func director (o * options ) func (* http. Request ) {
72- return func (r * http. Request ) {
73- ctx := r .Context ()
70+ // rewriter is a custom internal function for altering a http.Request
71+ func rewriter (o * options ) func (* httputil. ProxyRequest ) {
72+ return func (r * httputil. ProxyRequest ) {
73+ ctx := r .Out . Context ()
7474 ctx , span := otel .GetTracerProvider ().Tracer ("" ).Start (ctx , "x.proxy" )
7575 defer span .End ()
7676
77- c , err := o .getHostConfig (r )
77+ c , err := o .getHostConfig (r . Out )
7878 if err != nil {
79- o .onReqError (r , err )
79+ o .onReqError (r . Out , err )
8080 return
8181 }
8282
83- if forwardedProto := r .Header .Get ("X-Forwarded-Proto" ); forwardedProto != "" {
83+ if forwardedProto := r .In . Header .Get ("X-Forwarded-Proto" ); forwardedProto != "" {
8484 c .originalScheme = forwardedProto
85- } else if r .TLS == nil {
85+ } else if r .Out . TLS == nil {
8686 c .originalScheme = "http"
8787 } else {
8888 c .originalScheme = "https"
8989 }
90- if forwardedHost := r .Header .Get ("X-Forwarded-Host" ); forwardedHost != "" {
90+ if forwardedHost := r .In . Header .Get ("X-Forwarded-Host" ); forwardedHost != "" {
9191 c .originalHost = forwardedHost
9292 } else {
93- c .originalHost = r .Host
93+ c .originalHost = r .In . Host
9494 }
9595
96- * r = * r .WithContext (context .WithValue (ctx , hostConfigKey , c ))
97- headerRequestRewrite (r , c )
96+ * r . Out = * r . Out .WithContext (context .WithValue (ctx , hostConfigKey , c ))
97+ headerRequestRewrite (r . Out , c )
9898
9999 var body []byte
100100 var cb * compressableBody
101101
102- if r .ContentLength != 0 {
103- body , cb , err = readBody (r .Header , r .Body )
102+ if r .Out . ContentLength != 0 {
103+ body , cb , err = readBody (r .Out . Header , r . Out .Body )
104104 if err != nil {
105- o .onReqError (r , err )
105+ o .onReqError (r . Out , err )
106106 return
107107 }
108108 }
109109
110110 for _ , m := range o .reqMiddlewares {
111- if body , err = m (r , c , body ); err != nil {
112- o .onReqError (r , err )
111+ if body , err = m (r . Out , c , body ); err != nil {
112+ o .onReqError (r . Out , err )
113113 return
114114 }
115115 }
116116
117117 n , err := cb .Write (body )
118118 if err != nil {
119- o .onReqError (r , err )
119+ o .onReqError (r . Out , err )
120120 return
121121 }
122122
123- r .Header .Del ("Content-Length" )
124- r .ContentLength = int64 (n )
125- r .Body = cb
123+ r .Out . Header .Del ("Content-Length" )
124+ r .Out . ContentLength = int64 (n )
125+ r .Out . Body = cb
126126 }
127127}
128128
@@ -252,7 +252,7 @@ func New(hostMapper HostMapper, opts ...Options) http.Handler {
252252 }
253253
254254 rp := & httputil.ReverseProxy {
255- Director : director (o ),
255+ Rewrite : rewriter (o ),
256256 ModifyResponse : modifyResponse (o ),
257257 Transport : o .transport ,
258258 ErrorHandler : o .errHandler ,
0 commit comments