aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http_protocol.erl
AgeCommit message (Collapse)Author
2012-02-02Added absoluteURI supportDavid Kelly
If requests go through a proxy, they will have the original uri in the request, i.e. : GET http://proxy.server.uri/some/query/string HTTP 1.1 ... That was problematic -- cowboy_http_protocol:request didn't know what to to with the result of decode_packet applied to this, which would be something like: ``` erlang {http_request,'GET',{absoluteURI,http,<<"proxy.server.uri">>, undefined,<<"/some/query/string">>},{1,1}} ``` So, I just ignore the host, grab the path and pass into ``` erlang cowboy_http_protocol:request({http_request, Method, {abs_path, Path}, Version}, State) ``` Seems to do the trick without much effort.
2012-02-02Apply a trick to the erlang:hibernate calls to suppress dialyzer warningsLoïc Hoguin
Initially recommended by Magnus Klaar, the trick is to add a catch instruction before the erlang:hibernate/3 call so that Dialyzer thinks it will return, followed by the expected return value ('ok' for HTTP, 'closed' for websockets). This should be good enough until a real solution is found.
2012-01-23Fix a case where request body wouldn't get cleaned up on keepaliveLoïc Hoguin
The body was still in the buffer that's being used for the next request and was thus used as a request, causing errors.
2012-01-23Rename the type http_status/0 to cowboy_http:status/0Loïc Hoguin
2012-01-23Rename the type http_header/0 to cowboy_http:header/0Loïc Hoguin
At the same time rename http_headers/0 to cowboy_http:headers/0.
2012-01-23Rename the type http_version/0 to cowboy_http:version/0Loïc Hoguin
2012-01-23Rename the type http_uri/0 to cowboy_http:uri/0Loïc Hoguin
2012-01-23Rename the type http_method/0 to cowboy_http:method/0Loïc Hoguin
Exported types are much better than include files.
2012-01-23Merge branch 'multipart' of https://github.com/nox/cowboyLoïc Hoguin
Conflicts: src/cowboy_http_req.erl test/http_SUITE.erl
2012-01-23Add multipart supportAnthony Ramine
2012-01-06Fix handler crashes handlingLoïc Hoguin
We try to send a 500 error only if we didn't send the response headers yet. If they were, then we have no way to be sure the response was fully sent, nor should we assume anything about how this will be handled client-side, so we do nothing more and in both cases close the connection.
2012-01-06Move the ensure_response call before ensure_body_processedLoïc Hoguin
We want to reply as soon as possible.
2011-12-22Remove outdated @todo notes and update anotherLoïc Hoguin
2011-12-22Add a max_keepalive HTTP protocol optionLoïc Hoguin
Based on the patch by Louis-Philippe Gauthier.
2011-12-15Reply status 400 if we receive an unexpected value or error for headersLoïc Hoguin
2011-12-15Add cowboy:accept_ack/1 for a cleaner handling of the shoot messageLoïc Hoguin
2011-12-08Allow HTTP protocol upgrades to use keepaliveLoïc Hoguin
REST needed this to be allowed to chain requests on the same connection.
2011-12-07replace quoted:from_url with cowboy_http:urldecodeMagnus Klaar
This change makes the dependency on quoted optional by adding a minimal urldecode function to cowboy. A protocol option for setting the urldecoding function has been added to the cowboy_http_protocol module. The default value for this option is set to be equivalent to the default settings for quoted. {fun cowboy_http:urldecode/2, crash} A note has been added in the README to document how to use quoted instead of this function. A field to store this option value has been added to the state record in the cowboy_http_protocol module and the http_req record in include/http.hrl Functions that previously used quoted:from_url/1 has been updated to require an equivalent function in addition to the previously required arguments. This change removes a C compiler from the build requirements of cowboy. It also removes the requirement to cross compile the code if the target arch/OS is different from the arch/OS used to build it.
2011-12-06cowboy_http_protocol shouldn't crash if the client sends HTTP responsesLoïc Hoguin
It was replying back the correct error, but with a crash message in the console. This patch prevents it from crashing. Fixes issue #94 reported by oribrost.
2011-10-26Add 'Accept' header parsingLoïc Hoguin
Rework the cowboy_http_req:parse_header/2 function while I was at it.
2011-10-19Add a max_line_length to the HTTP protocolLoïc Hoguin
Allows to limit the size of request and header lines, thus preventing Cowboy from infinitely reading from the socket and never finding an end of line. Defaults to 4096 bytes.
2011-10-11Fix a misnamed variable for {loop, ...} returns in init/3Loïc Hoguin
2011-10-11Fix specs after erlang:hibernate/3 calls were addedLoïc Hoguin
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-10Add support for loops in standard HTTP handlersLoïc Hoguin
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-06Allow HTTP handlers to skip the handle/2 step in init/3Loïc Hoguin
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-05Remove the 'HEAD' chunked_reply/3 clauseLoïc Hoguin
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-05Parse 'Connection' headers as a list of tokensLoïc Hoguin
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-04Move a few binary string handling functions to cowboy_bstrLoïc Hoguin
2011-10-04Remove the connection information from the HTTP protocol stateLoïc Hoguin
Use the Req connection information instead.
2011-10-04Close connection on all errorsLoïc Hoguin
And use a proper cowboy_http_req:reply/4 call for the 204 response.
2011-10-04Small doc clarificationLoïc Hoguin
2011-10-04Do not send a 408 response if the Request-Line wasn't fully receivedLoïc Hoguin
The server should not send a response if there wasn't at least the beginning of a request sent (the Request-Line).
2011-09-30Add cowboy_protocol behaviourMichiel Hakvoort
2011-09-28Improve the error message for HTTP handlersLoïc Hoguin
Making it look more like the websocket handler error messages.
2011-09-14'Host' header is optional in HTTP/1.0Loïc Hoguin
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-13Reset the max number of empty lines between keepalive requestsLoïc Hoguin
Fixes issue #47.
2011-08-23Ensure header names are handled in a case insensitive mannerLoïc Hoguin
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-10Give the ListenerPid to the protocol on startupLoïc Hoguin
Also sends a message 'shoot' that can be received by the protocol to make sure Cowboy has had enough time to fully initialize the socket. This message should be received before any socket-related operations are performed. WebSocket request connections are now moved from the pool 'default' to the pool 'websocket', meaning we can have a lot of running WebSockets despite having a low 'max_connections' setting.
2011-07-07Call Handler:terminate/2 even on error in Handler:handle/2Loïc Hoguin
This ensures we can cleanup what we did in Handler:init/3.
2011-07-06Move recursion out of a try .. catch block.Loïc Hoguin
Fixes issue #31. Recursion shouldn't happen in a single catch statement or inside a try .. catch statement. The only safe construct for catching exceptions and perform recursion when everything goes well is to put the recursive call inside a try .. of .. catch construct in the of .. catch block. Otherwise the stack gets filled with exception-related information since they can still be caught if we were to send them and unfold the whole thing. Thanks go to lpgauth for reporting the issue and people on IRC for explaining the hows and whys.
2011-07-06Add documentation for the public interface.Loïc Hoguin
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-05-25Refresh the type specifications.Loïc Hoguin
Following discussions on #erlounge. Also fixes compilation in R14B03 and fixes a few underspecs dialyzer warnings.
2011-05-20Send a meaningful error to error_logger on handler crashes.Loïc Hoguin
Inspired by gen_server and friends. Should fix issue #13.
2011-05-09Implement path_info featureAnthony Ramine
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-08Add chunked reply support.Loïc Hoguin
Send the status line and headers using cowboy_http_req:chunked_reply/3, and individual chunks with cowboy_http_req:chunk/2.
2011-05-05Switch the HTTP protocol to use binary packets instead of lists.Loïc Hoguin
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-04Add cowboy_http_req:port/1.Loïc Hoguin
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-04-30Remove the next_request function always matching its first clause.Loïc Hoguin
2011-04-18Remove the include/types.hrl file.Loïc Hoguin
2011-04-18Move the dispatcher related types into cowboy_dispatcher.Loïc Hoguin