HTTP-Promise

 view release on metacpan or  search on metacpan

t/13.header_fields.t  view on Meta::CPAN

    is( $h->name, 'fieldName' );
    $str = q{form-data; name="fieldName"; filename="filename.jpg"};
    $h = HTTP::Promise::Headers::ContentDisposition->new( $str );
    is( $h->disposition, 'form-data' );
    is( $h->name, 'fieldName' );
    is( $h->filename, 'filename.jpg' );
    $str = q{form-data; name="fieldName"; filename="filename.jpg"};
    # perl -MEncode -MURI::Escape -lE 'say URI::Escape::uri_escape_utf8( Encode::decode_utf8( "ファイル.txt" ) )'
    $str = q{attachment; filename*="UTF-8'ja-JP'%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB.txt"};
    $h = HTTP::Promise::Headers::ContentDisposition->new( $str );
    is( $h->filename, 'ファイル.txt' );
    is( $h->filename_charset, 'UTF-8' );
    is( $h->filename_lang, 'ja-JP' );
    $h = HTTP::Promise::Headers::ContentDisposition->new;
    $h->disposition( 'form-data' );
    $h->name( 'someField' );
    is( $h->name, 'someField' );
    $h->filename( 'マイファイル.txt', 'ja-JP' );
    is( "$h", q{form-data; name="someField"; filename*=UTF-8'ja-JP'%E3%83%9E%E3%82%A4%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB.txt} );
};

subtest 'content-range' => sub
{
    use utf8;
    use ok( 'HTTP::Promise::Headers::ContentRange' );
    my $str = q{bytes 0-499/1234};
    my $h = HTTP::Promise::Headers::ContentRange->new( $str );
    is( "$h", $str );
    is( $h->unit, 'bytes' );
    is( $h->range_start, 0 );
    is( $h->range_end, 499 );
    is( $h->size, 1234 );

    $str = q{bytes */1234};
    $h = HTTP::Promise::Headers::ContentRange->new( $str );
    is( "$h", $str );
    is( $h->unit, 'bytes' );
    is( $h->range_start, undef, 'range_start' );
    is( $h->size, 1234 );
    
    $str = q{bytes 42-1233/*};
    $h = HTTP::Promise::Headers::ContentRange->new( $str );
    is( "$h", $str , 'as_string' );
    is( $h->unit, 'bytes' );
    is( $h->range_start, 42 );
    is( $h->range_end, 1233 );
    is( $h->size, '*' );
};

subtest 'content-security-policy' => sub
{
    use ok( 'HTTP::Promise::Headers::ContentSecurityPolicy' );
    my $str = q{default-src 'self'};
    my $h = HTTP::Promise::Headers::ContentSecurityPolicy->new( $str );
    is( "$h", $str );
    is( $h->default_src, "'self'" );
    $str = q{default-src 'self' trusted.com *.trusted.com};
    $h = HTTP::Promise::Headers::ContentSecurityPolicy->new( $str );
    is( "$h", $str );
    is( $h->default_src, q{'self' trusted.com *.trusted.com} );
    $str = q{base-uri https://example.com/; block-all-mixed-content; child-src https://example.com/ https://dev.example.com/; connect-src https://example.com/; default-src 'self'; font-src https://example.com/; form-action https://example.com/ https:...
    $h = HTTP::Promise::Headers::ContentSecurityPolicy->new( $str );
    is( "$h", $str );
    is( $h->base_uri, 'https://example.com/' );
    is( $h->block_all_mixed_content, 1 );
    is( $h->child_src, 'https://example.com/ https://dev.example.com/' );
    is( $h->connect_src, 'https://example.com/' );
    is( $h->default_src, "'self'" );
    is( $h->font_src, 'https://example.com/' );
    is( $h->form_action, 'https://example.com/ https://dev.example.com/' );
    is( $h->frame_ancestors, 'https://example.com/ https://dev.example.com/' );
    is( $h->frame_src, 'https://example.com/' );
    is( $h->img_src, q{'self' img.example.com} );
    is( $h->manifest_src, 'https://example.com/' );
    is( $h->media_src, 'https://example.com/' );
    is( $h->navigate_to, 'https://example.com/ https://dev.example.com/' );
    is( $h->object_src, 'https://example.com/' );
    is( $h->plugin_types, 'application/x-shockwave-flash' );
    is( $h->prefetch_src, 'https://example.com/' );
    is( $h->referrer, '"no-referrer"' );
    is( $h->report_to, 'csp-endpoint' );
    is( $h->report_uri, '/csp-violation-report-endpoint/ https://dev.example.com/report' );
    is( $h->require_sri_for, 'script style' );
    is( $h->require_trusted_types_for, "'script'" );
    is( $h->sandbox, 1 );
    is( $h->script_src, q{'self' js.example.com} );
    is( $h->script_src_elem, 'https://example.com/' );
    is( $h->script_src_attr, 'https://example.com/' );
    is( $h->style_src, 'https://example.com/' );
    is( $h->style_src_attr, 'https://example.com/' );
    is( $h->style_src_elem, 'https://example.com/' );
    is( $h->trusted_types, 1 );
    is( $h->upgrade_insecure_requests, 1 );
    is( $h->worker_src, 'https://example.com/' );
    $h->block_all_mixed_content(0);
    is( $h->block_all_mixed_content, 0 );
};

subtest 'content-type' => sub
{
    use ok( 'HTTP::Promise::Headers::ContentType' );
    my $str = q{text/html; charset=UTF-8};
    my $h = HTTP::Promise::Headers::ContentType->new( $str );
    is( "$h", $str );
    is( $h->type, 'text/html' );
    is( $h->charset, 'UTF-8' );

    $str = q{application/octet-stream};
    $h = HTTP::Promise::Headers::ContentType->new( $str );
    is( "$h", $str );
    is( $h->type, 'application/octet-stream' );
    
    $str = q{multipart/form-data; boundary=something};
    $h = HTTP::Promise::Headers::ContentType->new( $str );
    is( "$h", $str );
    is( $h->type, 'multipart/form-data' );
    is( $h->boundary, 'something' );
    
    $str = q{application/x-www-form-urlencoded};
    $h = HTTP::Promise::Headers::ContentType->new( $str );
    is( "$h", $str );
    is( $h->type, 'application/x-www-form-urlencoded' );
    
    $str = q{multipart/byteranges};
    $h = HTTP::Promise::Headers::ContentType->new( $str );
    is( "$h", $str );
    is( $h->type, 'multipart/byteranges' );
    
    $h = HTTP::Promise::Headers::ContentType->new;
    $h->type( 'text/plain' );
    $h->charset( 'utf-8' );
    is( "$h", 'text/plain; charset=utf-8' );
};

subtest 'expect-ct' => sub
{
    use ok( 'HTTP::Promise::Headers::ExpectCT' );
    my $str = q{max-age=86400, enforce, report-uri="https://foo.example.com/report"};
    my $h = HTTP::Promise::Headers::ExpectCT->new( $str );
    is( "$h", $str );
    is( $h->max_age, 86400 );
    is( $h->enforce, 1 );



( run in 1.317 second using v1.01-cache-2.11-cpan-437f7b0c052 )