mirror of
https://github.com/jech/galene.git
synced 2024-11-22 08:35:57 +01:00
More tweaks to webserver error handling.
This commit is contained in:
parent
3ad6f27b17
commit
0f53bf0373
2 changed files with 23 additions and 43 deletions
|
@ -400,19 +400,13 @@ func groupStatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
g, err := group.Add(name, nil)
|
g, err := group.Add(name, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
httpError(w, err)
|
||||||
notFound(w)
|
|
||||||
} else {
|
|
||||||
http.Error(w, "Internal server error",
|
|
||||||
http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
base, err := groupBase(r)
|
base, err := groupBase(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal server error",
|
httpError(w, err)
|
||||||
http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
d := g.Status(false, base)
|
d := g.Status(false, base)
|
||||||
|
@ -431,8 +425,7 @@ func publicHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
base, err := groupBase(r)
|
base, err := groupBase(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("couldn't determine group base: %v", err)
|
log.Printf("couldn't determine group base: %v", err)
|
||||||
http.Error(w, "Internal server error",
|
httpError(w, err)
|
||||||
http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("content-type", "application/json")
|
w.Header().Set("content-type", "application/json")
|
||||||
|
@ -512,8 +505,7 @@ var wsPublicUpgrader = websocket.Upgrader{
|
||||||
func wsHandler(w http.ResponseWriter, r *http.Request) {
|
func wsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
conf, err := group.GetConfiguration()
|
conf, err := group.GetConfiguration()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal server error",
|
httpError(w, err)
|
||||||
http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
upgrader := wsUpgrader
|
upgrader := wsUpgrader
|
||||||
|
@ -548,7 +540,7 @@ func recordingsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if filepath.Separator != '/' &&
|
if filepath.Separator != '/' &&
|
||||||
strings.ContainsRune(p, filepath.Separator) {
|
strings.ContainsRune(p, filepath.Separator) {
|
||||||
http.Error(w, "bad character in filename",
|
http.Error(w, "Bad character in filename",
|
||||||
http.StatusBadRequest)
|
http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -556,7 +548,7 @@ func recordingsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
p = path.Clean(p)
|
p = path.Clean(p)
|
||||||
|
|
||||||
if p == "/" {
|
if p == "/" {
|
||||||
http.Error(w, "nothing to see", http.StatusForbidden)
|
http.Error(w, "Nothing here", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -580,18 +572,18 @@ func recordingsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
group = parseGroupName("/", p)
|
group = parseGroupName("/", p)
|
||||||
if group == "" {
|
if group == "" {
|
||||||
http.Error(w, "bad group name", http.StatusBadRequest)
|
http.Error(w, "Bad group name", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if p[len(p)-1] == '/' {
|
if p[len(p)-1] == '/' {
|
||||||
http.Error(w, "bad group name", http.StatusBadRequest)
|
http.Error(w, "Bad group name", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
group, filename = path.Split(p)
|
group, filename = path.Split(p)
|
||||||
group = parseGroupName("/", group)
|
group = parseGroupName("/", group)
|
||||||
if group == "" {
|
if group == "" {
|
||||||
http.Error(w, "bad group name", http.StatusBadRequest)
|
http.Error(w, "Bad group name", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -625,13 +617,13 @@ func recordingsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func handleGroupAction(w http.ResponseWriter, r *http.Request, group string) {
|
func handleGroupAction(w http.ResponseWriter, r *http.Request, group string) {
|
||||||
if r.Method != "POST" {
|
if r.Method != "POST" {
|
||||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := r.ParseForm()
|
err := r.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "couldn't parse request", http.StatusBadRequest)
|
http.Error(w, "Couldn't parse request", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -641,13 +633,13 @@ func handleGroupAction(w http.ResponseWriter, r *http.Request, group string) {
|
||||||
case "delete":
|
case "delete":
|
||||||
filename := r.Form.Get("filename")
|
filename := r.Form.Get("filename")
|
||||||
if group == "" || filename == "" {
|
if group == "" || filename == "" {
|
||||||
http.Error(w, "no filename provided",
|
http.Error(w, "No filename provided",
|
||||||
http.StatusBadRequest)
|
http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if strings.ContainsRune(filename, '/') ||
|
if strings.ContainsRune(filename, '/') ||
|
||||||
strings.ContainsRune(filename, filepath.Separator) {
|
strings.ContainsRune(filename, filepath.Separator) {
|
||||||
http.Error(w, "bad character in filename",
|
http.Error(w, "Bad character in filename",
|
||||||
http.StatusBadRequest)
|
http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -666,7 +658,7 @@ func handleGroupAction(w http.ResponseWriter, r *http.Request, group string) {
|
||||||
http.StatusSeeOther)
|
http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
http.Error(w, "unknown query", http.StatusBadRequest)
|
http.Error(w, "Unknown query", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,7 +702,7 @@ func serveGroupRecordings(w http.ResponseWriter, r *http.Request, f *os.File, gr
|
||||||
// read early, so we return permission errors to HEAD
|
// read early, so we return permission errors to HEAD
|
||||||
fis, err := f.Readdir(-1)
|
fis, err := f.Readdir(-1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "server error", http.StatusInternalServerError)
|
httpError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -161,20 +160,13 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
g, err := group.Add(name, nil)
|
g, err := group.Add(name, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
httpError(w, err)
|
||||||
notFound(w)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Printf("group.Add: %v", err)
|
|
||||||
http.Error(w, "Internal server error",
|
|
||||||
http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
conf, err := group.GetConfiguration()
|
conf, err := group.GetConfiguration()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal server error",
|
httpError(w, err)
|
||||||
http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,8 +212,7 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
id := newId()
|
id := newId()
|
||||||
obfuscated, err := obfuscate(id)
|
obfuscated, err := obfuscate(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal Server Error",
|
httpError(w, err)
|
||||||
http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,8 +225,7 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
log.Printf("WHIP: %v", err)
|
log.Printf("WHIP: %v", err)
|
||||||
http.Error(w, "Internal Server Error",
|
httpError(w, err)
|
||||||
http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,8 +239,8 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
group.DelClient(c)
|
group.DelClient(c)
|
||||||
log.Printf("WHIP offer: %v", err)
|
log.Printf("WHIP offer: %v", err)
|
||||||
http.Error(w, "Internal Server Error",
|
httpError(w, err)
|
||||||
http.StatusInternalServerError)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Location", path.Join(r.URL.Path, obfuscated))
|
w.Header().Set("Location", path.Join(r.URL.Path, obfuscated))
|
||||||
|
@ -273,8 +263,7 @@ func whipResourceHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
id, err := deobfuscate(rest[1:])
|
id, err := deobfuscate(rest[1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal server error",
|
httpError(w, err)
|
||||||
http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,8 +301,7 @@ func whipResourceHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
conf, err := group.GetConfiguration()
|
conf, err := group.GetConfiguration()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal server error",
|
httpError(w, err)
|
||||||
http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue