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

40 commits

Author SHA1 Message Date
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
Loïc Hoguin
bb4bd9ac96 Add a cowboy_req:to_list/1 function
Removes a lot of duplicate code when printing error messages.
2012-09-15 20:33:57 +02:00
Loïc Hoguin
9b5cbb5000 Remove two unneeded Req modifications 2012-09-15 12:56:45 +02:00
Loïc Hoguin
d9e76d59a1 Change type #http_req{} to cowboy_req:req()
This removes cowboy_static's dependency on http.hrl.
2012-09-15 01:31:51 +02:00
Loïc Hoguin
79839b7bb5 Replace cowboy_req:path/1 with cowboy_req:raw_path/1
The latter is much more useful than the former, which ends up
being removed.
2012-09-10 12:26:04 +02:00
Loïc Hoguin
6fa734b487 Replace cowboy_req:host/1 with cowboy_req:raw_host/1
The latter is much more useful than the former, which ends up
being removed.
2012-09-10 12:25:57 +02:00
Loïc Hoguin
0e3adf1fee Rename cowboy_http_websocket to cowboy_websocket 2012-08-27 14:00:28 +02:00
Renamed from src/cowboy_http_websocket.erl (Browse further)