Skip to content

Commit

Permalink
Fix tests by taking new cowboy app into account.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyong committed Mar 26, 2014
1 parent e2a9ea6 commit e4e43e9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ clean:

test-deps:
git clone https://github.com/extend/cowboy.git test-deps/cowboy
pushd test-deps/cowboy; make; popd
pushd test-deps/cowboy; git checkout 0.9.0; make; popd

test: test-deps
mkdir -p .ct_results
ct_run -pa test-deps/cowboy/ebin test-deps/cowboy/deps/ranch/ebin ebin \
ct_run -pa test-deps/cowboy/ebin test-deps/cowboy/deps/*/ebin ebin \
-dir ct \
-logdir ./.ct_results \
-cover ct/websocket_client.coverspec
10 changes: 6 additions & 4 deletions ct/echo_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
start() ->
io:format("Starting echo server.~n"),
Dispatch = cowboy_router:compile([{'_', [
{"/hello/", ?MODULE, []},
{"/hello", ?MODULE, []},
{'_', ?MODULE, []}
]}]),
{ok, _} = cowboy:start_http(echo_listener, 2, [
Expand All @@ -34,9 +34,11 @@ init(_, _Req, _Opts) ->

websocket_init(_Transport, Req, _Opts) ->
case cowboy_req:qs_val(<<"q">>, Req) of
{undefined, Req2} -> {ok, Req2, #state{}};
{Text, Req2} -> self() ! {send, Text},
{ok, Req2, #state{}}
{undefined, Req2} ->
{ok, Req2, #state{}};
{Text, Req2} ->
self() ! {send, Text},
{ok, Req2, #state{}}
end.

websocket_handle(Frame, Req, State) ->
Expand Down
6 changes: 4 additions & 2 deletions ct/wc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ all() ->

init_per_suite(Config) ->
application:start(sasl),
application:start(asn1),
application:start(public_key),
application:start(ssl),
crypto:start(),
application:start(cow_lib),
application:start(ranch),
application:start(cowboy),
ok = echo_server:start(),
io:format("~p", [ws_client:module_info()]),
Config.

end_per_suite(Config) ->
Expand Down Expand Up @@ -122,4 +125,3 @@ long_msg() ->
L3 = << L2/binary, L2/binary, L2/binary, L2/binary >>,
%% 76800 bytes
<< L3/binary, L3/binary >>.

18 changes: 8 additions & 10 deletions src/websocket_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,14 @@ ws_client_init(Handler, Protocol, Host, Port, Path, Args) ->
websocket_handshake(WSReq) ->
[Protocol, Path, Host, Key, Transport, Socket] =
websocket_req:get([protocol, path, host, key, transport, socket], WSReq),
Handshake = [<<"GET ">>, Path,
<<" HTTP/1.1"
"\r\nHost: ">>, Host,
<<"\r\nUpgrade: WebSocket"
"\r\nConnection: Upgrade"
"\r\nSec-WebSocket-Key: ">>, Key,
<<"\r\nOrigin: ">>, atom_to_binary(Protocol, utf8), <<"://">>, Host,
<<"\r\nSec-WebSocket-Protocol: "
"\r\nSec-WebSocket-Version: 13"
"\r\n\r\n">>],
Handshake = ["GET ", Path, " HTTP/1.1\r\n"
"Host: ", Host, "\r\n"
"Connection: Upgrade\r\n"
"Origin: ", atom_to_binary(Protocol, utf8), "://", Host, "\r\n"
"Sec-WebSocket-Version: 13\r\n"
"Sec-WebSocket-Key: ", Key, "\r\n"
"Upgrade: websocket\r\n"
"\r\n"],
Transport = websocket_req:transport(WSReq),
Socket = websocket_req:socket(WSReq),
Transport:send(Socket, Handshake),
Expand Down

0 comments on commit e4e43e9

Please sign in to comment.