Commit e0a71fd0 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Clean up error handling and control flow

parent 31b056a9
...@@ -67,8 +67,7 @@ func git_handler(w http.ResponseWriter, r *http.Request) { ...@@ -67,8 +67,7 @@ func git_handler(w http.ResponseWriter, r *http.Request) {
return return
} }
} }
log.Print("Reached end of dispatch for loop") http.Error(w, "Not found", 404)
w.WriteHeader(404)
} }
func do_auth_request(r *http.Request) (*http.Response, error) { func do_auth_request(r *http.Request) (*http.Response, error) {
...@@ -105,17 +104,17 @@ func handle_get_info_refs(user string, _ string, path string, w http.ResponseWri ...@@ -105,17 +104,17 @@ func handle_get_info_refs(user string, _ string, path string, w http.ResponseWri
} }
w.Header().Add("Content-Type", fmt.Sprintf("application/x-%s-advertisement", rpc)) w.Header().Add("Content-Type", fmt.Sprintf("application/x-%s-advertisement", rpc))
no_cache(w) no_cache(w)
w.WriteHeader(200)
fmt.Fprintf(w, "%s0000", pkt_line(fmt.Sprintf("# service=%s\n", rpc))) fmt.Fprintf(w, "%s0000", pkt_line(fmt.Sprintf("# service=%s\n", rpc)))
if _, err := io.Copy(w, stdout); err != nil { if _, err := io.Copy(w, stdout); err != nil {
fail_500(w, err) panic(err) // No point in sending 500 to the client
return
} }
if err := cmd.Wait(); err != nil { if err := cmd.Wait(); err != nil {
fail_500(w, err) panic(err) // No point in sending 500 to the client
return
} }
case "": case "":
log.Print("dumb info refs") // The 'dumb' Git HTTP protocol is not supported
http.Error(w, "Not found", 404)
} }
} }
...@@ -147,20 +146,20 @@ func handle_post_rpc(user string, rpc string, path string, w http.ResponseWriter ...@@ -147,20 +146,20 @@ func handle_post_rpc(user string, rpc string, path string, w http.ResponseWriter
fail_500(w, err) fail_500(w, err)
return return
} }
w.Header().Add("Content-Type", fmt.Sprintf("application/x-%s-result", rpc))
no_cache(w)
if _, err := io.Copy(stdin, body); err != nil { if _, err := io.Copy(stdin, body); err != nil {
fail_500(w, err) fail_500(w, err)
return return
} }
stdin.Close() stdin.Close()
w.Header().Add("Content-Type", fmt.Sprintf("application/x-%s-result", rpc))
no_cache(w)
w.WriteHeader(200)
if _, err := io.Copy(w, stdout); err != nil { if _, err := io.Copy(w, stdout); err != nil {
fail_500(w, err) panic(err) // No point in sending 500 to the client
return
} }
if err := cmd.Wait(); err != nil { if err := cmd.Wait(); err != nil {
fail_500(w, err) panic(err) // No point in sending 500 to the client
return
} }
} }
...@@ -169,7 +168,7 @@ func pkt_line(s string) string { ...@@ -169,7 +168,7 @@ func pkt_line(s string) string {
} }
func fail_500(w http.ResponseWriter, err error) { func fail_500(w http.ResponseWriter, err error) {
w.WriteHeader(500) http.Error(w, "Internal server error", 500)
log.Print(err) log.Print(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