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
Łukasz Nowak
caddy
Commits
292c15cd
Commit
292c15cd
authored
Jun 23, 2015
by
Karthic Rao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modularizing config/setup/Websocket.go and for the same
parent
06a7f1d3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
5 deletions
+51
-5
config/setup/websocket.go
config/setup/websocket.go
+15
-5
config/setup/websocket_test.go
config/setup/websocket_test.go
+36
-0
No files found.
config/setup/websocket.go
View file @
292c15cd
...
...
@@ -7,6 +7,20 @@ import (
// WebSocket configures a new WebSockets middleware instance.
func
WebSocket
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
websocks
,
err
:=
websocketParse
(
c
)
if
err
!=
nil
{
return
nil
,
err
}
websockets
.
GatewayInterface
=
c
.
AppName
+
"-CGI/1.1"
websockets
.
ServerSoftware
=
c
.
AppName
+
"/"
+
c
.
AppVersion
return
func
(
next
middleware
.
Handler
)
middleware
.
Handler
{
return
websockets
.
WebSockets
{
Next
:
next
,
Sockets
:
websocks
}
},
nil
}
func
websocketParse
(
c
*
Controller
)
([]
websockets
.
Config
,
error
)
{
var
websocks
[]
websockets
.
Config
var
respawn
bool
...
...
@@ -68,10 +82,6 @@ func WebSocket(c *Controller) (middleware.Middleware, error) {
})
}
websockets
.
GatewayInterface
=
c
.
AppName
+
"-CGI/1.1"
websockets
.
ServerSoftware
=
c
.
AppName
+
"/"
+
c
.
AppVersion
return
websocks
,
nil
return
func
(
next
middleware
.
Handler
)
middleware
.
Handler
{
return
websockets
.
WebSockets
{
Next
:
next
,
Sockets
:
websocks
}
},
nil
}
config/setup/websocket_test.go
0 → 100644
View file @
292c15cd
package
setup
import
(
"github.com/mholt/caddy/middleware/websockets"
"testing"
)
func
TestWebSocket
(
t
*
testing
.
T
)
{
c
:=
NewTestController
(
`websocket cat`
)
mid
,
err
:=
WebSocket
(
c
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected no errors, got: %v"
,
err
)
}
if
mid
==
nil
{
t
.
Fatal
(
"Expected middleware, was nil instead"
)
}
handler
:=
mid
(
EmptyNext
)
myHandler
,
ok
:=
handler
.
(
websockets
.
WebSockets
)
if
!
ok
{
t
.
Fatalf
(
"Expected handler to be type WebSockets, got: %#v"
,
handler
)
}
if
myHandler
.
Sockets
[
0
]
.
Path
!=
"/"
{
t
.
Errorf
(
"Expected / as the default Path"
)
}
if
myHandler
.
Sockets
[
0
]
.
Command
!=
"cat"
{
t
.
Errorf
(
"Expected %s as the command"
,
"cat"
)
}
}
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