Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
f7cfe799
Commit
f7cfe799
authored
Nov 15, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
websocket: Simple buildEnv test, and fix for addresses without port
parent
3dc5e0e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
middleware/websocket/websocket.go
middleware/websocket/websocket.go
+6
-0
middleware/websocket/websocket_test.go
middleware/websocket/websocket_test.go
+22
-0
No files found.
middleware/websocket/websocket.go
View file @
f7cfe799
...
...
@@ -149,11 +149,17 @@ func serveWS(w http.ResponseWriter, r *http.Request, config *Config) (int, error
// cmdPath should be the path of the command being run.
// The returned string slice can be set to the command's Env property.
func
buildEnv
(
cmdPath
string
,
r
*
http
.
Request
)
(
metavars
[]
string
,
err
error
)
{
if
!
strings
.
Contains
(
r
.
RemoteAddr
,
":"
)
{
r
.
RemoteAddr
+=
":"
}
remoteHost
,
remotePort
,
err
:=
net
.
SplitHostPort
(
r
.
RemoteAddr
)
if
err
!=
nil
{
return
}
if
!
strings
.
Contains
(
r
.
Host
,
":"
)
{
r
.
Host
+=
":"
}
serverHost
,
serverPort
,
err
:=
net
.
SplitHostPort
(
r
.
Host
)
if
err
!=
nil
{
return
...
...
middleware/websocket/websocket_test.go
0 → 100644
View file @
f7cfe799
package
websocket
import
(
"net/http"
"testing"
)
func
TestBuildEnv
(
t
*
testing
.
T
)
{
req
,
err
:=
http
.
NewRequest
(
"GET"
,
"http://localhost"
,
nil
)
if
err
!=
nil
{
t
.
Fatal
(
"Error setting up request:"
,
err
)
}
req
.
RemoteAddr
=
"localhost:50302"
env
,
err
:=
buildEnv
(
"/bin/command"
,
req
)
if
err
!=
nil
{
t
.
Fatal
(
"Didn't expect an error:"
,
err
)
}
if
len
(
env
)
==
0
{
t
.
Fatal
(
"Expected non-empty environment; got %#v"
,
env
)
}
}
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