all repos — legit @ 5ba4a5747fdd66ac0ddf5742cf4c275b808df36d

Unnamed repository; edit this file 'description' to name the repository.

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	switch {
21	case path == "info/refs" &&
22		r.URL.RawQuery == "service=git-upload-pack" &&
23		r.Method == http.MethodGet:
24		d.InfoRefs(w, r)
25	case path == "git-upload-pack" && r.Method == http.MethodPost:
26		d.UploadPack(w, r)
27	case r.Method == http.MethodGet:
28		d.RepoIndex(w, r)
29	}
30}
31
32func Handlers(c *config.Config) *http.ServeMux {
33	mux := http.NewServeMux()
34	d := deps{c}
35
36	mux.HandleFunc("GET /", d.Index)
37	mux.HandleFunc("GET /static/{file}", d.ServeStatic)
38	mux.HandleFunc("GET /{name}", d.Multiplex)
39	mux.HandleFunc("POST /{name}", d.Multiplex)
40	mux.HandleFunc("GET /{name}/tree/{ref}/{rest...}", d.RepoTree)
41	mux.HandleFunc("GET /{name}/blob/{ref}/{rest...}", d.FileContent)
42	mux.HandleFunc("GET /{name}/log/{ref}", d.Log)
43	mux.HandleFunc("GET /{name}/archive/{file}", d.Archive)
44	mux.HandleFunc("GET /{name}/commit/{ref}", d.Diff)
45	mux.HandleFunc("GET /{name}/refs/{$}", d.Refs)
46	mux.HandleFunc("GET /{name}/{rest...}", d.Multiplex)
47	mux.HandleFunc("POST /{name}/{rest...}", d.Multiplex)
48
49	return mux
50}