Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
memoriav
Memobase 2020
services
Streaming Server
Commits
607ffff3
Commit
607ffff3
authored
Sep 28, 2020
by
Juergen Enge
Browse files
fallback signature parameter added
parent
4c4eb47d
Pipeline
#14874
passed with stages
in 3 minutes and 37 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pkg/memostream/memoServerHandlerMain.go
View file @
607ffff3
...
...
@@ -15,6 +15,7 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"regexp"
"strings"
)
...
...
@@ -39,6 +40,8 @@ func proxy(url url.URL, w http.ResponseWriter, req *http.Request) {
rp
.
ServeHTTP
(
w
,
req
)
}
var
regexpFallback
=
regexp
.
MustCompile
(
"^fallback(.+)$"
)
func
(
ms
*
memoServer
)
mainHandler
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
// remove prefix and use whole rest of url as signature
vars
:=
mux
.
Vars
(
req
)
...
...
@@ -48,14 +51,30 @@ func (ms *memoServer) mainHandler(w http.ResponseWriter, req *http.Request) {
return
}
action
,
_
:=
vars
[
"action"
]
params
,
_
:=
vars
[
"params"
]
//signature
:= strings.
TrimPrefix(req.URL.Path, ms.urlPrefix
)
params
tr
,
_
:=
vars
[
"params
tr
"
]
params
:=
strings
.
Split
(
paramstr
,
"/"
)
// resolve signature
me
,
err
:=
ms
.
resolver
.
resolve
(
signature
)
if
err
!=
nil
{
ms
.
DoPanicf
(
w
,
http
.
StatusNotFound
,
"signature %v not found: %v"
,
signature
,
err
)
return
// check for fallback parameter only if needed
fallback
:=
""
for
_
,
p
:=
range
params
{
if
matches
:=
regexpFallback
.
FindStringSubmatch
(
p
);
matches
!=
nil
{
fallback
=
matches
[
1
]
break
}
}
if
fallback
!=
""
{
me
,
err
=
ms
.
resolver
.
resolve
(
fallback
)
if
err
!=
nil
{
ms
.
DoPanicf
(
w
,
http
.
StatusNotFound
,
"signature %v and fallback %v not found: %v"
,
signature
,
fallback
,
err
)
return
}
}
else
{
ms
.
DoPanicf
(
w
,
http
.
StatusNotFound
,
"signature %v not found: %v"
,
signature
,
err
)
return
}
}
if
me
.
Access
!=
Media_Public
{
if
err
:=
CheckRequestJWT
(
req
,
ms
.
jwtSecret
,
ms
.
jwtAlg
,
signature
);
err
!=
nil
{
...
...
@@ -69,7 +88,7 @@ func (ms *memoServer) mainHandler(w http.ResponseWriter, req *http.Request) {
}
if
actions
,
ok
:=
ms
.
actions
[
me
.
Type
];
ok
{
for
_
,
a
:=
range
actions
{
ok
,
err
:=
a
.
Do
(
w
,
req
,
me
,
action
,
strings
.
Split
(
params
,
"/"
)
...
)
ok
,
err
:=
a
.
Do
(
w
,
req
,
me
,
action
,
params
...
)
if
err
!=
nil
{
ms
.
DoPanicf
(
w
,
http
.
StatusInternalServerError
,
"Cannot execute action %s on signature %s: %v"
,
action
,
me
.
Signature
,
err
)
return
...
...
Write
Preview
Supports
Markdown
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