Commit 299ebeea authored by Jacob Vosmaer's avatar Jacob Vosmaer

Improve auth request error handling

parent 4d3dd52c
...@@ -46,7 +46,11 @@ func git_handler(w http.ResponseWriter, r *http.Request) { ...@@ -46,7 +46,11 @@ func git_handler(w http.ResponseWriter, r *http.Request) {
for _, g := range git_handlers { for _, g := range git_handlers {
path_match := g.regexp.FindStringSubmatch(r.URL.Path) path_match := g.regexp.FindStringSubmatch(r.URL.Path)
if r.Method == g.method && path_match != nil { if r.Method == g.method && path_match != nil {
auth_response := do_auth_request(r) auth_response, err := do_auth_request(r)
if err != nil {
fail_500(w, err)
return
}
if auth_response.StatusCode != 200 { if auth_response.StatusCode != 200 {
for k, v := range auth_response.Header { for k, v := range auth_response.Header {
w.Header()[k] = v w.Header()[k] = v
...@@ -55,8 +59,9 @@ func git_handler(w http.ResponseWriter, r *http.Request) { ...@@ -55,8 +59,9 @@ func git_handler(w http.ResponseWriter, r *http.Request) {
io.Copy(w, auth_response.Body) io.Copy(w, auth_response.Body)
return return
} }
if _, err := fmt.Fscan(auth_response.Body, user); err != nil { if _, err := fmt.Fscan(auth_response.Body, &user); err != nil {
fail_500(w, err) fail_500(w, err)
return
} }
g.handle_func(user, g.rpc, path.Join(repo_root, path_match[1]), w, r) g.handle_func(user, g.rpc, path.Join(repo_root, path_match[1]), w, r)
return return
...@@ -66,21 +71,21 @@ func git_handler(w http.ResponseWriter, r *http.Request) { ...@@ -66,21 +71,21 @@ func git_handler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404) w.WriteHeader(404)
} }
func do_auth_request(r *http.Request) *http.Response { func do_auth_request(r *http.Request) (*http.Response, error) {
var err error var err error
url := fmt.Sprintf("%s%s", *auth_backend, r.URL.RequestURI()) url := fmt.Sprintf("%s%s", *auth_backend, r.URL.RequestURI())
auth_req, err := http.NewRequest(r.Method, url, nil) auth_req, err := http.NewRequest(r.Method, url, nil)
if err != nil { if err != nil {
return &http.Response{StatusCode: 500} return nil, err
} }
for k, v := range r.Header { for k, v := range r.Header {
auth_req.Header[k] = v auth_req.Header[k] = v
} }
result, err := http_client.Do(auth_req) result, err := http_client.Do(auth_req)
if err != nil { if err != nil {
return &http.Response{StatusCode: 500} return nil, err
} }
return result return nil, err
} }
func handle_get_info_refs(user string, _ string, path string, w http.ResponseWriter, r *http.Request) { func handle_get_info_refs(user string, _ string, path string, w http.ResponseWriter, r *http.Request) {
......
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