forked from electricdusk/rushlink
parent
ba08aca622
commit
40a32fa535
@ -67,6 +67,10 @@ func (rl *rushlink) uploadFileGetHandler(w http.ResponseWriter, r *http.Request)
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", fu.ContentType)
|
w.Header().Set("Content-Type", fu.ContentType)
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
if r.Method == "HEAD" {
|
||||||
|
return
|
||||||
|
}
|
||||||
io.Copy(w, file)
|
io.Copy(w, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
router.go
10
router.go
@ -79,14 +79,14 @@ func StartMainServer(addr string, db *db.Database, fs *db.FileStore) {
|
|||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.Use(recoveryMiddleware)
|
router.Use(recoveryMiddleware)
|
||||||
router.Use(metricsMiddleware)
|
router.Use(metricsMiddleware)
|
||||||
router.HandleFunc("/", rl.indexGetHandler).Methods("GET")
|
router.HandleFunc("/", rl.indexGetHandler).Methods("GET", "HEAD")
|
||||||
router.HandleFunc("/", rl.newPasteHandler).Methods("POST")
|
router.HandleFunc("/", rl.newPasteHandler).Methods("POST")
|
||||||
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}", rl.viewPasteHandler).Methods("GET")
|
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}", rl.viewPasteHandler).Methods("GET", "HEAD")
|
||||||
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}/nr", rl.viewPasteHandlerNoRedirect).Methods("GET")
|
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}/nr", rl.viewPasteHandlerNoRedirect).Methods("GET", "HEAD")
|
||||||
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}/meta", rl.viewPasteHandlerMeta).Methods("GET")
|
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}/meta", rl.viewPasteHandlerMeta).Methods("GET", "HEAD")
|
||||||
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}", rl.deletePasteHandler).Methods("DELETE")
|
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}", rl.deletePasteHandler).Methods("DELETE")
|
||||||
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}/delete", rl.deletePasteHandler).Methods("POST")
|
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}/delete", rl.deletePasteHandler).Methods("POST")
|
||||||
router.HandleFunc("/uploads/{id:[A-Za-z0-9-_]+}/{filename:.+}", rl.uploadFileGetHandler).Methods("GET")
|
router.HandleFunc("/uploads/{id:[A-Za-z0-9-_]+}/{filename:.+}", rl.uploadFileGetHandler).Methods("GET", "HEAD")
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Handler: router,
|
Handler: router,
|
||||||
|
5
views.go
5
views.go
@ -115,6 +115,11 @@ func render(w http.ResponseWriter, r *http.Request, tmplName string, data map[st
|
|||||||
}
|
}
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
|
if r.Method == "HEAD" {
|
||||||
|
return
|
||||||
|
}
|
||||||
err = tmpl.Execute(w, data)
|
err = tmpl.Execute(w, data)
|
||||||
default:
|
default:
|
||||||
// Fall back to plain text without template
|
// Fall back to plain text without template
|
||||||
|
Loading…
Reference in New Issue
Block a user