0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-15 12:40:25 +00:00
Commit graph

56 commits

Author SHA1 Message Date
Loïc Hoguin
8cc353114e Update specs that were too wide 2014-06-30 17:36:43 +02:00
Loïc Hoguin
17af50812c Remove outdated comments, all edoc, plus a few minor tweaks 2014-03-26 19:05:59 +01:00
Loïc Hoguin
8993249e42 Fix typespecs of cowboy_websocket:handler_terminate
Pointed out during the ConcuError tutorial by Kostis. Thanks! :-)
2014-03-08 19:51:39 +01:00
Loïc Hoguin
903594bb87 Update copyright years 2014-02-06 19:57:23 +01:00
Loïc Hoguin
0d5a12c3ec Merge branch 'fix-ws-atom-responses' of git://github.com/seriyps/cowboy 2013-08-27 18:21:03 +02:00
Loïc Hoguin
b22f25d902 Merge branch 'websocket-compressed-metadata' of git://github.com/irccloud/cowboy 2013-08-27 18:10:51 +02:00
Loïc Hoguin
bbee34fe16 Crash on failure, don't report errors
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-24 20:36:23 +02:00
RJ
83d85e641a add websocket_compress metadata 2013-08-15 10:47:18 +01:00
Sergey Prokhorov
01d30568dd Allow atom responses in websocket handlers #563 2013-08-13 23:29:16 +04:00
Ali Sabil
c5c9c398ff Use the proper typespec for the websocket_deflate_frame rsv bits 2013-07-08 09:49:35 +02:00
Ali Sabil
6f0b8804bc Fix handling of websocket fragmented deflated frames 2013-07-02 13:46:28 +02:00
Ali Sabil
a3b9438d16 Fix websocket unmasking when compression is enabled
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-02 13:46:28 +02:00
Ali Sabil
373f2e8134 Fix coding style in websocket_deflate_frame/3 2013-07-02 11:02:32 +02:00
Ali Sabil
4edef3c45c Remove usage of the inflate buffer 2013-07-02 10:58:12 +02:00
Loïc Hoguin
9eaee45c09 Fix compilation < R16B01 2013-06-20 18:44:36 +02:00
Loïc Hoguin
11493a40f1 Ignore deprecation warning for crypto:sha/1 for now
We can change this call when we start supporting only R16B+,
which may happen when R17B is released or some time before.
2013-06-20 16:01:58 +02:00
Ali Sabil
a63faff35e Add support for the webkit deflate frame extension 2013-06-20 13:09:13 +02:00
Loïc Hoguin
7577ce4920 Fix the cowboy_websocket:frame/0 type
It accepts iodata() and not binary() for the payload.
2013-05-15 14:53:45 +02:00
Loïc Hoguin
2b56bb498f Update Ranch to 0.8.0 2013-04-03 13:47:12 +02:00
James Fish
6d67ad809c Add sub protocol behaviour 2013-02-16 16:19:53 +00:00
Loïc Hoguin
e3daf439da Properly pass the handler's state to websocket_terminate/3 on close 2013-02-14 19:26:46 +01:00
Adam Cammack
7f0c6bbb39 Make cowboy_websocket.erl compile with +native
Worked until cccc0bc
2013-02-13 11:32:35 -06:00
Loïc Hoguin
65ed13d2da Do not reset the connection timeout timer on send
Sends can be successful even if the connection is gone.
2013-02-09 21:46:05 +01:00
Loïc Hoguin
638638a841 Fix {cowboy_req, resp_sent} potentially leaking in loop handlers 2013-01-29 14:35:26 +01:00
Loïc Hoguin
cd680706cd Add cowboy_websocket:close_code/0
Also fixes a warning.
2013-01-17 16:22:05 +01:00
Loïc Hoguin
8d69099508 Improve websocket close handling
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-14 16:20:33 +01:00
Loïc Hoguin
5dd09737d0 Websocket text frames are now checked for UTF-8 correctness
The autobahntestsuite now passes 100% of the tests. We are
getting close to fully implementing the Websocket RFC.
2013-01-13 00:10:32 +01:00
Loïc Hoguin
cccc0bc475 Unmask websocket frames on the fly and optimize the code
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-12 22:31:23 +01:00
Loïc Hoguin
71b68d53d9 All frames sent from client to server MUST be masked
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-12 16:04:35 +01:00
Loïc Hoguin
10e3692fa6 Remove support for Websocket hixie76 draft
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-10 21:58:38 +01:00
Loïc Hoguin
c930327fbf Remove cowboy_req:transport/1
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-05 22:04:52 +01:00
Loïc Hoguin
1b3f510b7e Add middleware support
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.
2013-01-03 22:47:51 +01:00
Jeremy Ong
5f122d9fa6 Cancel timer only on websocket_data receives or sends
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-22 18:32:15 +01:00
Andrew Thompson
d916d739d4 Make the arguments to error_logger more consistent
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-13 03:38:38 -05:00
Loïc Hoguin
6d4e15705f Add {close, StatusCode, Payload} and fix {close, Payload} 2012-12-08 19:11:56 +01:00
Loïc Hoguin
d2ccd2e090 Merge branch 'websocket_terminate_not_called' of git://github.com/dergraf/cowboy 2012-12-07 16:35:40 +01:00
Andre Graf
ae2a6cfb68 call websocket_terminate in case of a handshake error 2012-12-06 23:02:15 +01:00
Loïc Hoguin
db6b1596ae Make a few more missing headers lowercase 2012-12-05 13:43:25 +01:00
Loïc Hoguin
067958abd2 Add more frame types available in websocket replies
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-12-02 21:37:24 +01:00
Loïc Hoguin
45dd67741f Clarify error reports indicating they come from Cowboy 2012-11-28 18:30:53 +01:00
Ali Sabil
9b0049fdd7 Check for errors when calling Transport:send in the websocket protocol
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.
2012-11-27 13:45:25 +01:00
Loïc Hoguin
09914c4693 Allow websocket handlers to reply more than one frame
Instead of returning {text, Data}, you can now return
[{text, Data}, {text, Data2}, ...].
2012-10-11 21:46:43 +02:00
Loïc Hoguin
aeb86e70c1 Add crypto into the required applications
As suggested by @prof3ta.
2012-10-11 20:13:23 +02:00
Loïc Hoguin
34021666cb Don't use decode_packet/3 for parsing the headers
Header names are now binaries. Since header names are case insensitive
they are all converted to lowercase. For example: <<"content-length">>.

The max_line_length option was removed. Three new options have been
added instead:

 *  max_request_line_length (defaults to 4096)
 *  max_header_name_length (defaults to 64)
 *  max_header_value_length (defaults to 4096)
2012-09-21 09:18:56 +02:00
Loïc Hoguin
8d5f8db90a Improve consistency of return types for cowboy_req API
The signature of parse_header, body_qs, multipart_data and
the set_resp_* functions has changed.

See the cowboy_req module edoc for more details.
2012-09-17 13:56:58 +02:00
Loïc Hoguin
9ef94fb64e Introduce cowboy_req:set_meta/3 to set request metadata 2012-09-15 22:51:37 +02:00
Loïc Hoguin
0aaa717575 Remove duplicate code for ensure_response 2012-09-15 22:19:39 +02:00
Loïc Hoguin
27d591180c Add cowboy_req:url/1 to return the full request URL
Use it in cowboy_websocket for hixie76, replacing http by ws.
2012-09-15 22:03:00 +02:00
Loïc Hoguin
cd54214def Avoid a duplicate HTTP reply in cowboy_websocket:upgrade_error/1
Do this by checking whether we received the resp_sent message.
2012-09-15 21:18:53 +02:00
Loïc Hoguin
35ebe0b108 Put socket and transport into cowboy_websocket's #state{}
As part of the work to make cowboy_req:req() opaque.
2012-09-15 21:09:12 +02:00