aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-06-01 12:49:03 +0200
committerLoïc Hoguin <[email protected]>2011-06-01 12:49:03 +0200
commit919fa638ee24250a9f1def27b82f9f7648324d4a (patch)
treeb5a1bef923b9951503d97bca77db99b3c5de424a
parent3cfdf46e97c98d031f1aae9a0333afa132466a7a (diff)
downloadcowboy-919fa638ee24250a9f1def27b82f9f7648324d4a.tar.gz
cowboy-919fa638ee24250a9f1def27b82f9f7648324d4a.tar.bz2
cowboy-919fa638ee24250a9f1def27b82f9f7648324d4a.zip
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.
-rw-r--r--src/cowboy_http_req.erl12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl
index 3fbf95f..c2f2d2d 100644
--- a/src/cowboy_http_req.erl
+++ b/src/cowboy_http_req.erl
@@ -33,6 +33,10 @@
reply/4, chunked_reply/3, chunk/2
]). %% Response API.
+-export([
+ compact/1
+]). %% Misc API.
+
-include("include/http.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -213,6 +217,14 @@ chunk(Data, #http_req{socket=Socket, transport=Transport, resp_state=chunks}) ->
Transport:send(Socket, [integer_to_list(iolist_size(Data), 16),
<<"\r\n">>, Data, <<"\r\n">>]).
+%% Misc API.
+
+-spec compact(#http_req{}) -> #http_req{}.
+compact(Req) ->
+ Req#http_req{host=undefined, host_info=undefined, path=undefined,
+ path_info=undefined, qs_vals=undefined, raw_qs=undefined,
+ bindings=undefined, headers=[]}.
+
%% Internal.
-spec parse_qs(binary()) -> list({binary(), binary() | true}).