0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-15 20:50:24 +00:00
Commit graph

36 commits

Author SHA1 Message Date
Loïc Hoguin
a12a910341 Fix a crash in websocket_handshake/3 with hixie-76
Happened when an error occurred while trying to read the body to
get the key. Also fixes all the dialyzer warnings in cowboy_http_websocket.
2011-12-06 12:54:09 +01:00
Loïc Hoguin
68c1d886e5 Merge branch 'chrome-15' of https://github.com/puzza007/cowboy 2011-11-01 15:55:40 +01:00
Paul Oliver
89752a2769 update record spec for version 13 2011-10-30 11:22:12 +00:00
Loïc Hoguin
c605c4fa40 Add 'Accept' header parsing
Rework the cowboy_http_req:parse_header/2 function while I was at it.
2011-10-26 04:07:08 +02:00
Loïc Hoguin
30a1d13ae9 Make sure the correct callback name is displayed in websocket errors 2011-10-24 17:06:16 +02:00
Paul Oliver
30c3c75bbc Accept Sec-WebSocket-Version: 13 header on Chrome 15 through 17 2011-10-24 15:23:36 +01:00
Loïc Hoguin
f990109af6 We don't need to retrieve the Origin header for hybi-7+ websocket drafts 2011-10-24 10:11:09 +02:00
Loïc Hoguin
c589922ebd Parse Connection header tokens in a case-insensitive manner 2011-10-20 19:04:49 +02:00
Loïc Hoguin
381c178073 Add a cowboy_http_req:upgrade_reply/3 function and use it for websockets
This function doesn't try to add any additional header besides the
Connection: Upgrade header. It also doesn't accept a body.

It should be used for the intermediate reply to an upgrade process,
before the real reply is sent (if any, for example when using TLS).
2011-10-20 14:11:17 +02:00
Loïc Hoguin
d4088e7a46 "websocket" must be treated in a case insensitive manner for upgrades
Fixed according to the websocket draft specs.
2011-10-20 11:30:59 +02:00
Loïc Hoguin
70d28ff64d Make sure the hixie-76 websocket code works properly with proxies 2011-10-20 01:36:23 +02:00
Loïc Hoguin
691b7c4518 Fix specs after erlang:hibernate/3 calls were added
This however does not fix the related Dialyzer warnings.
I have no idea what the warnings are about nor how to fix them,
so feel free to work on it and submit a patch!
2011-10-11 01:49:13 +02:00
Loïc Hoguin
25ae2028d6 Add {shutdown, Req} to websocket_init/3 to fail a websocket upgrade
This change allows application developers to refuse websocket upgrades
by returning {shutdown, Req}. The application can also send a reply
with a custom error before returning from websocket_init/3, otherwise
an error 400 is sent.

Note that right now Cowboy closes the connection immediately. Also note
that neither terminate/3 nor websocket_terminate/3 will be called when
the connection is shutdown by websocket_init/3.
2011-10-10 09:09:15 +02:00
Loïc Hoguin
fe41f2944b Merge branch 'hybi-framing-fix' of https://github.com/smarkets/cowboy 2011-10-06 13:01:27 +02:00
Loïc Hoguin
237b468f42 Fix hixi76_location/5 when transport is tcp and port is 443
I know it is unlikely to use plain TCP on port 443, where SSL is
usually used, but a bug is still a bug, and as such it should be fixed.
Now the port will be probably appended to the location when port 443
is used without SSL.
2011-10-06 01:20:10 +02:00
Loïc Hoguin
bf5c2717bc Parse 'Connection' headers as a list of tokens
Replaces the 'Connection' interpretation in cowboy_http_protocol
from raw value to the parsed value, looking for a single token
matching close/keep-alive instead of the whole raw value (which
could contain more than one token, for example with Firefox 6+
using websocket).

Introduce the functions cowboy_http_req:parse_header/2 and /3
to semantically parse the header values and return a proper
Erlang term.
2011-10-05 13:32:20 +02:00
Hunter Morris
6250b22384 Fix byte-by-byte Websocket handling
If the websocket frame handling code in cowboy_http_websocket receives
only 1 byte at a time, it fails with a badmatch in
cowboy_http_websocket:websocket_data/4. This commit fixes the problem
and introduces a test of the correct behaviour.
2011-10-03 14:58:12 +01:00
Loïc Hoguin
986630d9ad Get rid of a binary construct in cowboy_http_websocket
Thanks to @nivertech for pointing it out in ticket #61.
2011-10-01 19:08:32 +02:00
Ori Bar
3715df5bd4 Fix handshake for when querystring is needed 2011-09-26 19:57:46 +02:00
Loïc Hoguin
d0f711a61d Add a test for websocket hibernate + timeout and fix this use case
The issue was that we were calling erlang:hibernate before a
receive .. after .. end call. Erlang hibernates the process before
reaching the receive instruction and we therefore couldn't enter
the after clause when hibernating.

This is now fixed by using erlang:send_after instead and receiving
that message instead of using an after clause.
2011-09-22 23:15:54 +02:00
Loïc Hoguin
04f55eb3c9 Allow websocket handlers to hibernate from the websocket_init/3 function
Also improve the documentation about hibernate.
2011-09-15 23:20:02 +02:00
Loïc Hoguin
2374aa7e07 Add WebSocket drafts 7, 8, 9 and 10 implementation
The implementation is only partial for now but should work for
all browsers implementing it.
2011-08-23 23:49:58 +02:00
Loïc Hoguin
43d14b52cd Give the ListenerPid to the protocol on startup
Also sends a message 'shoot' that can be received by the protocol
to make sure Cowboy has had enough time to fully initialize the
socket. This message should be received before any socket-related
operations are performed.

WebSocket request connections are now moved from the pool 'default'
to the pool 'websocket', meaning we can have a lot of running
WebSockets despite having a low 'max_connections' setting.
2011-08-10 20:28:30 +02:00
Loïc Hoguin
293cf33702 Separate message and packet handling for websockets
Improves the readability of websocket handler code by having
two functions: websocket_handle/3 handles the packets received
from the socket, removing the tuple construct that was otherwise
needed, so only websocket_handle(Data, Req, State) is needed now;
websocket_info/3 handles the messages that the websocket handler
process received, as websocket_info(Info, Req, State).

Both functions return values are handled identically by Cowboy
so nothing changes on that end.
2011-07-19 12:20:16 +02:00
Loïc Hoguin
87366e36ad Call websocket_close/4 *after* throwing the error
This ensures that an error thrown in handler_terminate/4 will be
shown after the error from handler_call/6, in the expected order.

As we already call WebSocketHandler:terminate/3, this should
fix issue #23.
2011-07-07 17:50:46 +02:00
Loïc Hoguin
108a491f55 Add documentation for the public interface.
This is probably not perfect yet but it should be better than
nothing. We'll improve things with feedback received from the
many users.
2011-07-06 17:42:20 +02:00
Steven Gravell
bebe3dc5d2 do not send ports 80 and 443 - browsers get mad
Browsers get mad that the returned location address is not the same
as what they sent, since the :(80|443) is stripped.

Add a simple eunit test due to existing ct websockets tests not
covering this case.
2011-06-27 15:25:30 +01:00
Loïc Hoguin
648921b8cf Add hibernate support for websockets.
Return {ok, Req, State, hibernate}
or {reply, Data, Req, State, hibernate} to hibernate the websocket
process and save up memory and CPU. You should hibernate processes
that will receive few messages. So probably most of them.
2011-06-06 18:15:36 +02:00
Loïc Hoguin
2fa1e53928 Compile the binary match pattern for websockets only once. 2011-06-06 13:48:41 +02:00
Loïc Hoguin
3cfdf46e97 Remove a binary warning from websocket_data by removing a byte_size call. 2011-05-31 12:48:59 +02:00
Loïc Hoguin
ad2e905a81 Send a meaningful error to error_logger on websocket handler crashes.
Same as commit 4c4030a792 but for websockets.
See also issue #13 on github.
2011-05-27 12:32:02 +02:00
Loïc Hoguin
3e55cb62c9 Refresh the type specifications.
Following discussions on #erlounge.

Also fixes compilation in R14B03 and fixes a few underspecs
dialyzer warnings.
2011-05-25 23:02:40 +02:00
Loïc Hoguin
29e71cf4da Switch the HTTP protocol to use binary packets instead of lists.
The server now does a single recv (or more, but only if needed)
which is then sent to erlang:decode_packet/3 multiple times. Since
most requests are smaller than the default MTU on many platforms,
we benefit from this greatly.

In the case of requests with a body, the server usually read at
least part of the body on the first recv. This is bufferized
properly and used when later retrieving the body.

In the case of pipelined requests, we can end up reading many
requests in a single recv, which are then handled properly using
only the buffer containing the received data.
2011-05-05 14:03:39 +02:00
Loïc Hoguin
6c1f73c53c Add cowboy_http_req:port/1.
Returns the port given in the Host header if present,
otherwise the default port of 443 for HTTPS and 80 for HTTP
is returned.
2011-05-04 12:52:13 +02:00
Loïc Hoguin
e8286e18e6 Remove the include/types.hrl file. 2011-04-18 13:56:38 +02:00
Loïc Hoguin
cb60d18e82 Initial draft-hixie-thewebsocketprotocol-76 support. 2011-04-14 21:21:17 +02:00