NAME

Net::HTTP::Knork::Response - Portable HTTP Response object for SPORE response

VERSION

version 0.20

SYNOPSIS

use Net:HTTP::Knork::Response;

my $response = Net::HTTP::Knork::Response->new(
    200, ['Content-Type', 'application/json'], '{"foo":1}';
);
$response->request($request);

DESCRIPTION

Net::HTTP::Knork::Response : create a HTTP response Most of the code was adapted from Net::HTTP::Spore::Response, with two main differences : - it uses Moo - it is a subclass of HTTP::Response

METHODS

new
my $res = Net::HTTP::Knork::Response->new;
my $res = Net::HTTP::Knork::Response->new($status);
my $res = Net::HTTP::Knork::Response->new($status, $message, $headers);
my $res = Net::HTTP::Knork::Response->new($status, $message, $headers, $body);

Creates a new Net::HTTP::Knork::Response object.

code
status
$res->status(200);
my $status = $res->status;

Gets or sets the HTTP status of the response

env $res->env($env); my $env = $res->env;

Gets or sets the environment for the response. Shortcut to $res->request->env

content
body
$res->body($body);
my $body = $res->body;

Gets or sets the body for the response

raw_body
my $raw_body = $res->raw_body

The raw_body value is the same as body when the body is sets for the first time.

content_type
$res->content_type('application/json');
my $ct = $res->content_type;

Gets or sets the content type of the response body

content_length
$res->content_length(length($body));
my $cl = $res->content_length;

Gets or sets the content type of the response body

location
$res->location('http://example.com');
my $location = $res->location;

Gets or sets the location header for the response

request
$res->request($request);
$request = $res->request;

Gets or sets the HTTP request that created the current HTTP response.

headers
$headers = $res->headers;
$res->headers(['Content-Type' => 'application/json']);

Gets or sets HTTP response headers.

my $cl = $res->header('Content-Length');
$res->header('Content-Type' => 'application/json');

Shortcut for $res->headers->header.

finalise
my $res = Net::HTTP::Knork::Response->new($status, $headers, $body);
say "http status is ".$res->[0];

Return an arrayref:

status

The first element of the array ref is the HTTP status

headers

The second element is an arrayref containing the list of HTTP headers

body

The third and final element is the body

AUTHOR

Emmanuel Peroumalnaïk

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by E. Peroumalnaik.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.