-
Notifications
You must be signed in to change notification settings - Fork 618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support HTTP Websocket Connections in wsclient #899
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,9 +54,6 @@ const ( | |
// writeBufSize is the size of the write buffer for the ws connection. | ||
writeBufSize = 32768 | ||
|
||
// gorilla/websocket expects the websocket scheme (ws[s]://) | ||
wsScheme = "wss" | ||
|
||
// Default NO_PROXY env var IP addresses | ||
defaultNoProxyIP = "169.254.169.254,169.254.170.2" | ||
) | ||
|
@@ -142,6 +139,10 @@ func (cs *ClientServerImpl) Connect() error { | |
return err | ||
} | ||
|
||
wsScheme, err := websocketScheme(parsedURL.Scheme) | ||
if err != nil { | ||
return err | ||
} | ||
parsedURL.Scheme = wsScheme | ||
|
||
// NewRequest never returns an error if the url parses and we just verified | ||
|
@@ -349,6 +350,19 @@ func (cs *ClientServerImpl) handleMessage(data []byte) { | |
} | ||
} | ||
|
||
func websocketScheme(httpScheme string) (wsScheme string, err error) { | ||
// gorilla/websocket expects the websocket scheme (ws[s]://) | ||
switch httpScheme { | ||
case "http": | ||
wsScheme = "ws" | ||
case "https": | ||
wsScheme = "wss" | ||
default: | ||
err = fmt.Errorf("Unknown httpScheme %s", httpScheme) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use format
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} | ||
return | ||
} | ||
|
||
// See https://github.com/gorilla/websocket/blob/87f6f6a22ebfbc3f89b9ccdc7fddd1b914c095f9/conn.go#L650 | ||
func permissibleCloseCode(err error) bool { | ||
return websocket.IsCloseError(err, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,9 @@ import ( | |
"github.com/gorilla/websocket" | ||
) | ||
|
||
// StartMockServer starts a mock websocket server. | ||
// GetMockServer retuns a mock websocket server that can be started up as TLS or not. | ||
// TODO replace with gomock | ||
func StartMockServer(t *testing.T, closeWS <-chan []byte) (*httptest.Server, chan<- string, <-chan string, <-chan error, error) { | ||
func GetMockServer(t *testing.T, closeWS <-chan []byte) (*httptest.Server, chan<- string, <-chan string, <-chan error, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Should we gate this code path with an 'allowUnsecureACS' option?" So my argument against is that we do allow using an http endpoint to talk to ECS via the SDK. If there were a flag, it should apply to both. |
||
serverChan := make(chan string) | ||
requestsChan := make(chan string) | ||
errChan := make(chan error) | ||
|
@@ -63,6 +63,6 @@ func StartMockServer(t *testing.T, closeWS <-chan []byte) (*httptest.Server, cha | |
} | ||
}) | ||
|
||
server := httptest.NewTLSServer(handler) | ||
server := httptest.NewUnstartedServer(handler) | ||
return server, serverChan, requestsChan, errChan, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, we've avoided using named returns. Please change this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
samuelkarp@d57d983