Skip to content
Browse files

improve HTTP headers functions

SVN Revision: 56
  • Loading branch information...
1 parent 7cc40f7 commit 5382a9cf58c782ae351516d107db060d41919a74 @nniclausse nniclausse committed Feb 17, 2003
Showing with 48 additions and 43 deletions.
  1. +2 −2 TODO
  2. +4 −4 include/ts_http.hrl
  3. +2 −0 include/ts_profile.hrl
  4. +1 −1 src/idx-tsunami.pl.src
  5. +38 −35 src/ts_http_common.erl
  6. +1 −1 src/tsunami.app.src
View
4 TODO
@@ -1,13 +1,13 @@
- add cookie support
-- add POST support
-- full support of httperf sesslog file
+- test POST support
- cache ssl session ID
- handle http/1.1 pipelining ?
- add multiple tcp connections per client (for http) ?
- improve documentation
- add custom http headers
- change sequence for loading sesslog file
+- add capability to send several samples at once to ts_mon
- groupchat for Jabber
- clients may do a checksum to control integrity of responses ?
View
8 include/ts_http.hrl
@@ -24,10 +24,10 @@
-record(http_request, {url, cookie=none, method=get, body=[], id = 0 }).
%% use by the client process to store information about the current request during
-%% the parsing of the response
+%% the parsing of the response
-record(http, {content_length= 0, % HTTP header: content length
body_size = 0, % current size of body,
- status = none % HTTP resp. status :200, etc. 'none' if no current cnx.
+ status = none % HTTP resp. status :200, etc. 'none' if no current cnx.
}).
-define(server_name, ts_utils:get_val(server_name)).
@@ -37,6 +37,6 @@
%% HTTP Protocol
-define(GET, "GET").
-define(POST, "POST").
--define(HTTP10, "HTTP/1.0").
--define(HTTP11, "HTTP/1.1").
+
+-define(USER_AGENT, "IDX-Tsunami").
View
2 include/ts_profile.hrl
@@ -49,6 +49,8 @@
-define(short_timeout, 1).
-define(retries, 4).
+-define(CR, "\n").
+
%% retry sending message after this timeout (in microsec.)
-define(client_retry_timeout, ts_utils:get_val(client_retry_timeout)).
-define(req_server_timeout, ts_utils:get_val(req_server_timeout)). %% timeout when for reading the session file
View
2 src/idx-tsunami.pl.src
@@ -106,7 +106,7 @@ if ($config or $start or $restart) {
} else {
# if contains ':' ,'.' or '-' , put quotes, otherwise,
# Erlang is not happy
- if (($config{$key} =~ /[:|-|\.]/) and ($config{$key} !~ /^\d+\.\d+$/)){
+ if (($config{$key} =~ /[:|-|\.]/) and ($config{$key} !~ /^\d+\.\d+$/) or $key eq "http_version"){
print "{$key, \"". $config{$key} . "\"},\n";
}
else {
View
73 src/ts_http_common.erl
@@ -28,7 +28,7 @@
-export([get_client/2,
get_client/3,
http_get/3,
- http_post/3,
+ http_post/4,
parse/2,
get_simple_client/2
]).
@@ -115,45 +115,48 @@ build_simplesession(N, Session, Id) ->
%%----------------------------------------------------------------------
%% Func: http_get/3
%% Args: URL, HTTP Version, Cookie
-%% Are we caching this string ? We should !
-%%----------------------------------------------------------------------
-http_get(URL, 1.0, none) ->
- CR=io_lib:nl(),
- ?GET ++ " " ++ URL ++" " ++ ?HTTP10 ++ CR ++ user_agent() ++ CR++CR;
-http_get(URL, 1.0, Cookie) -> %%TODO
- CR=io_lib:nl(),
- ?GET ++ " " ++ URL ++" " ++ ?HTTP10 ++ CR ++ user_agent() ++ CR++CR;
-http_get(URL, 1.1, none) ->
- CR=io_lib:nl(),
- ?GET ++ " " ++ URL ++" " ++ ?HTTP11 ++ CR++ host() ++ CR++ user_agent() ++ CR++CR;
-http_get(URL, 1.1, Cookie) -> %% TODO
- CR=io_lib:nl(),
- ?GET ++ " " ++ URL ++" " ++ ?HTTP11 ++ CR++ host() ++ CR++ user_agent() ++ CR++CR.
-
-%%----------------------------------------------------------------------
-%% Func: http_post/3
-%% Args: URL, HTTP Version, Cookie
%%----------------------------------------------------------------------
-http_post(URL, 1.0, none) ->
- CR=io_lib:nl(),
- ?POST ++ " " ++ URL ++" " ++ ?HTTP10 ++ CR ++ user_agent() ++ CR++CR;
-http_post(URL, 1.0, Cookie) -> %%TODO
- CR=io_lib:nl(),
- ?POST ++ " " ++ URL ++" " ++ ?HTTP10 ++ CR ++ user_agent() ++ CR++CR;
-http_post(URL, 1.1, none) ->
- CR=io_lib:nl(),
- ?POST ++ " " ++ URL ++" " ++ ?HTTP11 ++ CR++ host() ++ CR++ user_agent() ++ CR++CR;
-http_post(URL, 1.1, Cookie) -> %% TODO
- CR=io_lib:nl(),
- ?POST ++ " " ++ URL ++" " ++ ?HTTP11 ++ CR++ host() ++ CR++ user_agent() ++ CR++CR.
+http_get(URL, Version, Cookie) ->
+ lists:append([?GET, " ", URL," ", "HTTP/", Version, ?CR,
+ protocol_headers(Version),
+ user_agent(),
+ get_cookie(Cookie),
+ ?CR]).
+
+%%----------------------------------------------------------------------
+%% Func: http_post/4
+%% Args: URL, HTTP Version, Cookie, Content
+%% TODO: Content-Type ?
+%%----------------------------------------------------------------------
+http_post(URL, Version, Cookie, Content) ->
+ ContentLength=length(Content),
+ lists:append([?POST, " ", URL," ", "HTTP/", Version, ?CR,
+ protocol_headers(Version),
+ user_agent(),
+ get_cookie(Cookie),
+ "Content-Length: ",Content,?CR,
+ ?CR,
+ Content]).
%%----------------------------------------------------------------------
%% some HTTP headers functions
%%----------------------------------------------------------------------
user_agent() ->
- "User-Agent: IDX-Tsunami".
-host() ->
- "Host:" ++ ?server_name.
+ lists:append(["User-Agent: ", ?USER_AGENT, ?CR]).
+
+get_cookie(none) ->
+ [];
+get_cookie(Cookie) ->
+ lists:append(["Cookie: ", Cookie, ?CR]).
+
+%%----------------------------------------------------------------------
+%% set HTTP headers specific to the protocol version
+%%----------------------------------------------------------------------
+protocol_headers("1.1") ->
+ lists:append(["Host: ", ?server_name, ?CR]);
+protocol_headers("1.0") ->
+ [].
+
%%----------------------------------------------------------------------
%% Func: parse_requestline/1
@@ -298,7 +301,7 @@ parse(Data, State) when (State#state_rcv.session)#http.status == none ->
%% current connection
parse(Data, State) ->
DataSize = size(Data),
- ?PRINTDEBUG("HTTP Body ~p~n",[DataSize], ?DEB),
+ ?PRINTDEBUG("HTTP Body size=~p ~n",[DataSize], ?DEB),
Size = (State#state_rcv.session)#http.body_size + DataSize,
CLength = (State#state_rcv.session)#http.content_length,
case Size of
View
2 src/tsunami.app.src
@@ -53,7 +53,7 @@
{req_filename, "requests.txt"}, %% Fichiers de requetes
{req_server_timeout, 120000}, %% Fichiers de requetes
{http_req_filename, "http.txt"}, %% Fichiers de requetes HTTP
- {http_version, 1.1}, %%
+ {http_version, "1.1"}, %%
{client_retry_timeout, 10}, %% retry sending (in microsec.)
{ssl_ciphers, "EXP1024-RC4-SHA,EDH-RSA-DES-CBC3-SHA"},

0 comments on commit 5382a9c

Please sign in to comment.
Something went wrong with that request. Please try again.