Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
galene
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
galene
Commits
0f53bf03
Commit
0f53bf03
authored
Jan 18, 2024
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More tweaks to webserver error handling.
parent
3ad6f27b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
43 deletions
+23
-43
webserver/webserver.go
webserver/webserver.go
+15
-23
webserver/whip.go
webserver/whip.go
+8
-20
No files found.
webserver/webserver.go
View file @
0f53bf03
...
...
@@ -400,19 +400,13 @@ func groupStatusHandler(w http.ResponseWriter, r *http.Request) {
g
,
err
:=
group
.
Add
(
name
,
nil
)
if
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
notFound
(
w
)
}
else
{
http
.
Error
(
w
,
"Internal server error"
,
http
.
StatusInternalServerError
)
}
httpError
(
w
,
err
)
return
}
base
,
err
:=
groupBase
(
r
)
if
err
!=
nil
{
http
.
Error
(
w
,
"Internal server error"
,
http
.
StatusInternalServerError
)
httpError
(
w
,
err
)
return
}
d
:=
g
.
Status
(
false
,
base
)
...
...
@@ -431,8 +425,7 @@ func publicHandler(w http.ResponseWriter, r *http.Request) {
base
,
err
:=
groupBase
(
r
)
if
err
!=
nil
{
log
.
Printf
(
"couldn't determine group base: %v"
,
err
)
http
.
Error
(
w
,
"Internal server error"
,
http
.
StatusInternalServerError
)
httpError
(
w
,
err
)
return
}
w
.
Header
()
.
Set
(
"content-type"
,
"application/json"
)
...
...
@@ -512,8 +505,7 @@ var wsPublicUpgrader = websocket.Upgrader{
func
wsHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
conf
,
err
:=
group
.
GetConfiguration
()
if
err
!=
nil
{
http
.
Error
(
w
,
"Internal server error"
,
http
.
StatusInternalServerError
)
httpError
(
w
,
err
)
return
}
upgrader
:=
wsUpgrader
...
...
@@ -548,7 +540,7 @@ func recordingsHandler(w http.ResponseWriter, r *http.Request) {
if
filepath
.
Separator
!=
'/'
&&
strings
.
ContainsRune
(
p
,
filepath
.
Separator
)
{
http
.
Error
(
w
,
"
b
ad character in filename"
,
http
.
Error
(
w
,
"
B
ad character in filename"
,
http
.
StatusBadRequest
)
return
}
...
...
@@ -556,7 +548,7 @@ func recordingsHandler(w http.ResponseWriter, r *http.Request) {
p
=
path
.
Clean
(
p
)
if
p
==
"/"
{
http
.
Error
(
w
,
"
nothing to se
e"
,
http
.
StatusForbidden
)
http
.
Error
(
w
,
"
Nothing her
e"
,
http
.
StatusForbidden
)
return
}
...
...
@@ -580,18 +572,18 @@ func recordingsHandler(w http.ResponseWriter, r *http.Request) {
}
group
=
parseGroupName
(
"/"
,
p
)
if
group
==
""
{
http
.
Error
(
w
,
"
b
ad group name"
,
http
.
StatusBadRequest
)
http
.
Error
(
w
,
"
B
ad group name"
,
http
.
StatusBadRequest
)
return
}
}
else
{
if
p
[
len
(
p
)
-
1
]
==
'/'
{
http
.
Error
(
w
,
"
b
ad group name"
,
http
.
StatusBadRequest
)
http
.
Error
(
w
,
"
B
ad group name"
,
http
.
StatusBadRequest
)
return
}
group
,
filename
=
path
.
Split
(
p
)
group
=
parseGroupName
(
"/"
,
group
)
if
group
==
""
{
http
.
Error
(
w
,
"
b
ad group name"
,
http
.
StatusBadRequest
)
http
.
Error
(
w
,
"
B
ad group name"
,
http
.
StatusBadRequest
)
return
}
}
...
...
@@ -625,13 +617,13 @@ func recordingsHandler(w http.ResponseWriter, r *http.Request) {
func
handleGroupAction
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
group
string
)
{
if
r
.
Method
!=
"POST"
{
http
.
Error
(
w
,
"
m
ethod not allowed"
,
http
.
StatusMethodNotAllowed
)
http
.
Error
(
w
,
"
M
ethod not allowed"
,
http
.
StatusMethodNotAllowed
)
return
}
err
:=
r
.
ParseForm
()
if
err
!=
nil
{
http
.
Error
(
w
,
"
c
ouldn't parse request"
,
http
.
StatusBadRequest
)
http
.
Error
(
w
,
"
C
ouldn't parse request"
,
http
.
StatusBadRequest
)
return
}
...
...
@@ -641,13 +633,13 @@ func handleGroupAction(w http.ResponseWriter, r *http.Request, group string) {
case
"delete"
:
filename
:=
r
.
Form
.
Get
(
"filename"
)
if
group
==
""
||
filename
==
""
{
http
.
Error
(
w
,
"
n
o filename provided"
,
http
.
Error
(
w
,
"
N
o filename provided"
,
http
.
StatusBadRequest
)
return
}
if
strings
.
ContainsRune
(
filename
,
'/'
)
||
strings
.
ContainsRune
(
filename
,
filepath
.
Separator
)
{
http
.
Error
(
w
,
"
b
ad character in filename"
,
http
.
Error
(
w
,
"
B
ad character in filename"
,
http
.
StatusBadRequest
)
return
}
...
...
@@ -666,7 +658,7 @@ func handleGroupAction(w http.ResponseWriter, r *http.Request, group string) {
http
.
StatusSeeOther
)
return
default
:
http
.
Error
(
w
,
"
u
nknown query"
,
http
.
StatusBadRequest
)
http
.
Error
(
w
,
"
U
nknown 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
fis
,
err
:=
f
.
Readdir
(
-
1
)
if
err
!=
nil
{
http
.
Error
(
w
,
"server error"
,
http
.
StatusInternalServerErro
r
)
http
Error
(
w
,
er
r
)
return
}
...
...
webserver/whip.go
View file @
0f53bf03
...
...
@@ -12,7 +12,6 @@ import (
"log"
"net/http"
"net/url"
"os"
"path"
"strings"
...
...
@@ -161,20 +160,13 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
g
,
err
:=
group
.
Add
(
name
,
nil
)
if
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
notFound
(
w
)
return
}
log
.
Printf
(
"group.Add: %v"
,
err
)
http
.
Error
(
w
,
"Internal server error"
,
http
.
StatusInternalServerError
)
httpError
(
w
,
err
)
return
}
conf
,
err
:=
group
.
GetConfiguration
()
if
err
!=
nil
{
http
.
Error
(
w
,
"Internal server error"
,
http
.
StatusInternalServerError
)
httpError
(
w
,
err
)
return
}
...
...
@@ -220,8 +212,7 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
id
:=
newId
()
obfuscated
,
err
:=
obfuscate
(
id
)
if
err
!=
nil
{
http
.
Error
(
w
,
"Internal Server Error"
,
http
.
StatusInternalServerError
)
httpError
(
w
,
err
)
return
}
...
...
@@ -234,8 +225,7 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
return
}
else
if
err
!=
nil
{
log
.
Printf
(
"WHIP: %v"
,
err
)
http
.
Error
(
w
,
"Internal Server Error"
,
http
.
StatusInternalServerError
)
httpError
(
w
,
err
)
return
}
...
...
@@ -249,8 +239,8 @@ func whipEndpointHandler(w http.ResponseWriter, r *http.Request) {
if
err
!=
nil
{
group
.
DelClient
(
c
)
log
.
Printf
(
"WHIP offer: %v"
,
err
)
http
.
Error
(
w
,
"Internal Server Error"
,
http
.
StatusInternalServerError
)
http
Error
(
w
,
err
)
return
}
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
:
])
if
err
!=
nil
{
http
.
Error
(
w
,
"Internal server error"
,
http
.
StatusInternalServerError
)
httpError
(
w
,
err
)
return
}
...
...
@@ -312,8 +301,7 @@ func whipResourceHandler(w http.ResponseWriter, r *http.Request) {
conf
,
err
:=
group
.
GetConfiguration
()
if
err
!=
nil
{
http
.
Error
(
w
,
"Internal server error"
,
http
.
StatusInternalServerError
)
httpError
(
w
,
err
)
return
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment