mirror of https://github.com/perkeep/perkeep.git
Put gitweb.cgi at /code/ on the website.
This commit is contained in:
parent
8b13da6ec0
commit
d5192826d3
|
@ -19,6 +19,8 @@ const defaultAddr = ":31798" // default webserver address
|
|||
var (
|
||||
httpAddr = flag.String("http", defaultAddr, "HTTP service address (e.g., '"+defaultAddr+"')")
|
||||
root = flag.String("root", "", "Website root (parent of 'static', 'content', and 'tmpl")
|
||||
gitwebScript = flag.String("gitwebscript", "/usr/lib/cgi-bin/gitweb.cgi", "Path to gitweb.cgi, or blank to disable.")
|
||||
gitwebFiles = flag.String("gitwebfiles", "/usr/share/gitweb", "Path to gitweb's static files.")
|
||||
pageHtml, errorHtml *template.Template
|
||||
)
|
||||
|
||||
|
@ -154,6 +156,20 @@ func serveFile(rw http.ResponseWriter, req *http.Request, relPath, absPath strin
|
|||
servePage(rw, "", "", []byte(data))
|
||||
}
|
||||
|
||||
type gitwebHandler struct{
|
||||
Cgi http.Handler
|
||||
Static http.Handler
|
||||
}
|
||||
|
||||
func (h *gitwebHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.RawPath == "/code/" ||
|
||||
strings.HasPrefix(r.URL.RawPath, "/code/?") {
|
||||
h.Cgi.ServeHTTP(rw, r)
|
||||
} else {
|
||||
h.Static.ServeHTTP(rw, r)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
readTemplates()
|
||||
|
@ -162,6 +178,13 @@ func main() {
|
|||
mux.Handle("/favicon.ico", http.FileServer(path.Join(*root, "static"), "/"))
|
||||
mux.Handle("/static/", http.FileServer(path.Join(*root, "static"), "/static/"))
|
||||
mux.Handle("/test.cgi", &CgiHandler{ExecutablePath: path.Join(*root, "test.cgi")})
|
||||
mux.Handle("/code", http.RedirectHandler("/code/", http.StatusFound))
|
||||
if *gitwebScript != "" {
|
||||
mux.Handle("/code/", &gitwebHandler{
|
||||
Cgi: &CgiHandler{ExecutablePath: *gitwebScript},
|
||||
Static: http.FileServer(*gitwebFiles, "/code/"),
|
||||
})
|
||||
}
|
||||
mux.HandleFunc("/", mainHandler)
|
||||
|
||||
if err := http.ListenAndServe(*httpAddr, mux); err != nil {
|
||||
|
|
|
@ -75,8 +75,8 @@ func (h *CgiHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
|
||||
linebody := line.NewReader(cmd.Stdout, 1024)
|
||||
unsent := make(map[string]string)
|
||||
sentStatus := false
|
||||
headers := make(map[string]string)
|
||||
statusCode := http.StatusOK
|
||||
for {
|
||||
line, isPrefix, err := linebody.ReadLine()
|
||||
if isPrefix {
|
||||
|
@ -102,32 +102,29 @@ func (h *CgiHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
h, v := parts[0], parts[1]
|
||||
h = strings.TrimSpace(h)
|
||||
v = strings.TrimSpace(h)
|
||||
v = strings.TrimSpace(v)
|
||||
switch {
|
||||
case h == "Status":
|
||||
if len(v) < 3 {
|
||||
log.Printf("CGI: bogus status (short)")
|
||||
log.Printf("CGI: bogus status (short): %q", v)
|
||||
return
|
||||
}
|
||||
code, err := strconv.Atoi(v[0:3])
|
||||
if err != nil {
|
||||
log.Printf("CGI: bogus status")
|
||||
log.Printf("CGI: bogus status: %q", v)
|
||||
log.Printf("CGI: line was %q", line)
|
||||
return
|
||||
}
|
||||
rw.WriteHeader(code)
|
||||
sentStatus = true
|
||||
case sentStatus:
|
||||
rw.SetHeader(h, v)
|
||||
case !sentStatus:
|
||||
unsent[h] = v
|
||||
statusCode = code
|
||||
default:
|
||||
headers[h] = v
|
||||
}
|
||||
}
|
||||
if !sentStatus {
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
}
|
||||
for h, v := range unsent {
|
||||
for h, v := range headers {
|
||||
rw.SetHeader(h, v)
|
||||
}
|
||||
rw.WriteHeader(statusCode)
|
||||
|
||||
_, err = io.Copy(rw, linebody)
|
||||
if err != nil {
|
||||
log.Printf("CGI: copy error: %v", err)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
<div class='bar'><div class='hatecss'>
|
||||
<a href='/'>About</a>
|
||||
<a href='/code'>Code</a>
|
||||
<a href='/code/'>Code</a>
|
||||
<a href='/contributors'>Contributors</a>
|
||||
<a href='http://groups.google.com/group/camlistore/'>Mailing List</a>
|
||||
<a href='http://code.google.com/p/camlistore/w/list'>Wiki</a>
|
||||
|
|
Loading…
Reference in New Issue