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

206 commits

Author SHA1 Message Date
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
3cfdf46e97 Remove a binary warning from websocket_data by removing a byte_size call. 2011-05-31 12:48:59 +02:00
Loïc Hoguin
ad2e905a81 Send a meaningful error to error_logger on websocket handler crashes.
Same as commit 4c4030a792 but for websockets.
See also issue #13 on github.
2011-05-27 12:32:02 +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
0720d6b9e3 Automatically start crypto, public_key and ssl if needed.
Following mochiweb and misultin's example here even though I'm not
too thrilled about starting them and not stopping but it's optional
and the application's author can start/stop them as normal anyway.
2011-05-24 20:52:19 +02:00
Loïc Hoguin
4c4030a792 Send a meaningful error to error_logger on handler crashes.
Inspired by gen_server and friends. Should fix issue #13.
2011-05-20 01:28:55 +02:00
Loïc Hoguin
98b9b1124c Merge remote-tracking branch 'nox/path-info' 2011-05-16 12:08:55 +02:00
Loïc Hoguin
9f06bac7bf Only try to update the Date field once every seconds. 2011-05-14 18:50:43 +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
Loïc Hoguin
5d698250b2 Add a max_connections transport option.
Limits the number of parallel requests processed at once.
Waiting requests are kept in the accept queue.
The limit is not explicitly observed, but it should be
around the given value at any time. Defaults to 1024.

Thanks to ostinelli's benchmark to point out the issue hopefully
solved by this and the previous commit.
2011-05-09 22:01:31 +02:00
Loïc Hoguin
b3d3045cae Increase the default backlog from 128 to 1024.
Improves reliability under heavy load.
2011-05-09 20:37: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
Anthony Ramine
094f5c1735 Remove a superfluous function clause in try_match 2011-05-09 13:06:47 +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
Anthony Ramine
9c155bfea7 Add cowboy_sup to the list of registered processes
Cowboy top supervisor has a name and it should be clearly stated in its
.app.src file.
2011-05-03 16:00:55 +02:00
Loïc Hoguin
65048fa657 Add backlog transport option.
This fixes issues with the http_load benchmark tool. The default backlog
option from OTP only queues up to 5 connections, which is way too low for
a fast-responding server.

Issue initially found thanks to DeadZen bugging me to test cowboy with
http_load. Fix found thanks to ostinelli's misultin already having the
backlog option which was the one thing it did differently than cowboy.
2011-04-30 22:26:56 +02:00
Loïc Hoguin
c044fa9602 Remove the next_request function always matching its first clause. 2011-04-30 01:14:57 +02:00
Loïc Hoguin
20293be912 Fix type specs for ssl:socket.
Should fix the warnings given by the Dialyzer-current build
over at http://dialyzer.softlab.ntua.gr/current/cowboy/

Thanks Kostis for the help.
2011-04-29 11:34:32 +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
db7833f5e8 Move the type application_start_type() into cowboy_app. 2011-04-18 13:27:42 +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
6712eaa5c8 Rename match() into match_rule(). 2011-04-18 12:20:52 +02:00
Loïc Hoguin
ef2673b61e Rename dispatch() into dispatch_rules(). 2011-04-18 12:14:13 +02:00
Loïc Hoguin
61d755f8cc Move the opaque type sslsocket() out of include/types.hrl. 2011-04-18 00:09:12 +02:00
Loïc Hoguin
15dc645596 Use the inet:socket() type instead of the user-defined one. 2011-04-18 00:06:26 +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
8f818d79df Add an accept timeout for code reloading.
Thought it was already there, but I guess not. Anyway it's here now
so everything is back to normal. ;)
2011-04-16 13:59:30 +02:00
Loïc Hoguin
d4985dd72b SSL transport uses sslsocket(), not plain socket(). 2011-04-14 23:42:03 +02:00
Loïc Hoguin
cb60d18e82 Initial draft-hixie-thewebsocketprotocol-76 support. 2011-04-14 21:21:17 +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
Loïc Hoguin
4048499af2 Add a test case for cowboy_dispatcher:match/3.
Added it while debugging an issue, so why not keep it?
2011-04-14 01:10:57 +02:00
Loïc Hoguin
bc99200bae Add a Transport:messages/0 function to obtain the atoms sent in active mode.
That way we can support active mode without having to hardcode the atoms
for each transports available.
2011-04-12 16:27:44 +02:00
Loïc Hoguin
73b120b68e Fix a pattern matching bug in cowboy_http_protocol:handler_init/2. 2011-04-12 16:22:46 +02:00
Loïc Hoguin
6ec20b736e Limit the number of empty lines to allow before the request-line.
Defaults to 5. Prevents someone from indefinitely sending empty lines.
2011-04-09 15:28:41 +02:00
Loïc Hoguin
4cbba84a00 Discard the port from the host before tokenizing it. 2011-04-08 12:12:46 +02:00
Loïc Hoguin
0fad6c6fde Don't crash on errors while receiving headers; throw an error 500 instead.
The server shouldn't crash the request process when we have an error
while receiving headers. A case where this could happen is if the header
line is too long.

See also bfrog's report on ticket #3 on github.
2011-04-07 00:54:32 +02:00
Loïc Hoguin
d8a2fcf258 Don't automatically retrieve the peer information for the 'OPTIONS' method. 2011-04-05 20:09:49 +02:00
Loïc Hoguin
44e6f60b91 Handle properly the default Connection value for HTTP/1.0.
Fixes a bug reported by evaxsoftware on IRC.
2011-04-05 20:07:52 +02:00
Loïc Hoguin
04a5aa7c5c Add initial SSL transport support.
Code is working but hasn't been benchmarked yet.
2011-04-03 18:35:35 +02:00
Loïc Hoguin
a8af32c54b Don't ignore the return values in cowboy:stop_listener/1. 2011-04-03 15:21:29 +02:00
Loïc Hoguin
ccf7a242b4 Ensure the listening socket gets closed with the listener supervisor.
Moved the Transport:listen call to cowboy_acceptors_sup. This make it
depend on a child of cowboy_listener_sup instead of cowboy_sup, which
isn't getting shut down when calling cowboy:stop_listener/1 and thus
didn't close the listening socket.
2011-04-03 01:44:52 +02:00