The Functions
GET
my $res = GET $uri;
Sends a simple GET request to the Apache test server. Returns an "HTTP::Response" object.
You can also supply additional headers to be sent with the request by adding their name/value pairs after the "url" parameter, for example:
my $res = GET $url, 'Accept-Language' => 'de,en-us,en;q=0.5';
GET_STR
A shortcut function for "GET($uri)->as_string".
GET_BODY
A shortcut function for "GET($uri)->content".
GET_BODY_ASSERT
Use this function when your test is outputting content that you need to check, and you want to make sure that the request was successful before comparing the contents of the request. If the request was unsuccessful, "GET_BODY_ASSERT" will return an error message. Otherwise it will simply return the content of the request just as "GET_BODY" would.
GET_OK
A shortcut function for "GET($uri)->is_success".
GET_RC
A shortcut function for "GET($uri)->code".
GET_HEAD
Throws out the content of the request, and returns the string representation of the request. Since the body has been thrown out, the representation will consist solely of the headers. Furthermore, "GET_HEAD" inserts a "#" at the beginning of each line of the return string, so that the contents are suitable for printing to STDERR during your tests without interfering with the workings of "Test::Harness".
HEAD
my $res = HEAD $uri;
Sends a HEAD request to the Apache test server. Returns an "HTTP::Response" object.
HEAD_STR
A shortcut function for "HEAD($uri)->as_string".
HEAD_BODY
A shortcut function for "HEAD($uri)->content". Of course, this means that it will likely return nothing.
HEAD_BODY_ASSERT
Use this function when your test is outputting content that you need to check, and you want to make sure that the request was successful before comparing the contents of the request. If the request was unsuccessful, "HEAD_BODY_ASSERT" will return an error message. Otherwise it will simply return the content of the request just as "HEAD_BODY" would.
HEAD_OK
A shortcut function for "GET($uri)->is_success".
HEAD_RC
A shortcut function for "GET($uri)->code".
HEAD_HEAD
Throws out the content of the request, and returns the string representation of the request. Since the body has been thrown out, the representation will consist solely of the headers. Furthermore, "GET_HEAD" inserts a "#" at the beginning of each line of the return string, so that the contents are suitable for printing to STDERR during your tests without interfering with the workings of "Test::Harness".
PUT
my $res = PUT $uri;
Sends a simple PUT request to the Apache test server. Returns an "HTTP::Response" object.
PUT_STR
A shortcut function for "PUT($uri)->as_string".
PUT_BODY
A shortcut function for "PUT($uri)->content".
PUT_BODY_ASSERT
Use this function when your test is outputting content that you need to check, and you want to make sure that the request was successful before comparing the contents of the request. If the request was unsuccessful, "PUT_BODY_ASSERT" will return an error message. Otherwise it will simply return the content of the request just as "PUT_BODY" would.
PUT_OK
A shortcut function for "PUT($uri)->is_success".
PUT_RC
A shortcut function for "PUT($uri)->code".
PUT_HEAD
Throws out the content of the request, and returns the string representation of the request. Since the body has been thrown out, the representation will consist solely of the headers. Furthermore, "PUT_HEAD" inserts a "#" at the beginning of each line of the return string, so that the contents are suitable for printing to STDERR during your tests without interfering with the workings of "Test::Harness".
POST
my $res = POST $uri, [ arg => $val, arg2 => $val ];
Sends a POST request to the Apache test server and returns an "HTTP::Response" object. An array reference of parameters passed as the second argument will be submitted to the Apache test server as the POST content. Parameters corresponding to those documented in Optional Parameters can follow the optional array reference of parameters, or after $uri.
To upload a chunk of data, simply use:
my $res = POST $uri, content => $data;
POST_STR
A shortcut function for "POST($uri, @args)->content".
POST_BODY
A shortcut function for "POST($uri, @args)->content".
POST_BODY_ASSERT
Use this function when your test is outputting content that you need to check, and you want to make sure that the request was successful before comparing the contents of the request. If the request was unsuccessful, "POST_BODY_ASSERT" will return an error message. Otherwise it will simply return the content of the request just as "POST_BODY" would.
POST_OK
A shortcut function for "POST($uri, @args)->is_success".
POST_RC
A shortcut function for "POST($uri, @args)->code".
POST_HEAD
Throws out the content of the request, and returns the string representation of the request. Since the body has been thrown out, the representation will consist solely of the headers. Furthermore, "POST_HEAD" inserts a "#" at the beginning of each line of the return string, so that the contents are suitable for printing to STDERR during your tests without interfering with the workings of "Test::Harness".
UPLOAD
my $res = UPLOAD $uri, \@args, filename => $filename;
Sends a request to the Apache test server that includes an uploaded file. Other POST parameters can be passed as a second argument as an array reference.
"Apache::TestRequest" will read in the contents of the file named via the "filename" parameter for submission to the server. If you'd rather, you can submit use the "content" parameter instead of "filename", and its value will be submitted to the Apache server as file contents:
my $res = UPLOAD $uri, undef, content => "This is file content";
The name of the file sent to the server will simply be "b". Note that in this case, you cannot pass other POST arguments to UPLOAD() -- they would be ignored.
UPLOAD_BODY
A shortcut function for "UPLOAD($uri, @params)->content".
UPLOAD_BODY_ASSERT
Use this function when your test is outputting content that you need to check, and you want to make sure that the request was successful before comparing the contents of the request. If the request was unsuccessful, "UPLOAD_BODY_ASSERT" will return an error message. Otherwise it will simply return the content of the request just as "UPLOAD_BODY" would.
OPTIONS
my $res = OPTIONS $uri;
Sends an "OPTIONS" request to the Apache test server. Returns an "HTTP::Response" object with the Allow header, indicating which methods the server supports. Possible methods include "OPTIONS", "GET", "HEAD" and "POST". This function thus can be useful for testing what options the Apache server supports. Consult the HTTPD 1.1 specification, section 9.2, at http://www.faqs.org/rfcs/rfc2616.html for more information.
URL Manipulation Functions
"Apache::TestRequest" also includes a few helper functions to aid in the creation of urls used in the functions above.
"module2path"
$path = Apache::TestRequest::module2path($module_name);
Convert a module name to a path, safe for use in the various request methods above. e.g. "::" can't be used in URLs on win32. For example:
$path = Apache::TestRequest::module2path('Foo::Bar');
returns:
/Foo__Bar
"module2url"
$url = Apache::TestRequest::module2url($module);
$url = Apache::TestRequest::module2url($module, \%options);
Convert a module name to a full URL including the current configurations "hostname:port" and sets "module" accordingly.
$url = Apache::TestRequest::module2url('Foo::Bar');
returns:
http://$hostname:$port/Foo__Bar
The default scheme used is "http". You can override this by passing your preferred scheme into an optional second param. For example:
$module = 'MyTestModule::TestHandler';
$url = Apache::TestRequest::module2url($module, {scheme => 'https'});
returns:
https://$hostname:$port/MyTestModule__TestHandler
You may also override the default path with a path of your own:
$module = 'MyTestModule::TestHandler';
$url = Apache::TestRequest::module2url($module, {path => '/foo'});
returns:
http://$hostname:$port/foo