Commit bc64cb9b authored by Nick Thomas's avatar Nick Thomas

Merge branch 'api-remove-unused-body' into 'master'

Remove unused 'body' argument

See merge request gitlab-org/gitlab-workhorse!315
parents 11c8ab89 cacfe84c
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
...@@ -170,34 +169,30 @@ func rebaseUrl(url *url.URL, onto *url.URL, suffix string) *url.URL { ...@@ -170,34 +169,30 @@ func rebaseUrl(url *url.URL, onto *url.URL, suffix string) *url.URL {
return &newUrl return &newUrl
} }
func (api *API) newRequest(r *http.Request, body io.Reader, suffix string) (*http.Request, error) { func (api *API) newRequest(r *http.Request, suffix string) (*http.Request, error) {
authReq := &http.Request{ authReq := &http.Request{
Method: r.Method, Method: r.Method,
URL: rebaseUrl(r.URL, api.URL, suffix), URL: rebaseUrl(r.URL, api.URL, suffix),
Header: helper.HeaderClone(r.Header), Header: helper.HeaderClone(r.Header),
} }
if body != nil {
authReq.Body = ioutil.NopCloser(body)
}
// Clean some headers when issuing a new request without body // Clean some headers when issuing a new request without body
if body == nil { authReq.Header.Del("Content-Type")
authReq.Header.Del("Content-Type") authReq.Header.Del("Content-Encoding")
authReq.Header.Del("Content-Encoding") authReq.Header.Del("Content-Length")
authReq.Header.Del("Content-Length") authReq.Header.Del("Content-Disposition")
authReq.Header.Del("Content-Disposition") authReq.Header.Del("Accept-Encoding")
authReq.Header.Del("Accept-Encoding")
// Hop-by-hop headers. These are removed when sent to the backend.
// Hop-by-hop headers. These are removed when sent to the backend. // http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html authReq.Header.Del("Transfer-Encoding")
authReq.Header.Del("Transfer-Encoding") authReq.Header.Del("Connection")
authReq.Header.Del("Connection") authReq.Header.Del("Keep-Alive")
authReq.Header.Del("Keep-Alive") authReq.Header.Del("Proxy-Authenticate")
authReq.Header.Del("Proxy-Authenticate") authReq.Header.Del("Proxy-Authorization")
authReq.Header.Del("Proxy-Authorization") authReq.Header.Del("Te")
authReq.Header.Del("Te") authReq.Header.Del("Trailers")
authReq.Header.Del("Trailers") authReq.Header.Del("Upgrade")
authReq.Header.Del("Upgrade")
}
// Also forward the Host header, which is excluded from the Header map by the http libary. // Also forward the Host header, which is excluded from the Header map by the http libary.
// This allows the Host header received by the backend to be consistent with other // This allows the Host header received by the backend to be consistent with other
...@@ -227,7 +222,7 @@ func (api *API) newRequest(r *http.Request, body io.Reader, suffix string) (*htt ...@@ -227,7 +222,7 @@ func (api *API) newRequest(r *http.Request, body io.Reader, suffix string) (*htt
// //
// authResponse will only be present if the authorization check was successful // authResponse will only be present if the authorization check was successful
func (api *API) PreAuthorize(suffix string, r *http.Request) (httpResponse *http.Response, authResponse *Response, outErr error) { func (api *API) PreAuthorize(suffix string, r *http.Request) (httpResponse *http.Response, authResponse *Response, outErr error) {
authReq, err := api.newRequest(r, nil, suffix) authReq, err := api.newRequest(r, suffix)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("preAuthorizeHandler newUpstreamRequest: %v", err) return nil, nil, fmt.Errorf("preAuthorizeHandler newUpstreamRequest: %v", err)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment