Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sfu
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
Alain Takoudjou
sfu
Commits
f8e2f755
Commit
f8e2f755
authored
Dec 07, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement redirection to canonical host.
parent
ef1c211b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
galene.go
galene.go
+2
-0
webserver/webserver.go
webserver/webserver.go
+28
-0
No files found.
galene.go
View file @
f8e2f755
...
@@ -27,6 +27,8 @@ func main() {
...
@@ -27,6 +27,8 @@ func main() {
flag
.
StringVar
(
&
httpAddr
,
"http"
,
":8443"
,
"web server `address`"
)
flag
.
StringVar
(
&
httpAddr
,
"http"
,
":8443"
,
"web server `address`"
)
flag
.
StringVar
(
&
webserver
.
StaticRoot
,
"static"
,
"./static/"
,
flag
.
StringVar
(
&
webserver
.
StaticRoot
,
"static"
,
"./static/"
,
"web server root `directory`"
)
"web server root `directory`"
)
flag
.
StringVar
(
&
webserver
.
Redirect
,
"redirect"
,
""
,
"redirect to canonical `host`"
)
flag
.
StringVar
(
&
dataDir
,
"data"
,
"./data/"
,
flag
.
StringVar
(
&
dataDir
,
"data"
,
"./data/"
,
"data `directory`"
)
"data `directory`"
)
flag
.
StringVar
(
&
group
.
Directory
,
"groups"
,
"./groups/"
,
flag
.
StringVar
(
&
group
.
Directory
,
"groups"
,
"./groups/"
,
...
...
webserver/webserver.go
View file @
f8e2f755
...
@@ -31,6 +31,8 @@ var server atomic.Value
...
@@ -31,6 +31,8 @@ var server atomic.Value
var
StaticRoot
string
var
StaticRoot
string
var
Redirect
string
func
Serve
(
address
string
,
dataDir
string
)
error
{
func
Serve
(
address
string
,
dataDir
string
)
error
{
http
.
Handle
(
"/"
,
&
fileHandler
{
http
.
Dir
(
StaticRoot
)})
http
.
Handle
(
"/"
,
&
fileHandler
{
http
.
Dir
(
StaticRoot
)})
http
.
HandleFunc
(
"/group/"
,
groupHandler
)
http
.
HandleFunc
(
"/group/"
,
groupHandler
)
...
@@ -116,6 +118,20 @@ const (
...
@@ -116,6 +118,20 @@ const (
veryCachableCacheControl
=
"max-age=86400"
veryCachableCacheControl
=
"max-age=86400"
)
)
func
redirect
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
bool
{
if
Redirect
==
""
||
strings
.
EqualFold
(
r
.
Host
,
Redirect
)
{
return
false
}
u
:=
url
.
URL
{
Scheme
:
"https"
,
Host
:
Redirect
,
Path
:
r
.
URL
.
Path
,
}
http
.
Redirect
(
w
,
r
,
u
.
String
(),
http
.
StatusMovedPermanently
)
return
true
}
func
makeCachable
(
w
http
.
ResponseWriter
,
p
string
,
fi
os
.
FileInfo
,
cachable
bool
)
{
func
makeCachable
(
w
http
.
ResponseWriter
,
p
string
,
fi
os
.
FileInfo
,
cachable
bool
)
{
etag
:=
fmt
.
Sprintf
(
"
\"
%v-%v
\"
"
,
fi
.
Size
(),
fi
.
ModTime
()
.
UnixNano
())
etag
:=
fmt
.
Sprintf
(
"
\"
%v-%v
\"
"
,
fi
.
Size
(),
fi
.
ModTime
()
.
UnixNano
())
w
.
Header
()
.
Set
(
"ETag"
,
etag
)
w
.
Header
()
.
Set
(
"ETag"
,
etag
)
...
@@ -140,6 +156,10 @@ type fileHandler struct {
...
@@ -140,6 +156,10 @@ type fileHandler struct {
}
}
func
(
fh
*
fileHandler
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
(
fh
*
fileHandler
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
redirect
(
w
,
r
)
{
return
}
mungeHeader
(
w
)
mungeHeader
(
w
)
p
:=
r
.
URL
.
Path
p
:=
r
.
URL
.
Path
// this ensures any leading .. are removed by path.Clean below
// this ensures any leading .. are removed by path.Clean below
...
@@ -236,6 +256,10 @@ func parseGroupName(path string) string {
...
@@ -236,6 +256,10 @@ func parseGroupName(path string) string {
}
}
func
groupHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
groupHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
redirect
(
w
,
r
)
{
return
}
mungeHeader
(
w
)
mungeHeader
(
w
)
name
:=
parseGroupName
(
r
.
URL
.
Path
)
name
:=
parseGroupName
(
r
.
URL
.
Path
)
if
name
==
""
{
if
name
==
""
{
...
@@ -420,6 +444,10 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -420,6 +444,10 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
}
}
func
recordingsHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
recordingsHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
redirect
(
w
,
r
)
{
return
}
if
len
(
r
.
URL
.
Path
)
<
12
||
r
.
URL
.
Path
[
:
12
]
!=
"/recordings/"
{
if
len
(
r
.
URL
.
Path
)
<
12
||
r
.
URL
.
Path
[
:
12
]
!=
"/recordings/"
{
http
.
Error
(
w
,
"server error"
,
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
"server error"
,
http
.
StatusInternalServerError
)
return
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