DTA-CAB

 view release on metacpan or  search on metacpan

CAB/Client/HTTP.pm  view on Meta::CPAN

## Description: DTA::CAB generic HTTP server clients

package DTA::CAB::Client::HTTP;
use DTA::CAB;
use DTA::CAB::Datum ':all';
use DTA::CAB::Utils ':all';
use DTA::CAB::Client;
#use DTA::CAB::Client::XmlRpc;
use LWP::UserAgent;
use HTTP::Status;
use HTTP::Request::Common;
use URI::Escape qw(uri_escape_utf8);
#use Encode qw(encode decode encode_utf8 decode_utf8);
use Carp qw(confess);
use strict;

##==============================================================================
## Globals
##==============================================================================

our @ISA = qw(DTA::CAB::Client);

CAB/Client/HTTP.pm  view on Meta::CPAN

    $qmode = 'post';
  }

  ##-- get response
  my ($rsp);
  if ($qmode eq 'get') {
    $form{$qname} = $$dataref;
    $rsp = $cli->uget_form($cli->lwpUrl, \%form, @$headers);
  }
  else {
    ##-- encode (for HTTP::Request v5.810 e.g. on services)
    foreach (values %form) {
      utf8::encode($_) if (utf8::is_utf8($_));
    }

    ##-- encode dataref
    utf8::encode($$dataref) if (utf8::is_utf8($$dataref));

    if ($qmode eq 'post') {
      ##-- post most
      $form{$qname} = $$dataref;

CAB/Client/HTTP.pm  view on Meta::CPAN

 $uriStr = $cli->urlEncode(\%form);
 $uriStr = $cli->urlEncode(\@form);
 $uriStr = $cli->urlEncode( $str);

Encodes query form parameters or a raw string for inclusing in a URL.

=item urequest

 $response = $cli->urequest($httpRequest);

Gets response for $httpRequest (a HTTP::Request object) using $cli-E<gt>ua-E<gt>request().
Also traces request to $cli-E<gt>{tracefh} if defined.

=utem urequest_unix

 $response = $cli->urequest_unix($httpRequest);

Guts for L<urequest()|/urequest> over UNIX sockets
using L<LWP::Protocol::http::SocketUnixAlt|LWP::Protocol::http::SocketUnixAlt>.

=item uhead

CAB/Format/Raw/HTTP.pm  view on Meta::CPAN

}

##--------------------------------------------------------------
## Methods: Input: local

## $fmt = $fmt->parseRawString(\$str)
sub parseRawString {
  my ($fmt,$str) = @_;
  utf8::encode($$str) if (utf8::is_utf8($$str));

  ## Use multipart/form-data to avoid implicit LF->CR+LF conversion by LWP::UserAgent (HTTP::Request::Common::POST() v6.03 / debian wheezy)
  #$fmt->trace("querying $fmt->{tokurl} ...");
  my $rsp = $fmt->{ua}->post($fmt->{tokurl}, { $fmt->{txtparam}=>$$str }, 'Content-Type'=>'multipart/form-data');
  if (!$rsp || !$rsp->is_success) {
    $fmt->trace("parseRawString(): error from server:\n", $rsp->as_string) if ($rsp);
    $fmt->logdie("parseRawString(): error from server $fmt->{tokurl}: ", ($rsp ? $rsp->status_line : '(no response)'))
      if (!$rsp || !$rsp->is_success);
  }

  ##-- construct & buffer document
  $fmt->{doc} = DTA::CAB::Format::TT->parseTokenizerString( $rsp->content_ref );

CAB/Server/HTTP.pm  view on Meta::CPAN

    $hreq = $csock->get_request();
    if (!$hreq) {
      $srv->clientError($csock, RC_BAD_REQUEST, "could not parse HTTP request: ", xml_escape($csock->reason || 'get_request() failed'));
      ++$srv->{nErrors};
      next;
    }

    ##-- log basic request, and possibly request data
    $urikey = $hreq->uri->as_string;
    $srv->vlog($srv->{logConnect}, "client $chost: ", $hreq->method, ' ', $urikey);
    $srv->vlog($srv->{logRequestData}, "client $chost: HTTP::Request={\n", $hreq->as_string, "}");

    ##-- check global content-length limit
    if (($srv->{maxRequestSize}//-1) >= 0 && ($hreq->content_length//0) > $srv->{maxRequestSize}) {
      $srv->clientError($csock, RC_REQUEST_ENTITY_TOO_LARGE, "request exceeds server limit (max=$srv->{maxRequestSize} bytes)");
      ++$srv->{nErrors};
      next;
    }

    ##-- map request to handler
    ($handler,$localPath) = $srv->getPathHandler($hreq->uri);

CAB/Server/HTTP/Handler.pm  view on Meta::CPAN

by L<DTA::CAB::Server::HTTP|DTA::CAB::Server::HTTP> $srv
for path (string) $path.
Should return true on success.

Default implementation just returns true.

=item run

 $rsp = $h->run($server, $localPath, $clientConn, $httpRequest);

Run the handler to respond to an HTTP::Request $httpRequest
sent to the L<DTA::CAB::Server::HTTP|DTA::CAB::Server::HTTP> object $server
matching server path $localPath by the client socket $clientConn.

Should return a HTTP::Response object to pass to the client.
If the method call die()s or returns undef, an error response will be
sent to the client instead if it the connection is still open.

This method may return the data to the client itself; if so,
it should close the client connection ($csock-E<gt>shutdown(2); $csock-E<gt>close())
and return undef to prevent bogus error messages.



( run in 0.549 second using v1.01-cache-2.11-cpan-de7293f3b23 )