0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 20:30:23 +00:00
Commit graph

2127 commits

Author SHA1 Message Date
Loïc Hoguin
a55d1966f4 Bump quoted to version 1.2.0 2011-10-11 10:21:59 +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
5e006be01f Add support for loops in standard HTTP handlers
Now init/3 can return one of the following values to enable loops:
 - {loop, Req, State}
 - {loop, Req, State, hibernate}
 - {loop, Req, State, Timeout}
 - {loop, Req, State, Timeout, hibernate}

Returning one of these tuples will activate looping in the HTTP handler.
When looping, handle/2 is never called. Instead, Cowboy will listen
for Erlang messages and forward them to the info/3 function of the
handler. If a timeout is defined, Cowboy will also close the connection
when no message has been received for Timeout milliseconds.

The info/3 function is defined as info(Msg, Req, State). It can return
either of the following tuples:
 - {ok, Req, State}
 - {loop, Req, State}
 - {loop, Req, State, hibernate}

The first one ends the connection, calling terminate/2 before closing.
The others continue the loop.

Loops are useful when writing long-polling handlers that need to wait
and don't expect to receive anything. Therefore it is recommended to
set a timeout to close the connection if nothing arrives after a while
and to enable hibernate everywhere.

Normal HTTP handlers shouldn't need to use this and as such info/3
was made optional.
2011-10-10 17:27:52 +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
7774e64923 Add *.swp to gitignore 2011-10-10 08:52:11 +02:00
Loïc Hoguin
dbc577e69b Merge remote-tracking branch 'jlouis/issue-71' 2011-10-10 08:20:48 +02:00
Jesper Louis Andersen
a800425131 Add cowboy:child_spec/6
This new exported function returns a Child Spec suitable for embedding
cowboy in another applications supervisor structure. While here,
implement `start_listener/6` in terms of it.
2011-10-10 08:18:26 +02:00
Loïc Hoguin
fd786ef233 Fix a crash in response_connection when Name is an atom =/= 'Connection' 2011-10-07 16:14:39 +02:00
Loïc Hoguin
138cccb4f9 Allow HTTP handlers to skip the handle/2 step in init/3
You can now return {shutdown, Req, State} from Handler:init/3
to skip the handle/2 step.

Also allow init/3 function to send responses.
2011-10-06 15:54:37 +02:00
Loïc Hoguin
5740a9671e Add R14B to the travis-ci configuration file 2011-10-06 13:25:39 +02:00
Loïc Hoguin
245434a54d Add R14B04 to the travis-ci configuration file 2011-10-06 13:21: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
8e835bce9f Close the connection when the application sends Connection: close
Now Cowboy checks headers sent to the client for the 'Connection'
header value, parses it, and checks whether it contains a 'close'
or 'keep-alive' value. It makes sure to close or keep the connection
alive depending on the value found there, if any.

Also change chunked replies to not close the connection by default
unless the application requests it.
2011-10-06 12:40:04 +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
97460a5993 Fix a crash in websocket_handshake when cowboy_http_req:compact/1 is used
Also add a call to compact/1 in the websocket test handler so we may
catch bugs related to it faster later on.
2011-10-06 01:07:49 +02:00
Loïc Hoguin
c2be0f2073 Remove the 'HEAD' chunked_reply/3 clause
From the RFC:
  The HEAD method is identical to GET except that the server MUST NOT
  return a message-body in the response. The metainformation contained
  in the HTTP headers in response to a HEAD request SHOULD be identical
  to the information sent in response to a GET request.
2011-10-05 18:30:23 +02:00
Loïc Hoguin
8eb7af0a0b Skip deps when generating docs 2011-10-05 16:06:50 +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
Loïc Hoguin
9a775cce3c Move a few binary string handling functions to cowboy_bstr 2011-10-04 18:34:14 +02:00
Loïc Hoguin
ee77ecec92 Remove the connection information from the HTTP protocol state
Use the Req connection information instead.
2011-10-04 13:09:57 +02:00
Loïc Hoguin
547107cfb9 Close connection on all errors
And use a proper cowboy_http_req:reply/4 call for the 204 response.
2011-10-04 12:37:19 +02:00
Loïc Hoguin
148fb949c5 Small doc clarification 2011-10-04 11:27:04 +02:00
Loïc Hoguin
d25c30790c Do not send a 408 response if the Request-Line wasn't fully received
The server should not send a response if there wasn't at least
the beginning of a request sent (the Request-Line).
2011-10-04 10:54:30 +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
Loïc Hoguin
b79e9fbeb4 Get rid of a binary construct in cowboy_http_req
Thanks to @klaar for pointing it out in ticket #59.
2011-10-01 18:54:43 +02:00
Loïc Hoguin
ce26d7090b Rename the type cowboy_dispatcher:path_tokens/0 to :tokens/0 2011-10-01 02:32:20 +02:00
Loïc Hoguin
6572d4d374 Merge branch 'path-split-doc' of https://github.com/klaar/cowboy 2011-10-01 02:24:38 +02:00
Loïc Hoguin
76f855ebd0 Merge branch 'master' of https://github.com/hakvroot/cowboy 2011-10-01 02:10:10 +02:00
Michiel Hakvoort
d8e841c8a2 Add cowboy_protocol behaviour 2011-09-30 08:49:58 +02:00
Magnus Klaar
973e67a53c add note to split_path/1 and path/1 on escaped / 2011-09-29 23:13:00 +02:00
Loïc Hoguin
eff9477201 Improve the error message for HTTP handlers
Making it look more like the websocket handler error messages.
2011-09-28 18:01:35 +02:00
Loïc Hoguin
0e84e7f920 Merge remote-tracking branch 'smarkets/cacertfile' 2011-09-28 15:02:08 +02:00
Steven Gravell
ea5780b7cd add cacertfile configuration 2011-09-28 13:40:09 +01:00
Loïc Hoguin
b675fb2ab1 Merge remote-tracking branch 'nivertech/master' 2011-09-26 19:59:44 +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
89ae3c8cad 'Host' header is optional in HTTP/1.0
Krishnamurthy, Kristol, Mogul: "Key Differences between HTTP/1.0
and HTTP/1.1", "Internet address conservation".
http://www8.org/w8-papers/5c-protocols/key/key.html

Fixes issue #35 reported by Alex Kropivny.
2011-09-14 01:45:12 +02:00
Loïc Hoguin
b669b1b5a3 Reset the max number of empty lines between keepalive requests
Fixes issue #47.
2011-09-13 23:41:34 +02:00
Loïc Hoguin
961526d704 Improve the Cowboy definition in the README 2011-09-13 23:10:41 +02:00
Loïc Hoguin
55ba8dc4da Merge pull request #46 from tillitech/master
Fix the handling of HEAD requests
2011-09-06 03:24:53 -07:00
Ali Sabil
bb469f6c3d Fix the handling of the HEAD requests
Responses to the HEAD requests used to include an response body.
2011-09-06 12:11:44 +02:00
Loïc Hoguin
8bb7472fb0 Update version to 0.3.0 to continue with development 2011-09-05 15:51:53 +02:00
Loïc Hoguin
009ad4c9eb Update version to 0.2.0 2011-09-05 15:45:19 +02:00
Loïc Hoguin
2a25ad6c24 Update AUTHORS file 2011-09-05 15:41:13 +02:00
Loïc Hoguin
a1d6c2e66f Tweak the .travis.yml file
We want to run 'make tests' and not that rebar command.
Also remove R14B as quoted doesn't work with it.
2011-09-05 14:22:36 +02:00
Loïc Hoguin
24f3981377 Add .travis.yml file 2011-09-05 14:14:30 +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
24bf2c54d0 Ensure header names are handled in a case insensitive manner
To this end we are formatting the header names just like OTP does
except we do it for names of up to 32 characters, as there are
widely used header names of more than 20 characters, the limit that
OTP follows currently. An example of such header name would be
Sec-Websocket-Version.

The formatting itself is fairly simple: an uppercase character at
the start and after dashes, everything else lowercase.
2011-08-23 16:20:53 +02:00