Commit b35b91e1 authored by Jacob Vosmaer's avatar Jacob Vosmaer

More changes

parent b45d281f
package main package main
import ( import (
"bytes"
"compress/gzip" "compress/gzip"
"flag" "flag"
"fmt" "fmt"
...@@ -41,24 +40,24 @@ func main() { ...@@ -41,24 +40,24 @@ func main() {
} }
func git_handler(w http.ResponseWriter, r *http.Request) { func git_handler(w http.ResponseWriter, r *http.Request) {
var user string
log.Print(r.Method, " ", r.URL) log.Print(r.Method, " ", r.URL)
for _, g := range git_handlers { for _, g := range git_handlers {
m := g.regexp.FindStringSubmatch(r.URL.Path) path_match := g.regexp.FindStringSubmatch(r.URL.Path)
if r.Method == g.method && m != nil { if r.Method == g.method && path_match != nil {
response := validation_request(r) auth_response := do_auth_request(r)
if response.StatusCode != 200 { if auth_response.StatusCode != 200 {
w.Header().Set("WWW-Authenticate", response.Header.Get("WWW-Authenticate")) for k, v := range auth_response.Header {
w.WriteHeader(response.StatusCode) w.Header()[k] = v
}
w.WriteHeader(auth_response.StatusCode)
io.Copy(w, auth_response.Body)
return return
} }
buf := new(bytes.Buffer) if _, err := fmt.Fscan(auth_response.Body, user); err != nil {
_, err := buf.ReadFrom(response.Body)
if err != nil {
fail_500(w, err) fail_500(w, err)
return
} }
user := buf.String() 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, m[1]), w, r)
return return
} }
} }
...@@ -66,21 +65,19 @@ func git_handler(w http.ResponseWriter, r *http.Request) { ...@@ -66,21 +65,19 @@ func git_handler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404) w.WriteHeader(404)
} }
func validation_request(r *http.Request) *http.Response { func do_auth_request(r *http.Request) *http.Response {
var err error var err error
result := &http.Response{} result := &http.Response{}
url := fmt.Sprintf("http://localhost:8080%s", r.URL.RequestURI()) url := fmt.Sprintf("http://localhost:8080%s", r.URL.RequestURI())
vreq, err := http.NewRequest(r.Method, url, nil) auth_req, err := http.NewRequest(r.Method, url, nil)
if err != nil { if err != nil {
result.StatusCode = 500 result.StatusCode = 500
return result return result
} }
for k, v := range r.Header { for k, v := range r.Header {
vreq.Header[k] = v auth_req.Header[k] = v
} }
user, password, _ := r.BasicAuth() result, err = http_client.Do(auth_req)
vreq.SetBasicAuth(user, password)
result, err = http_client.Do(vreq)
if err != nil { if err != nil {
result.StatusCode = 500 result.StatusCode = 500
return result return result
......
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