JMAP-Tester

 view release on metacpan or  search on metacpan

t/lib/JMAP/Tester/MockServer.pm  view on Meta::CPAN

  my $path  = $req->path_info;

  return  index($path, '/jmap/session/')  == 0 ? _handle_session_req($req)
        : index($path, '/jmap/api/')      == 0 ? _handle_api_req($req)
        : index($path, '/jmap/download/') == 0 ? _handle_download_req($req)
        : index($path, '/jmap/upload/')   == 0 ? _handle_upload_req($req)
        :                                        _error(404);
}

sub _handle_download_req ($req) {
  my (undef, undef, undef, $accountid, $blob_id, $name) = split m{/}, $req->path_info;
  return [
    200,
    [
      'Content-Type' => $req->parameters->{type},
      'Content-Disposition' => qq{attachment; filename="$name"},
    ],
    [ "The blob you requested was $blob_id for $accountid." ],
  ];
}

sub _handle_upload_req ($req) {
  my (undef, undef, undef, $account_id) = split m{/}, $req->path_info;

  my $content = $req->raw_body;
  my $length  = length $content;
  my $blob_id = substr($content, 0, 1) . q{-} . $length; # Whatever.

  my $result = {
    accountId => $account_id,
    blobId    => $blob_id,
    type      => scalar $req->header('Content-Type'),
    size      => $length,



( run in 1.423 second using v1.01-cache-2.11-cpan-71847e10f99 )