all repos — legit @ acac8d47d0dd4bab02274f750d22937044bee988

web frontend for git, written in go

routes/handler.go (view raw)

 1package routes
 2
 3import (
 4	"net/http"
 5
 6	"git.icyphox.sh/legit/config"
 7)
 8
 9// Checks for gitprotocol-http(5) specific smells; if found, passes
10// the request on to the git http service, else render the web frontend.
11func (d *deps) Multiplex(w http.ResponseWriter, r *http.Request) {
12	path := r.PathValue("rest")
13
14	if r.URL.RawQuery == "service=git-receive-pack" {
15		w.WriteHeader(http.StatusBadRequest)
16		w.Write([]byte("no pushing allowed!"))
17		return
18	}
19
20	if path == "info/refs" &&
21		r.URL.RawQuery == "service=git-upload-pack" &&
22		r.Method == "GET" {
23		d.InfoRefs(w, r)
24	} else if path == "git-upload-pack" && r.Method == "POST" {
25		d.UploadPack(w, r)
26	} else if r.Method == "GET" {
27		d.RepoIndex(w, r)
28	}
29}
30
31func Handlers(c *config.Config) *http.ServeMux {
32	mux := http.NewServeMux()
33	d := deps{c}
34
35	mux.HandleFunc("GET /", d.Index)
36	mux.HandleFunc("GET /static/{file}", d.ServeStatic)
37	mux.HandleFunc("GET /{name}", d.Multiplex)
38	mux.HandleFunc("POST /{name}", d.Multiplex)
39	mux.HandleFunc("GET /{name}/tree/{ref}/{rest...}", d.RepoTree)
40	mux.HandleFunc("GET /{name}/blob/{ref}/{rest...}", d.FileContent)
41	mux.HandleFunc("GET /{name}/log/{ref}", d.Log)
42	mux.HandleFunc("GET /{name}/archive/{file}", d.Archive)
43	mux.HandleFunc("GET /{name}/commit/{ref}", d.Diff)
44	mux.HandleFunc("GET /{name}/refs/{$}", d.Refs)
45	mux.HandleFunc("GET /{name}/{rest...}", d.Multiplex)
46	mux.HandleFunc("POST /{name}/{rest...}", d.Multiplex)
47
48	return mux
49}