Skip to content
Browse files

- set the Host header during configuration phase

- change server_name to host_header

SVN Revision: 489
  • Loading branch information...
1 parent 2da1708 commit b628eaaa173df94cb0b4702a6f4d8f45558c3e7d @nniclausse nniclausse committed Jul 19, 2005
View
2 include/ts_http.hrl
@@ -29,7 +29,7 @@
-record(http_request, {
url,
version="1.1", % default is HTTP/1.1
- server_name, % use for the 'Host:' header
+ host_header, % use for the 'Host:' header
get_ims_date, % used when the method is getims
cookie = none,
method = get,
View
15 src/tsunami/ts_http.erl
@@ -98,19 +98,12 @@ add_dynparams(true, DynData, Param, HostData) ->
%% Function: add_dynparams/3
%% no cookies
-add_dynparams(#http_dyndata{cookies=[], user_agent=UA},Param, {Host, 80}) ->
- %% don't print port in "Host:" if it's the default
- Param#http_request{server_name=Host, user_agent=UA};
-add_dynparams(#http_dyndata{cookies=[],user_agent=UA},Param, {Host, Port}) ->
- Param#http_request{server_name=Host++":"++ integer_to_list(Port), user_agent=UA};
+add_dynparams(#http_dyndata{cookies=[],user_agent=UA},Param, _) ->
+ Param#http_request{user_agent=UA};
%% cookies
-add_dynparams(#http_dyndata{cookies=DynData,user_agent=UA}, Param, {Host, 80}) ->
- %% don't print port in "Host:" if it's the default
- Param#http_request{cookie=DynData,server_name=Host, user_agent=UA};
-add_dynparams(#http_dyndata{cookies=DynData, user_agent=UA}, Param, {Host, Port}) ->
+add_dynparams(#http_dyndata{cookies=DynData,user_agent=UA}, Param, _) ->
%% FIXME: should we use the Port value in the Cookie ?
- Param#http_request{cookie=DynData,user_agent=UA,
- server_name=Host++":"++ integer_to_list(Port)}.
+ Param#http_request{cookie=DynData,user_agent=UA}.
init_dynparams() ->
%% FIXME: optimization: suppress this call if we don't need
View
6 src/tsunami/ts_http_common.erl
@@ -49,7 +49,7 @@
%%----------------------------------------------------------------------
http_get(#http_request{url=URL, version=Version, cookie=Cookie, user_agent=UA,
get_ims_date=undefined, soap_action=SOAPAction,
- server_name=Host, userid=UserId, passwd=Passwd})->
+ host_header=Host, userid=UserId, passwd=Passwd})->
list_to_binary([?GET, " ", URL," ", "HTTP/", Version, ?CRLF,
"Host: ", Host, ?CRLF,
user_agent(UA),
@@ -60,7 +60,7 @@ http_get(#http_request{url=URL, version=Version, cookie=Cookie, user_agent=UA,
http_get(#http_request{url=URL, version=Version, cookie=Cookie,user_agent=UA,
get_ims_date=Date, soap_action=SOAPAction,
- server_name=Host, userid=UserId, passwd=Passwd}) ->
+ host_header=Host, userid=UserId, passwd=Passwd}) ->
list_to_binary([?GET, " ", URL," ", "HTTP/", Version, ?CRLF,
["If-Modified-Since: ", Date, ?CRLF],
"Host: ", Host, ?CRLF,
@@ -76,7 +76,7 @@ http_get(#http_request{url=URL, version=Version, cookie=Cookie,user_agent=UA,
%%----------------------------------------------------------------------
http_post(#http_request{url=URL, version=Version, cookie=Cookie,user_agent=UA,
soap_action=SOAPAction, content_type=ContentType,
- body=Content, server_name=Host,
+ body=Content, host_header=Host,
userid=UserId, passwd=Passwd}) ->
ContentLength=integer_to_list(size(Content)),
?DebugF("Content Length of POST: ~p~n.", [ContentLength]),
View
4 src/tsunami/tsunami.app.src
@@ -20,10 +20,6 @@
{env, [
{debug_level, 2},
{ts_cookie, "humhum"},
- {server_name, "localhost"},%% required for HTTP/1.1 requests
- {server_adr, "127.0.0.1"}, %% server IP or name
- {server_port, 80}, %% server port
- {server_protocol, gen_tcp},%% gen_tcp, gen_udp or ssl
{snd_size, 32768}, %% send buffer size
{rcv_size, 32768}, %% receive buffer size
{tcp_timeout, 600000}, %% 10min timeout
View
99 src/tsunami_controller/ts_config_http.erl
@@ -48,12 +48,13 @@
parse_config(Element = #xmlElement{name=dyn_variable}, Conf = #config{}) ->
ts_config:parse(Element,Conf);
parse_config(Element = #xmlElement{name=http},
- Config=#config{curid = Id, session_tab = Tab,
+ Config=#config{curid = Id, session_tab = Tab, server = Server,
sessions = [CurS | _], dynvar=DynVar,
subst = SubstFlag, match=MatchRegExp}) ->
Version = ts_config:getAttr(Element#xmlElement.attributes, version),
URL = ts_config:getAttr(Element#xmlElement.attributes, url),
Contents = ts_config:getAttr(Element#xmlElement.attributes, contents),
+ UseProxy = ts_config:getAttr(atom, Element#xmlElement.attributes, use_server_as_proxy, false),
%% Apache Tomcat applications need content-type informations to read post forms
ContentType = ts_config:getAttr(string,Element#xmlElement.attributes,
content_type, "application/x-www-form-urlencoded"),
@@ -66,24 +67,27 @@ parse_config(Element = #xmlElement{name=http},
?LOGF("Bad method ! ~p ~n",[Other],?ERR),
get
end,
- ServerName = ts_config:get_default(Tab,http_server_name, server_name),
+
Request = #http_request{url = URL,
method = Method,
version = Version,
get_ims_date= Date,
- server_name = ServerName,
content_type= ContentType,
body = list_to_binary(Contents)},
%% SOAP Support: Add SOAPAction header to the message
Request2 = case lists:keysearch(soap,#xmlElement.name,
- Element#xmlElement.content) of
- {value, SoapEl=#xmlElement{} } ->
+ Element#xmlElement.content) of
+ {value, SoapEl=#xmlElement{} } ->
SOAPAction = ts_config:getAttr(SoapEl#xmlElement.attributes,
action),
Request#http_request{soap_action=SOAPAction};
_ ->
Request
end,
+ PreviousHTTPServer = case ets:lookup(Tab, {http_server, CurS#session.id}) of
+ [] -> [];
+ [{_Key,PrevServ}] -> PrevServ
+ end,
Msg = case lists:keysearch(www_authenticate,#xmlElement.name,
Element#xmlElement.content) of
{value, AuthEl=#xmlElement{} } ->
@@ -92,10 +96,11 @@ parse_config(Element = #xmlElement{name=http},
Passwd = ts_config:getAttr(string,AuthEl#xmlElement.attributes,
passwd, undefined),
NewReq=Request2#http_request{userid=UserId, passwd=Passwd},
- set_msg(NewReq, 0, {SubstFlag, MatchRegExp} );
+ set_msg(NewReq, 0, {SubstFlag, MatchRegExp, UseProxy, Server, PreviousHTTPServer, Tab, CurS#session.id} );
_ ->
- set_msg(Request2, 0, {SubstFlag, MatchRegExp} )
+ set_msg(Request2, 0, {SubstFlag, MatchRegExp, UseProxy, Server, PreviousHTTPServer, Tab, CurS#session.id} )
end,
+
ts_config:mark_prev_req(Id-1, Tab, CurS),
ets:insert(Tab,{{CurS#session.id, Id},Msg#ts_request{endpage=true,
dynvar_specs=DynVar}}),
@@ -105,9 +110,6 @@ parse_config(Element = #xmlElement{name=http},
%% Parsing default values
parse_config(Element = #xmlElement{name=default}, Conf = #config{session_tab = Tab}) ->
case ts_config:getAttr(Element#xmlElement.attributes, name) of
- "server_name" ->
- Val = ts_config:getAttr(Element#xmlElement.attributes, value),
- ets:insert(Tab,{{http_server_name, value}, Val});
"user_agent" ->
Val = ts_config:getAttr(Element#xmlElement.attributes, value), %FIXME: useless
lists:foldl( fun(A,B)->parse_config(A,B) end, Conf, Element#xmlElement.content)
@@ -144,36 +146,53 @@ parse_config(_, Conf = #config{}) ->
%% port and scheme from the URL and override the global setup of the
%% server. These informations are stored in the #ts_request record.
set_msg(HTTP=#http_request{url="http" ++ URL},
- ThinkTime, {SubstFlag, MatchRegExp}) -> % full URL
+ ThinkTime, {SubstFlag, MatchRegExp, UseProxy, Server, _PrevHTTPServer, Tab, Id}) -> % full URL
URLrec = parse_URL("http" ++ URL),
- Path= case URLrec#url.querypart of
- "" -> % no query
- URLrec#url.path;
- _String ->
- URLrec#url.path ++ "?" ++ URLrec#url.querypart
- end,
+ Path = set_query(URLrec),
+ HostHeader = set_host_header(URLrec),
Port = set_port(URLrec),
- Scheme = case URLrec#url.scheme of
- http -> gen_tcp;
- https -> ssl
- end,
- set_msg2(HTTP#http_request{url=Path}, ThinkTime,
+ Scheme = set_scheme(URLrec#url.scheme),
+ ets:insert(Tab,{{http_server, Id}, {HostHeader}}),
+ set_msg2(HTTP#http_request{url=Path, host_header = HostHeader}, ThinkTime,
#ts_request{ack = parse,
subst = SubstFlag,
match = MatchRegExp,
host = URLrec#url.host,
scheme = Scheme,
port = Port});
-%
-set_msg(HTTPRequest, Think, {SubstFlag, MatchRegExp}) -> % relative URL,
+
+%% relative URL, no previous HTTP server (hence, first request in session)
+set_msg(HTTPRequest, Think, {SubstFlag, MatchRegExp, false, Server, [],_Tab,_Id}) ->
+ Tmp= case Server#server.type of
+ gen_tcp -> "http";
+ ssl -> "https"
+ end,
+ URL =lists:append([Tmp, "://", Server#server.host, ":",
+ integer_to_list(Server#server.port),
+ HTTPRequest#http_request.url]),
+ set_msg(HTTPRequest#http_request{url=URL}, Think, {SubstFlag, MatchRegExp, false, Server, [],_Tab,_Id});
+
+%% relative URL, no previous HTTP server, use proxy, error !
+set_msg(HTTPRequest, Think, {SubstFlag, MatchRegExp, true, _Server, [],_Tab,_Id}) ->
+ ?LOG("Need absolut URL when using a proxy ! Abort",?ERR),
+ throw({error, badurl_proxy});
+%% relative URL, no proxy
+set_msg(HTTPRequest, Think, {SubstFlag, MatchRegExp, false, _Server, {HostHeader},_Tab,_Id}) ->
%%% use global host, port and scheme (undefined value), it will be
%%% dynamicaly set during the run (using default server or previous
%%% one used in the current session)
- set_msg2(HTTPRequest, Think, #ts_request{ack = parse,
- subst = SubstFlag,
- match = MatchRegExp
- }).
-
+ set_msg2(HTTPRequest#http_request{host_header= HostHeader}, Think,
+ #ts_request{ack = parse, subst = SubstFlag, match = MatchRegExp });
+set_msg(HTTPRequest, Think, {SubstFlag, MatchRegExp, true, Server, {HostHeader},_Tab,_Id}) -> % relative URL, use proxy
+%%% use global host, port and scheme (undefined value), it will be
+%%% dynamicaly set during the run (using default server or previous
+%%% one used in the current session)
+ set_msg2(HTTPRequest#http_request{host_header= HostHeader}, Think,
+ #ts_request{ack = parse, subst = SubstFlag, match = MatchRegExp }).
+
+%% Func: set_mgs2/3
+%% Purpose: set param and thinktime in ts_request
+%% Returns: ts_request
set_msg2(HTTPRequest, 0, Msg) -> % no thinktime, only wait for response
Msg#ts_request{ thinktime=infinity,
param = HTTPRequest };
@@ -183,6 +202,17 @@ set_msg2(HTTPRequest, Think, Msg) -> % end of a page, wait before the next one
param = HTTPRequest }.
%%--------------------------------------------------------------------
+%% Func: set_host_header/1
+%%--------------------------------------------------------------------
+set_host_header(#url{host=Host,scheme=https,port=undefined}) -> Host ++":443";
+set_host_header(#url{host=Host,scheme=http,port=undefined}) -> Host;
+set_host_header(#url{host=Host,port=Port}) when is_integer(Port) ->
+ Host ++ ":" ++ integer_to_list(Port);
+set_host_header(#url{host=Host,port=Port}) when is_list(Port) ->
+ Host ++ ":" ++ Port.
+
+
+%%--------------------------------------------------------------------
%% Func: set_port/1
%% Purpose: Returns port according to scheme if not already defined
%% Returns: PortNumber (integer)
@@ -192,6 +222,15 @@ set_port(#url{scheme=http,port=undefined}) -> 80;
set_port(#url{port=Port}) when is_integer(Port) -> Port;
set_port(#url{port=Port}) -> integer_to_list(Port).
+set_scheme(http) -> gen_tcp;
+set_scheme(https) -> ssl.
+
+
+set_query(URLrec = #url{querypart=""}) ->
+ URLrec#url.path;
+set_query(URLrec = #url{}) ->
+ URLrec#url.path ++ "?" ++ URLrec#url.querypart.
+
%%----------------------------------------------------------------------
%% Func: parse_URL/1
@@ -231,3 +270,5 @@ parse_URL(path,[$?|T], Acc, URL) ->
URL#url{path=lists:reverse(Acc), querypart=T};
parse_URL(path,[H|T], Acc, URL) ->
parse_URL(path, T, [H|Acc], URL).
+
+
View
2 src/tsunami_controller/tsunami_controller.app.src
@@ -24,8 +24,6 @@
{file_server_timeout, 30000}, %% timeout for reading file
{warm_time, 10}, %% (seconds) initial waiting time when launching clients
- {server_name, "glop"},
-
{thinktime_value, "5"}, % default value = 5sec
{thinktime_override, "false"},
{thinktime_random, "false"},

0 comments on commit b628eaa

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