| 1 |
NAME |
| 2 |
`Test::Async::HTTP' - unit test code that uses `Net::Async::HTTP' |
| 3 |
|
| 4 |
DESCRIPTION |
| 5 |
This module implements a mock version of Net::Async::HTTP suitable for |
| 6 |
unit tests that virtualises the actual HTTP request/response cycle, |
| 7 |
allowing the unit test script to inspect the requests made and provide |
| 8 |
responses to them. |
| 9 |
|
| 10 |
METHODS |
| 11 |
$f = $http->do_request( %args ) |
| 12 |
Implements the actual Net::Async::HTTP request API. |
| 13 |
|
| 14 |
The following arguments are handled specially: |
| 15 |
|
| 16 |
* timeout |
| 17 |
The value of a `timeout' argument is captured as an extra header on |
| 18 |
the request object called `X-NaHTTP-Timeout'. |
| 19 |
|
| 20 |
* stall_timeout |
| 21 |
* expect_continue |
| 22 |
* SSL |
| 23 |
These arguments are entirely ignored. |
| 24 |
|
| 25 |
$response = $http->GET( $uri, %args )->get |
| 26 |
$response = $http->HEAD( $uri, %args )->get |
| 27 |
$response = $http->PUT( $uri, $content, %args )->get |
| 28 |
$response = $http->POST( $uri, $content, %args )->get |
| 29 |
Convenient wrappers for using the `GET', `HEAD', `PUT' or `POST' methods |
| 30 |
with a `URI' object and few if any other arguments, returning a |
| 31 |
`Future'. |
| 32 |
|
| 33 |
Remember that `POST' with non-form data (as indicated by a plain scalar |
| 34 |
instead of an `ARRAY' reference of form data name/value pairs) needs a |
| 35 |
`content_type' key in `%args'. |
| 36 |
|
| 37 |
$p = $http->next_pending |
| 38 |
Returns the next pending request wrapper object if one is outstanding |
| 39 |
(due to an earlier call to `do_request'), or `undef'. |
| 40 |
|
| 41 |
PENDING REQUEST OBJECTS |
| 42 |
Objects returned by `next_pending' respond to the following methods: |
| 43 |
|
| 44 |
$request = $p->request |
| 45 |
Returns the HTTP::Request object underlying this pending request. |
| 46 |
|
| 47 |
$p->respond( $resp ) |
| 48 |
Makes the request complete with the given HTTP::Response response. This |
| 49 |
response is given to the Future that had been returned by the |
| 50 |
`do_request' method. |
| 51 |
|
| 52 |
$p->respond_header( $header ) |
| 53 |
$p->respond_more( $data ) |
| 54 |
$p->respond_done |
| 55 |
Alternative to the single `respond' method, to allow an equivalent of |
| 56 |
chunked encoding response. `respond_header' responds with the header and |
| 57 |
initial content, followed by multiple calls to `respond_more' to provide |
| 58 |
more body content, until a final `respond_done' call finishes the |
| 59 |
request. |
| 60 |
|
| 61 |
AUTHOR |
| 62 |
Paul Evans <[email protected]> |
| 63 |
|