File: 03_multipart_post.t

package info (click to toggle)
libhttp-tiny-multipart-perl 0.08-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 128 kB
  • sloc: perl: 268; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 839 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!perl

use strict;
use warnings;

use HTTP::Tiny;
use HTTP::Tiny::Multipart;

use Test::More;

{
  no warnings 'redefine';
  *HTTP::Tiny::request = sub { return @_ };
}

my $ua = HTTP::Tiny->new;

{
    my ($obj, $type, $url, $data) = $ua->post_multipart( 'http://perl-services.de', [ field1 => 'test' ] );
    is $type, 'POST';
    is $url,  'http://perl-services.de';

    ok $data->{content};
    my ($boundary) = split /\x0d/, $data->{content};

    like $boundary, qr/\A-+\w+\z/;

    my ($plain_boundary) = $boundary =~ m{\A-+(\w+)};

    is_deeply $data, {
        headers => {
            'content-type' => "multipart/form-data; boundary=" . $plain_boundary,
        },
        content => "$boundary\x0d\x0aContent-Disposition: form-data; name=\"field1\"\x0d\x0a\x0d\x0atest\x0d\x0a$boundary--\x0d\x0a",
    };
}

done_testing();