aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_websocket.erl
AgeCommit message (Collapse)Author
2015-03-06Update Cowlib to 1.2.0; adds Websocket permessage-deflateLoïc Hoguin
The Websocket text frames should also be less resource intensive to validate now, with a binary concatenation avoided.
2015-02-16Use cow_ws for the Websocket parsing codeLoïc Hoguin
Updates Cowlib to 1.1.0
2014-11-07Rename 'shutdown' close reason and tuples to 'stop'Loïc Hoguin
The 'shutdown' atom has a specific meaning inside OTP. We are instead going to use 'stop' which is pretty much the equivalent of what we actually do. 'shutdown' is now reserved for future special processes implementation.
2014-10-03Replace some /binary to /bits in binary pattern matchingLoïc Hoguin
We don't need the extra check for multiple of 8 bits.
2014-09-30Improve handler interface and documentationLoïc Hoguin
This change simplifies a little more the sub protocols mechanism. Aliases have been removed. The renaming of loop handlers as long polling handlers has been reverted. Plain HTTP handlers now simply do their work in the init/2 callback. There is no specific code for them. Loop handlers now follow the same return value as Websocket, they use ok to continue and shutdown to stop. Terminate reasons for all handler types have been documented. The terminate callback is now appropriately called in all cases (or should be). Behaviors for all handler types have been moved in the module that implement them. This means that cowboy_handler replaces the cowboy_http_handler behavior, and similarly cowboy_loop replaces cowboy_loop_handler, cowboy_websocket replaces cowboy_websocket_handler. Finally cowboy_rest now has the start of a behavior in it and will have the full list of optional callbacks defined once Erlang 18.0 gets released. The guide has been reorganized and should be easier to follow.
2014-09-26Unify the init and terminate callbacksLoïc Hoguin
This set of changes is the first step to simplify the writing of handlers, by removing some extraneous callbacks and making others optional. init/3 is now init/2, its first argument being removed. rest_init/2 and rest_terminate/2 have been removed. websocket_init/3 and websocket_terminate/3 have been removed. terminate/3 is now optional. It is called regardless of the type of handler, including rest and websocket. The return value of init/2 changed. It now returns {Mod, Req, Opts} with Mod being either one of the four handler type or a custom module. It can also return extra timeout and hibernate options. The signature for sub protocols has changed, they now receive these extra timeout and hibernate options. Loop handlers are now implemented in cowboy_long_polling, and will be renamed throughout the project in a future commit.
2014-09-23Breaking update of the cowboy_req interfaceLoïc Hoguin
Simplify the interface for most cowboy_req functions. They all return a single value except the four body reading functions. The reply functions now only return a Req value. Access functions do not return a Req anymore. Functions that used to cache results do not have a cache anymore. The interface for accessing query string and cookies has therefore been changed. There are now three query string functions: qs/1 provides access to the raw query string value; parse_qs/1 returns the query string as a list of key/values; match_qs/2 returns a map containing the values requested in the second argument, after applying constraints and default value. Similarly, there are two cookie functions: parse_cookies/1 and match_cookies/2. More match functions will be added in future commits. None of the functions return an error tuple anymore. It either works or crashes. Cowboy will attempt to provide an appropriate status code in the response of crashed handlers. As a result, the content decode function has its return value changed to a simple binary, and the body reading functions only return on success.
2014-07-12Drop R15 supportLoïc Hoguin
2014-07-12Reply with 400 on header parsing crashLoïc Hoguin
This is a first step to improve the HTTP status codes returned by Cowboy on crashes. We will tweak it over time. Also fixes a small bug where two replies may have been sent when using loop handlers under rare conditions.
2014-06-30Update specs that were too wideLoïc Hoguin
2014-03-26Remove outdated comments, all edoc, plus a few minor tweaksLoïc Hoguin
2014-03-08Fix typespecs of cowboy_websocket:handler_terminateLoïc Hoguin
Pointed out during the ConcuError tutorial by Kostis. Thanks! :-)
2014-02-06Update copyright yearsLoïc Hoguin
2013-08-27Merge branch 'fix-ws-atom-responses' of git://github.com/seriyps/cowboyLoïc Hoguin
2013-08-27Merge branch 'websocket-compressed-metadata' of git://github.com/irccloud/cowboyLoïc Hoguin
2013-08-24Crash on failure, don't report errorsLoïc Hoguin
When something went wrong in a handler we used to report errors and then terminate the process normally. This doesn't work so well with links which won't detect failure. Now we still catch the error, but throw another one with more details on why it happened, including the Req object information and the stacktrace. Ranch will then print an error message with all this information. Because we crash directly, this also means that we will not hog resources unnecessarily for too long when something bad happens.
2013-08-15add websocket_compress metadataRJ
2013-08-13Allow atom responses in websocket handlers #563Sergey Prokhorov
2013-07-08Use the proper typespec for the websocket_deflate_frame rsv bitsAli Sabil
2013-07-02Fix handling of websocket fragmented deflated framesAli Sabil
2013-07-02Fix websocket unmasking when compression is enabledAli Sabil
The unmasking logic was based on the length of inflated data instead of the length of the deflated data. This meant data would get corrupted when we receive a websocket frame split across multiple TCP packets.
2013-07-02Fix coding style in websocket_deflate_frame/3Ali Sabil
2013-07-02Remove usage of the inflate bufferAli Sabil
2013-06-20Fix compilation < R16B010.8.6Loïc Hoguin
2013-06-20Ignore deprecation warning for crypto:sha/1 for nowLoïc Hoguin
We can change this call when we start supporting only R16B+, which may happen when R17B is released or some time before.
2013-06-20Add support for the webkit deflate frame extensionAli Sabil
2013-05-15Fix the cowboy_websocket:frame/0 typeLoïc Hoguin
It accepts iodata() and not binary() for the payload.
2013-04-03Update Ranch to 0.8.0Loïc Hoguin
2013-02-16Add sub protocol behaviourJames Fish
2013-02-14Properly pass the handler's state to websocket_terminate/3 on closeLoïc Hoguin
2013-02-13Make cowboy_websocket.erl compile with +nativeAdam Cammack
Worked until cccc0bc
2013-02-09Do not reset the connection timeout timer on sendLoïc Hoguin
Sends can be successful even if the connection is gone.
2013-01-29Fix {cowboy_req, resp_sent} potentially leaking in loop handlersLoïc Hoguin
2013-01-17Add cowboy_websocket:close_code/0Loïc Hoguin
Also fixes a warning.
2013-01-14Improve websocket close handlingLoïc Hoguin
We now always send a failure reason (bad protocol, bad encoding, etc.) unless the closure was initiated by the client and it didn't send a close code. We now check that the close frames have a payload that is valid UTF-8, unless they don't have a payload at all. We now do not crash the process anymore when bad opcodes are sent, or when the opcode 0 is sent before fragmentation was initiated. Overall this makes us closer to full compliance with the RFC.
2013-01-13Websocket text frames are now checked for UTF-8 correctnessLoïc Hoguin
The autobahntestsuite now passes 100% of the tests. We are getting close to fully implementing the Websocket RFC.
2013-01-12Unmask websocket frames on the fly and optimize the codeLoïc Hoguin
No change in functionality, but this will allow us to validate that text frames are utf8 without having to receive the frame entirely.
2013-01-12All frames sent from client to server MUST be maskedLoïc Hoguin
Good in theory, but implementations may vary. If something stops working after this commit we might need some tweaks to support existing clients. Please try it and give feedback.
2013-01-10Remove support for Websocket hixie76 draftLoïc Hoguin
It was only used by Safari 5.0.1 and possibly 5.1. Their market share is dropping as we speak. It was also insecure (disabled in Firefox for that reason). This will allow us to make much more efficient and cleaner code for the rest of the Websocket versions we support (drafts 7 to 17 + RFC), which are pretty much all versions seen in the wild excluding the one we're removing here.
2013-01-05Remove cowboy_req:transport/1Loïc Hoguin
It was added to help with response body streaming functions. But it was a clumsy solution that we discarded in favor of passing socket and transport to said function. It was also very odd compared to the rest of the cowboy_req interface. If you used this function before, worry not, here's its proper equivalent. [Socket, Transport] = cowboy_req:get([socket, transport], Req)
2013-01-03Add middleware supportLoïc Hoguin
Middlewares allow customizing the request processing. All existing Cowboy project are incompatible with this commit. You need to change `{dispatch, Dispatch}` in the protocol options to `{env, [{dispatch, Dispatch}]}` to fix your code.
2012-12-22Cancel timer only on websocket_data receives or sendsJeremy Ong
This commit prevents erlang messages from keeping a websocket connection alive. Previously, the timer was canceled upon any activity. Now, the timeout is only canceled when actual data is sent from the client. The handler_loop_timeout/1 function is called from websocket_data/4 instead of handler_before_loop/4. It is also called after every successful reply in handler_call/4.
2012-12-13Make the arguments to error_logger more consistentAndrew Thompson
The purpose of this patch is to make the arguments cowboy passes to error_logger more consistent. With this patch there's only 3 variations on the error_logger argument list; a 5 element list, an 8 element list and a 10 element list. In all cases, the first 3 arguments are the Module, Function and Arity of the function being called and the second-to-last argument is always the Request. Additionally, for lists longer than 5 elements, the last argument is always the stack-trace. The added consistency of the argument ordering makes it much easier to write code in lager's error_logger handler to catch these messages and write a pretty one-liner (while writing the full message to the crash.log).
2012-12-08Add {close, StatusCode, Payload} and fix {close, Payload}Loïc Hoguin
2012-12-07Merge branch 'websocket_terminate_not_called' of git://github.com/dergraf/cowboyLoïc Hoguin
2012-12-06call websocket_terminate in case of a handshake errorAndre Graf
2012-12-05Make a few more missing headers lowercaseLoïc Hoguin
2012-12-02Add more frame types available in websocket repliesLoïc Hoguin
We can now reply empty close, ping and pong frames, or close frames with a payload. This means that we can send a frame and then close the connection in a single operation. If a close packet is sent, the connection is closed immediately, even if there was frames that remained to be sent. Cowboy will silently drop any extra frames in the list given as a reply.
2012-11-28Clarify error reports indicating they come from CowboyLoïc Hoguin
2012-11-27Check for errors when calling Transport:send in the websocket protocolAli Sabil
In some situations, the underlying socket might become "half-open" in which case the websocket will stay in a waiting state indefinitely. The detection of this state requires checking for errors when calling send.