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

99 commits

Author SHA1 Message Date
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
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
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
Magnus Klaar
973e67a53c add note to split_path/1 and path/1 on escaped / 2011-09-29 23:13:00 +02: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
Tom Burdick
b75859e075 Fail early in cookie-related API functions 2011-07-26 13:53:52 +02:00
Tom Burdick
5bd936db66 Implement cookies in cowboy_http_req 2011-07-26 13:53:31 +02:00
Loïc Hoguin
fa20273b37 URL decode query strings
Should be good for both GET and POST query strings.

This adds https://github.com/klaar/quoted.erl as a dependency.
Props to klaar for this code.
2011-07-20 17:38:10 +02:00
Loïc Hoguin
d363f91410 Fail fast when a wrong type is given to API functions
Idea given by bfrog, fixes issue #34.
2011-07-18 14:21:45 +02:00
Loïc Hoguin
108a491f55 Add documentation for the public interface.
This is probably not perfect yet but it should be better than
nothing. We'll improve things with feedback received from the
many users.
2011-07-06 17:42:20 +02:00
Loïc Hoguin
6b1fb5f390 Fix the @equiv EDoc tags 2011-06-30 01:11:11 +02:00
Loïc Hoguin
919fa638ee Add function cowboy_http_req:compact/1 to regain memory.
It removes all the non-essential data from the HTTP request record.
It allows some applications to make better use of their memory,
for example websockets which do not need to keep all the headers
information and can simply discard it using this function.
2011-06-01 12:49:03 +02:00
Loïc Hoguin
3e55cb62c9 Refresh the type specifications.
Following discussions on #erlounge.

Also fixes compilation in R14B03 and fixes a few underspecs
dialyzer warnings.
2011-05-25 23:02:40 +02:00
Loïc Hoguin
98b9b1124c Merge remote-tracking branch 'nox/path-info' 2011-05-16 12:08:55 +02:00
Loïc Hoguin
c7069e7fb9 Add the Server header in the HTTP replies. 2011-05-14 18:46:50 +02:00
Loïc Hoguin
95006c3291 Add the required Date header in the HTTP replies.
The formatted date is generated and kept up to date regularly
by a gen_server process storing it in the cowboy_clock ets table.
Then it is retrieved by other processes simply by reading the table.
2011-05-14 15:20:12 +02:00
Anthony Ramine
0ca8f1364b Implement path_info feature
The dispatcher now accepts '...' as the leading segment of Host and the
trailing segment of Path, this special atom matches any remaining path tail.

When given "cowboy.bugs.dev-extend.eu", host rule ['...', <<"dev-extend">>,
<<"eu">>] matches and fills host_info with [<<"cowboy">>, <<"bugs">>].

When given "/a/b/c/d", path rule [<<"a">>, <<"b">>, '...'] matches and fills
path_info with [<<"c">>, <<"d">>].
2011-05-09 15:14:38 +02:00
Loïc Hoguin
420f5baf98 Add chunked reply support.
Send the status line and headers using
cowboy_http_req:chunked_reply/3, and
individual chunks with cowboy_http_req:chunk/2.
2011-05-08 17:26:21 +02:00
Loïc Hoguin
18582a7a39 Separate building the response head from replying. 2011-05-08 14:40:58 +02:00
Anthony Ramine
48f7cd3a35 Allow atoms for response header names 2011-05-06 11:39:38 +02:00
Loïc Hoguin
29e71cf4da Switch the HTTP protocol to use binary packets instead of lists.
The server now does a single recv (or more, but only if needed)
which is then sent to erlang:decode_packet/3 multiple times. Since
most requests are smaller than the default MTU on many platforms,
we benefit from this greatly.

In the case of requests with a body, the server usually read at
least part of the body on the first recv. This is bufferized
properly and used when later retrieving the body.

In the case of pipelined requests, we can end up reading many
requests in a single recv, which are then handled properly using
only the buffer containing the received data.
2011-05-05 14:03:39 +02:00
Loïc Hoguin
6c1f73c53c Add cowboy_http_req:port/1.
Returns the port given in the Host header if present,
otherwise the default port of 443 for HTTPS and 80 for HTTP
is returned.
2011-05-04 12:52:13 +02:00
Loïc Hoguin
bb800ee0d9 Use http_headers() type in cowboy_http_req:headers/1. 2011-05-04 11:29:06 +02:00
Loïc Hoguin
e8286e18e6 Remove the include/types.hrl file. 2011-04-18 13:56:38 +02:00
Loïc Hoguin
63a92df14e Replace port_number() by ip_port() from kernel/include/inet.hrl. 2011-04-18 13:52:32 +02:00
Loïc Hoguin
731d839323 Replace posix() by atom(), for now.
The type isn't exported by OTP so we don't win much.
Also, inet.erl and file.erl define posix() différently,
so OTP needs to stop being so confuse in the first place
before we can attempt to use it properly.
2011-04-18 13:32:35 +02:00
Loïc Hoguin
2beb5c8206 Move the dispatcher related types into cowboy_dispatcher. 2011-04-18 13:24:27 +02:00
Loïc Hoguin
9ad32386c0 Use the inet:ip_address() type instead of the user-defined one. 2011-04-17 23:57:30 +02:00
Loïc Hoguin
7f35f693fc Fix specs for cowboy_http_req:reply/4.
Body is iodata(), not iolist().
2011-04-14 14:13:26 +02:00
Loïc Hoguin
c32db277c8 Fix a bug where dupe headers were sent in cowboy_http_req:reply/4.
Now the server defines default headers that can be overwritten by the
handler simply by passing them to the reply/4 function. Default headers
include, for now, Connection and Content-Length headers. Note that it isn't
enough to change the Connection header to close a keep-alive connection
server-side.
2011-04-14 01:32:02 +02:00
Anthony Ramine
101034842e Make the default value the last parameter of HTTP req accessors
This makes cowboy_http_req's qs_val/3, binding/3 and header/3 behave like
proplists:get_value/3.
2011-03-29 14:20:51 +02:00
Anthony Ramine
96a770620e Make HTTP req accessors call themselves with their default default value
Use lists:keyfind/3 in qs_val/3, binding/3 and header/3 and make qs_val/2,
binding/2 and header/2 call those.
2011-03-29 14:18:31 +02:00
Anthony Ramine
4eeabe5612 Fix cowboy_http_req:body with regard to the new accessors default value
header/2 now returns 'undefined' when the header isn't in the request.
2011-03-29 13:58:03 +02:00
Loïc Hoguin
150723ca21 Return undefined instead of failing or returning "" when a value doesn't exist. 2011-03-27 13:11:57 +02:00
Loïc Hoguin
71e940a6eb Fix query string related type specs in cowboy_http_req. 2011-03-27 01:09:47 +01:00
Loïc Hoguin
3865415a60 Boring 80-col change. 2011-03-22 13:23:40 +01:00
Loïc Hoguin
06274cd8ab Introduce cowboy_http_req:body_qs/1 for automated urlencoded body parsing. 2011-03-22 13:20:21 +01:00
Loïc Hoguin
775a03e6eb Fix spec for cowboy_http_req:parse_qs/1. 2011-03-22 13:19:38 +01:00
Loïc Hoguin
c645b682e7 Fix spec for cowboy_http_req:body/1 and body/2. 2011-03-22 13:18:53 +01:00
Loïc Hoguin
545116edfa Fix spec for cowboy_http_req:reply/4. 2011-03-21 22:47:37 +01:00
Loïc Hoguin
fdd9d4c0ef Fix spec for cowboy_http_req:qs_vals/1. 2011-03-21 22:33:42 +01:00
Loïc Hoguin
7cacb88fec Introduce cowboy_http_req:body/1 to read the full request body. 2011-03-21 22:08:27 +01:00
Loïc Hoguin
8b02992e6a Skip the request body if it hasn't been read by the handler. 2011-03-21 17:47:17 +01:00
Loïc Hoguin
71b31cee92 Make sure we can only reply to an HTTP request inside Handler:handle.
Of course since requests are a record the response state can be explicitly
overriden, but standard use prevents errors by making sure only one reply
is sent.
2011-03-20 18:03:36 +01:00
Loïc Hoguin
d69d0adfa7 Lazy-retrieve the peer name and port to avoid wasting time each request. 2011-03-20 16:09:05 +01:00
Loïc Hoguin
408f167621 Move the reply function to cowboy_http_req. 2011-03-18 22:38:26 +01:00
Loïc Hoguin
da72255940 Initial commit. 2011-03-17 00:29:35 +01:00