Browse files

Add support for HEAD, PUT and DELETE method for HTTP. Fix for TSUN-22

SVN Revision: 678
  • Loading branch information...
1 parent 8e11f40 commit c138ea195a551d89a617b7e77c792f8610d2385a @nniclausse nniclausse committed Aug 8, 2006
Showing with 38 additions and 14 deletions.
  1. +3 −0 include/ts_http.hrl
  2. +11 −2 src/tsung/ts_http.erl
  3. +22 −7 src/tsung/ts_http_common.erl
  4. +1 −4 src/tsung_controller/ts_config_http.erl
  5. +1 −1 tsung-1.0.dtd
View
3 include/ts_http.hrl
@@ -89,6 +89,9 @@
%% HTTP Protocol
-define(GET, "GET").
-define(POST, "POST").
+-define(PUT, "PUT").
+-define(HEAD, "HEAD").
+-define(DELETE, "DELETE").
-define(USER_AGENT, "Tsung").
-define(USER_AGENT_ERROR_MSG, "Total sum of user agents frequency is not equal to 100").
View
13 src/tsung/ts_http.erl
@@ -62,10 +62,19 @@ new_session() ->
%% Returns: binary
%%----------------------------------------------------------------------
get_message(Req=#http_request{method=get}) ->
- ts_http_common:http_get(Req);
+ ts_http_common:http_no_body(?GET, Req);
+
+get_message(Req=#http_request{method=head}) ->
+ ts_http_common:http_no_body(?HEAD, Req);
+
+get_message(Req=#http_request{method=delete}) ->
+ ts_http_common:http_no_body(?DELETE, Req);
get_message(Req=#http_request{method=post}) ->
- ts_http_common:http_post(Req).
+ ts_http_common:http_body(?POST, Req);
+
+get_message(Req=#http_request{method=put}) ->
+ ts_http_common:http_body(?PUT, Req).
%%----------------------------------------------------------------------
%% Function: parse/2
View
29 src/tsung/ts_http_common.erl
@@ -38,32 +38,40 @@
-export([
http_get/1,
http_post/1,
+ http_body/2,
+ http_no_body/2,
parse/2,
parse_req/1,
parse_req/2
]).
%%----------------------------------------------------------------------
%% Func: http_get/1
+%%----------------------------------------------------------------------
+http_get(Args) ->
+ http_no_body(?GET, Args).
+
+%%----------------------------------------------------------------------
+%% Func: http_get/1
%% Args: #http_request
%%----------------------------------------------------------------------
-http_get(#http_request{url=URL, version=Version, cookie=Cookie, user_agent=UA,
+http_no_body(Method,#http_request{url=URL, version=Version, cookie=Cookie, user_agent=UA,
get_ims_date=undefined, soap_action=SOAPAction,
host_header=Host, userid=UserId, passwd=Passwd})->
?DebugF("GET ~p~n",[URL]),
- list_to_binary([?GET, " ", URL," ", "HTTP/", Version, ?CRLF,
+ list_to_binary([Method, " ", URL," ", "HTTP/", Version, ?CRLF,
"Host: ", Host, ?CRLF,
user_agent(UA),
authenticate(UserId,Passwd),
soap_action(SOAPAction),
set_cookie_header({Cookie, Host, URL}),
?CRLF]);
-http_get(#http_request{url=URL, version=Version, cookie=Cookie,user_agent=UA,
+http_no_body(Method,#http_request{url=URL, version=Version, cookie=Cookie,user_agent=UA,
get_ims_date=Date, soap_action=SOAPAction,
host_header=Host, userid=UserId, passwd=Passwd}) ->
?DebugF("GET ~p~n",[URL]),
- list_to_binary([?GET, " ", URL," ", "HTTP/", Version, ?CRLF,
+ list_to_binary([Method, " ", URL," ", "HTTP/", Version, ?CRLF,
["If-Modified-Since: ", Date, ?CRLF],
"Host: ", Host, ?CRLF,
user_agent(UA),
@@ -74,15 +82,22 @@ http_get(#http_request{url=URL, version=Version, cookie=Cookie,user_agent=UA,
%%----------------------------------------------------------------------
%% Func: http_post/1
+%%----------------------------------------------------------------------
+http_post(Args) ->
+ http_body(?POST, Args).
+
+%%----------------------------------------------------------------------
+%% Func: http_body/2
%% Args: #http_request
%%----------------------------------------------------------------------
-http_post(#http_request{url=URL, version=Version, cookie=Cookie,user_agent=UA,
- soap_action=SOAPAction, content_type=ContentType,
+http_body(Method,#http_request{url=URL, version=Version, cookie=Cookie,
+ user_agent=UA, soap_action=SOAPAction,
+ content_type=ContentType,
body=Content, host_header=Host,
userid=UserId, passwd=Passwd}) ->
ContentLength=integer_to_list(size(Content)),
?DebugF("Content Length of POST: ~p~n.", [ContentLength]),
- Headers = [?POST, " ", URL," ", "HTTP/", Version, ?CRLF,
+ Headers = [Method, " ", URL," ", "HTTP/", Version, ?CRLF,
"Host: ", Host, ?CRLF,
user_agent(UA),
authenticate(UserId,Passwd),
View
5 src/tsung_controller/ts_config_http.erl
@@ -63,10 +63,7 @@ parse_config(Element = #xmlElement{name=http},
content_type, "application/x-www-form-urlencoded"),
Date = ts_config:getAttr(string, Element#xmlElement.attributes,
'if_modified_since', undefined),
- Method = case ts_config:getAttr(Element#xmlElement.attributes, method) of
- "GET" -> get;
- "POST"-> post
- end,
+ Method = list_to_atom(httpd_util:to_lower(ts_config:getAttr(string, Element#xmlElement.attributes, method))),
Request = #http_request{url = URL,
method = Method,
View
2 tsung-1.0.dtd
@@ -104,7 +104,7 @@
contents CDATA #IMPLIED
content_type CDATA #IMPLIED
if_modified_since CDATA #IMPLIED
- method (GET | POST) "GET"
+ method (GET | POST | PUT | DELETE | HEAD) "GET"
url CDATA #REQUIRED
version (1.0 | 1.1) "1.1" >

0 comments on commit c138ea1

Please sign in to comment.