This commit is contained in:
parent
900b6bd3e7
commit
fa0c7e9373
2 changed files with 9 additions and 0 deletions
2
main.go
2
main.go
|
@ -167,6 +167,8 @@ func requestPerMinute() {
|
|||
|
||||
func beforeAll(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, req *http.Request) {
|
||||
defer panicHandler(w)
|
||||
|
||||
if req.Method != "GET" && req.Method != "HEAD" {
|
||||
io.WriteString(w, "Only GET and HEAD requests are allowed.")
|
||||
return
|
||||
|
|
7
utils.go
7
utils.go
|
@ -55,3 +55,10 @@ func RelativeUrl(in string) (newurl string) {
|
|||
segment_url.Path = path_prefix + segment_url.Path
|
||||
return segment_url.RequestURI()
|
||||
}
|
||||
|
||||
func panicHandler(w http.ResponseWriter) {
|
||||
if r := recover(); r != nil {
|
||||
log.Printf("Panic: %v", r)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue