GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Test::HTTP::Syntax(3) User Contributed Perl Documentation Test::HTTP::Syntax(3)

Test::HTTP::Syntax - HTTP tests in a natural style.

  use Test::HTTP::Syntax;
  use Test::HTTP tests => 9;

or

  use Test::HTTP '-syntax', tests => 9;

then

  test_http 'echo test' {
      >> GET /echo/foo
      >> Accept: text/plain

      << 200
      ~< Content-type: ^text/plain\b
      <<
      << foo
  }

Test::HTTP::Syntax is a source filter module designed to work with Test::HTTP. It provides a simple, linewise syntax for specifying HTTP tests in a way that looks a lot like HTTP request and response packets.

All this module does is translate the linewise packet syntax into calls to Test::HTTP.

The actual module used for the tests can be set by setting the variable $Test::HTTP::Syntax::Test_package. It defaults to "Test::HTTP".

Test::HTTP::Syntax only filters sections of code which are delimited by a "test_http" block.

  test_http TEST_NAME {
      # Code to be filtered
      # ...
  }

This gets translated into

  {
      my $test = Test::HTTP->new(TEST_NAME);
      # Filtered code
      # ...
  }

A request packet consists of a REQUEST START line, 0 or more REQUEST HEADER lines, and an optional REQUEST BODY. The packet ends when a blank line is encountered.

The presence of a REQUEST packet only constructs the request within $test. The request does not get run unless a RESPONSE packet is encountered or "$test->run_request()" is called explicitly.

REQUEST START

This line marks the start of a request block.

  >> METHOD URI

"METHOD" is one of "GET", "PUT", "POST", "HEAD", or "DELETE", and "URI" is a URI. This line is followed by 0 or more REQUEST HEADERS, and then optionally a REQUEST BODY.

REQUEST HEADER

  >> HEADER: VALUE

This sets the value of an HTTP request header.

REQUEST BODY

  >>
  >> body line 1
  >> body line 2

This sets the contents of the body of the HTTP packet.

A response packet consists of a RESPONSE START line, 0 or more LITERAL or REGEX RESPONSE HEADER lines, and an optional RESPONSE BODY.

The start of a response packet triggers the execution of the pending request, and starts testing the response received therefrom.

RESPONSE START

  << NNN

"NNN" is a 3-digit HTTP response code which we expect to receive.

LITERAL RESPONSE HEADER

  << HEADER: VALUE

Performs a literal match on the value of the "HEADER" header in the HTTP response packet.

REGEX RESPONSE HEADER

  ~< HEADER: REGEX

Performs a regular expression match on the value of "HEADER" against the REGEX qr{REGEX}.

RESPONSE BODY

  <<
  << body line 1
  << body line 2

Performs a literal match on the given body with the body of the HTTP response packet.

<http://www.w3.org/Protocols/rfc2616/rfc2616.html>, Test::HTTP

Socialtext, Inc. "<code@socialtext.com>"

Copyright 2006 Socialtext, Inc., all rights reserved.

Same terms as Perl.

2012-04-24 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.