aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http_websocket.erl
AgeCommit message (Collapse)Author
2012-05-23Update version to 0.6.00.6.0Loïc Hoguin
Also update the CHANGELOG and copyright years.
2012-05-04Add a note about crypto websocket usage in the doc commentsLoïc Hoguin
2012-04-24use erlang:start_timer/3 instead of erlang:send_after/3 for handling timeoutsBob Ippolito
2012-04-06Merge branch 'websocket-fragments' of https://github.com/klaar/cowboyLoïc Hoguin
2012-04-05Add support for fragmented websocket messagesMagnus Klaar
2012-04-01Add chunked transfer encoding support and rework the body reading APILoïc Hoguin
Introduces 3 low level functions and updates the existing higher levels functions. The new primitives are has_body/1, body_length/1 and stream_body/1. In addition to that, a helper function init_stream/4 has been added. Streaming a body implies to decode the Transfer-Encoding and Content-Encoding used for the body. By default, Cowboy will try to figure out what was used and decode them properly. You can override this if you want to disable this behavior or simply support more encodings by calling the init_stream/4 function before you start streaming the body.
2012-04-01Convert request to proplist when loggingMagnus Klaar
2012-03-12Rename inet:ip_port() to inet:port_number()Loïc Hoguin
Thanks go to @superbobry for pointing it out.
2012-02-27Remove the redundant include/ from -include("http.hrl")Loïc Hoguin
2012-02-02Apply a trick to the erlang:hibernate calls to suppress dialyzer warningsLoïc Hoguin
Initially recommended by Magnus Klaar, the trick is to add a catch instruction before the erlang:hibernate/3 call so that Dialyzer thinks it will return, followed by the expected return value ('ok' for HTTP, 'closed' for websockets). This should be good enough until a real solution is found.
2012-01-06Fix handler crashes handlingLoïc Hoguin
We try to send a 500 error only if we didn't send the response headers yet. If they were, then we have no way to be sure the response was fully sent, nor should we assume anything about how this will be handled client-side, so we do nothing more and in both cases close the connection.
2011-12-22Add 'Upgrade' header parsingLoïc Hoguin
Not parsing product tokens, I don't see much point.
2011-12-22Websocket control frames payload length must be lower than 126 bytesLoïc Hoguin
2011-12-19Add meta/2 and meta/3 to cowboy_http_req to save useful protocol informationLoïc Hoguin
* cowboy_http_protocol now defines 'websocket_version' as metadata. * cowboy_http_rest now defines 'media_type', 'language', 'charset' as metadata.
2011-12-10update /bits in binary expressions to /binaryMagnus Klaar
This is a workaround for an issue in the hipe compiler where compilation of code matching on binaries using patterns of the form Data = <<Char, _Ignore/bits>> fails because _Ignore is expected to be used. Using /binary instead of /bits resolves the issue. We're applying this change to all binary expressions in cowboy_http because all functions in this module process human readable text formats which are always expected to be bytestrings. Two uses of /bits has been changed to /binary in cowboy_http_websocket in two clauses of a single function, websocket_data/4. This is safe to change because the data is later passed to binary:match/2 which will always fail with a badarg error if the input is a bitstring instead of a bytestring.
2011-12-08Allow HTTP protocol upgrades to use keepaliveLoïc Hoguin
REST needed this to be allowed to chain requests on the same connection.
2011-12-06Fix a crash in websocket_handshake/3 with hixie-76Loïc Hoguin
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-11-01Merge branch 'chrome-15' of https://github.com/puzza007/cowboyLoïc Hoguin
2011-10-30update record spec for version 13Paul Oliver
2011-10-26Add 'Accept' header parsingLoïc Hoguin
Rework the cowboy_http_req:parse_header/2 function while I was at it.
2011-10-24Make sure the correct callback name is displayed in websocket errorsLoïc Hoguin
2011-10-24Accept Sec-WebSocket-Version: 13 header on Chrome 15 through 17Paul Oliver
2011-10-24We don't need to retrieve the Origin header for hybi-7+ websocket draftsLoïc Hoguin
2011-10-20Parse Connection header tokens in a case-insensitive mannerLoïc Hoguin
2011-10-20Add a cowboy_http_req:upgrade_reply/3 function and use it for websocketsLoïc Hoguin
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"websocket" must be treated in a case insensitive manner for upgradesLoïc Hoguin
Fixed according to the websocket draft specs.
2011-10-20Make sure the hixie-76 websocket code works properly with proxiesLoïc Hoguin
2011-10-11Fix specs after erlang:hibernate/3 calls were addedLoïc Hoguin
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-10Add {shutdown, Req} to websocket_init/3 to fail a websocket upgradeLoïc Hoguin
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-06Merge branch 'hybi-framing-fix' of https://github.com/smarkets/cowboyLoïc Hoguin
2011-10-06Fix hixi76_location/5 when transport is tcp and port is 443Loïc Hoguin
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-05Parse 'Connection' headers as a list of tokensLoïc Hoguin
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-03Fix byte-by-byte Websocket handlingHunter Morris
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-01Get rid of a binary construct in cowboy_http_websocketLoïc Hoguin
Thanks to @nivertech for pointing it out in ticket #61.
2011-09-26Fix handshake for when querystring is neededOri Bar
2011-09-22Add a test for websocket hibernate + timeout and fix this use caseLoïc Hoguin
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-15Allow websocket handlers to hibernate from the websocket_init/3 functionLoïc Hoguin
Also improve the documentation about hibernate.
2011-08-23Add WebSocket drafts 7, 8, 9 and 10 implementationLoïc Hoguin
The implementation is only partial for now but should work for all browsers implementing it.
2011-08-10Give the ListenerPid to the protocol on startupLoïc Hoguin
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-07-19Separate message and packet handling for websocketsLoïc Hoguin
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-07Call websocket_close/4 *after* throwing the errorLoïc Hoguin
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-06Add documentation for the public interface.Loïc Hoguin
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-06-27do not send ports 80 and 443 - browsers get madSteven Gravell
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-06Add hibernate support for websockets.Loïc Hoguin
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-06Compile the binary match pattern for websockets only once.Loïc Hoguin
2011-05-31Remove a binary warning from websocket_data by removing a byte_size call.Loïc Hoguin
2011-05-27Send a meaningful error to error_logger on websocket handler crashes.Loïc Hoguin
Same as commit 4c4030a792a94d96f8bda5076fcfdc03a590030e but for websockets. See also issue #13 on github.
2011-05-25Refresh the type specifications.Loïc Hoguin
Following discussions on #erlounge. Also fixes compilation in R14B03 and fixes a few underspecs dialyzer warnings.
2011-05-05Switch the HTTP protocol to use binary packets instead of lists.Loïc Hoguin
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-04Add cowboy_http_req:port/1.Loïc Hoguin
Returns the port given in the Host header if present, otherwise the default port of 443 for HTTPS and 80 for HTTP is returned.