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

218 commits

Author SHA1 Message Date
Loïc Hoguin
e2b5c21443 Drop R15 support 2014-07-12 14:19:29 +02:00
Loïc Hoguin
97a3108576 Reply with 400 on header parsing crash
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-07-12 12:09:43 +02:00
Loïc Hoguin
5d1d9af6cd Add a return value to onresponse hook to override status/headers
This would allow us to override them without messing up the body,
and would make it usable with the static file handler for example.

Experimental at this point.
2014-06-03 18:31:05 +02:00
Loïc Hoguin
0c37925642 Add request body reading options
The options were added to allow developers to fix timeout
issues when reading large bodies. It is also a cleaner and
easier to extend interface.

This commit deprecates the functions init_stream, stream_body
and skip_body which are no longer needed. They will be removed
in 1.0.

The body function can now take an additional argument that is a
list of options. The body_qs, part and part_body functions can
too and simply pass this argument down to the body call.

There are options for disabling the automatic continue reply,
setting a maximum length to be returned (soft limit), setting
the read length and read timeout, and setting the transfer and
content decode functions.

The return value of the body and body_qs have changed slightly.
The body function now works similarly to the part_body function,
in that it returns either an ok or a more tuple depending on
whether there is additional data to be read. The body_qs function
can return a badlength tuple if the body is too big. The default
size has been increased from 16KB to 64KB.

The default read length and timeout have been tweaked and vary
depending on the function called.

The body function will now adequately process chunked bodies,
which means that the body_qs function will too. But this means
that the behavior has changed slightly and your code should be
tested properly when updating your code.

The body and body_qs still accept a length as first argument
for compatibility purpose with older code. Note that this form
is deprecated and will be removed in 1.0. The part and part_body
function, being new and never having been in a release yet, have
this form completely removed in this commit.

Again, while most code should work as-is, you should make sure
that it actually does before pushing this to production.
2014-06-02 23:09:43 +02:00
Loïc Hoguin
0502452967 Update cowlib to 0.6.1 2014-03-27 11:39:09 +01: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
d4ce3c638d Use the new chunked and identity transfer decoding code from cowlib 2014-03-24 14:24:52 +01:00
Loïc Hoguin
dbf7b1c5e5 Use cow_http_hd:parse_transfer_encoding/1 where applicable 2014-03-24 14:24:52 +01:00
Loïc Hoguin
dff1b5715c Use cow_http_hd:parse_content_length/1 where applicable 2014-03-24 14:24:52 +01:00
Loïc Hoguin
2629f70ef3 Use cow_http_hd:parse_connection/1 where applicable 2014-03-24 14:24:46 +01:00
Loïc Hoguin
917cf99e10 Add and document the new multipart code
The old undocumented API is removed entirely.

While a documentation exists for the new API, it will not
be considered set in stone until further testing has been
performed, and a file upload example has been added.

The new API should be a little more efficient than the
old API, especially with smaller messages.
2014-02-06 19:36:25 +01:00
Loïc Hoguin
7a274661b2 Fix typespecs for cowboy_req:binding/{2,3} and :bindings/1 2013-12-28 20:10:06 +01:00
Loïc Hoguin
a0205779fe Remove an unnecessary clause in cowboy_req:body/2 2013-11-09 18:08:54 +01:00
Adrian Roe
c2e946708e Add a workaround to disable chunked transfer-encoding
This is an undocumented workaround to disable chunks when using HTTP/1.1.
It can be used when the client advertises itself as HTTP/1.1 despite not
understanding the chunked transfer-encoding.

Usage can be found looking at the test for it. When activated, Cowboy
will still advertise itself as HTTP/1.1, but will send the body the same
way it would if it was HTTP/1.0.
2013-11-08 21:56:37 +01:00
Loïc Hoguin
8d546dacbc Optimize query string parsing
*  Parsing code was moved to cowlib: cowboy_qs:parse_qs/1
 *  A function was added to build query strings: cowboy_qs:qs/1
 *  Also added cowboy_qs:urlencode/1 and cowboy_qsurldecode/1
2013-11-08 18:47:05 +01:00
Loïc Hoguin
faf64524c6 Move cookie parsing/building code to cowlib
The code for parsing has also been rewritten to be more efficient
and to be able to handle cookie values with space inside them properly.

Update cowlib to 0.2.0.
2013-10-23 16:35:23 +02:00
Loïc Hoguin
bfb6db1eab Simpler code for sending errors following crashes 2013-08-24 20:21:05 +02:00
pmyarchon
95c915dfaa Slight docs fix in cowboy_req.erl 2013-07-18 12:16:03 +04:00
Ali Sabil
a63faff35e Add support for the webkit deflate frame extension 2013-06-20 13:09:13 +02:00
Ali Sabil
ba1eca6b97 Avoid crashing in cowboy_req on invalid Accept-Encoding header
Certain clients send malformed Accept-Encoding headers, which causes
cowboy_req to crash is compression is enabled.
2013-06-10 15:22:05 +02:00
Loïc Hoguin
c1a1fd125d Don't crash on empty Cookie header
It's not allowed, however a heavily deployed client (Flash player)
can send such an empty header, therefore we make a special condition
for it and return an empty list when it happens.
2013-05-31 18:59:52 +02:00
Loïc Hoguin
9a2d35c2e8 Add experimental and incomplete SPDY support
The SPDY connection processes are also supervisors.

Missing:
 *  sendfile support
 *  request body reading support
2013-05-30 20:21:01 +02:00
Loïc Hoguin
1d413ea51b Move cowboy_protocol:onresponse_fun() to cowboy:onresponse_fun() 2013-05-16 17:01:38 +02:00
Loïc Hoguin
df73a4d0a5 Move cowboy_http:status() to cowboy:http_status() 2013-05-16 16:29:24 +02:00
Loïc Hoguin
f8a7856127 Move cowboy_http:headers() to cowboy:http_headers() 2013-05-16 16:16:32 +02:00
Loïc Hoguin
c0c333e41b Move cowboy_http:version() to cowboy:http_version() 2013-05-16 16:06:52 +02:00
Loïc Hoguin
ba7e6c07ec Improve the specs for cowboy_req:init_stream/4 2013-05-16 15:54:30 +02:00
Loïc Hoguin
28186a68d0 Make the HTTP version type more practical
Now instead of {1, 1} we have 'HTTP/1.1', and instead of {1, 0}
we have 'HTTP/1.0'. This is more efficient, easier to read in
crash logs, and clearer in the code.
2013-05-16 12:56:01 +02:00
Loïc Hoguin
e0b5526f1e Remove cowboy_req:fragment/1
Clients do not send it. We skip the value if we receive it now,
as it shouldn't happen, and won't for all the mainstream clients.
2013-05-15 15:17:33 +02:00
Loïc Hoguin
a45787208e Fix two incorrect comments in cowboy_req 2013-05-15 14:53:28 +02:00
Loïc Hoguin
76c6aa2183 The cookie value can only be binary() 2013-05-15 14:50:40 +02:00
Loïc Hoguin
c582335c5b The return value of cowboy_req:peer/1 is never undefined 2013-05-15 14:49:44 +02:00
James Fish
c8242ab396 Add chunked response body fun
Adds a new type of streaming response fun. It can be set in a similar
way to a streaming body fun with known length:

Req2 = cowboy_req:set_resp_body_fun(chunked, StreamFun, Req)

The fun, StreamFun, should accept a fun as its single argument. This
fun, ChunkFun, is used to send chunks of iodata:

ok = ChunkFun(IoData)

ChunkFun should not be called with an empty binary or iolist as this
will cause HTTP 1.1 clients to believe the stream is over. The final (0
length) chunk will be sent automatically - even if it has already been
sent - assuming no exception is raised.

Also note that the connection will close after the last chunk for HTTP
1.0 clients.
2013-04-26 21:02:10 +01:00
Loïc Hoguin
9bc276df3b Merge branch 'range_header' of git://github.com/Egobrain/cowboy 2013-04-26 15:48:06 +02:00
Egobrain
2f40a69c11 Added range header parser 2013-04-26 17:46:32 +04:00
Egobrain
3bf5b46786 Removed asserts from unit tests 2013-04-26 17:08:53 +04:00
Loïc Hoguin
cf0e005894 Fix an outdated comment 2013-04-22 14:54:22 +02:00
Loïc Hoguin
6256429dc9 Remove cowboy_req:peer_addr/1
This kind of function is highly dependent on the proxy used,
therefore parsing was added for x-forwarded-for instead and we
just let users write the function that works for them. The code
can be easily extracted if anyone was using the function.
2013-04-11 22:25:36 +02:00
Loïc Hoguin
67beb4d01d Parse the x-forwarded-for header as a list of tokens 2013-04-11 22:25:36 +02:00
Loïc Hoguin
be94cb12aa Shorten the parse_header clauses 2013-04-11 22:25:35 +02:00
Loïc Hoguin
bd9c3df6d0 No need for fully qualified call to the same module 2013-04-11 22:25:31 +02:00
Loïc Hoguin
53a48b254f Switch the arguments to cowboy_req:stream_body/2
Make them consistent with the rest of the module.
2013-04-09 19:47:14 +02:00
Loïc Hoguin
ce1d8862c0 Replace init_stream/5 with stream_body/2
This allows us to change the max chunk length on a per chunk basis
instead of for the whole stream. It's also much easier to use this
way even if we don't want to change the chunk size.
2013-04-02 19:40:38 +02:00
rambocoder
84d7671e91 Check the length before reading the body in body/1 and body_qs/1 2013-03-06 08:50:45 -05:00
Loïc Hoguin
233cf43ab9 Make streamed chunk size configurable
Defaults to a maximum of 1000000 bytes.

Also standardize the te_identity and te_chunked decoding functions.
Now they both try to read as much as possible (up to the limit),
making body reading much faster when not using chunked encoding.
2013-03-05 21:54:35 +01:00
Loïc Hoguin
55e98f4f61 Handle identity transfer-encoding when determining body length 2013-03-05 14:08:44 +01:00
Egobrain
73c718dcb5 Added warn compile options. Fixed compile warnings. 2013-02-21 18:32:23 +04:00
0xAX
1de2e1f2a4 cowbot_req:has_body:/1 improved 2013-02-14 18:56:52 +06:00
Loïc Hoguin
20329a6e9e Fix connection state being ignored for unknown length streaming 2013-02-12 17:15:11 +01:00
Loïc Hoguin
40b8d0befc Better handle socket closing with loop handlers
We now read from the socket to be able to detect errors or TCP close
events, and buffer the data if any. Once the data receive goes over
a certain limit, which defaults to 5000 bytes, we simply close the
connection with an {error, overflow} reason.
2013-02-11 09:03:13 +01:00