<commit_before>#!perl

# Copyright (C) 2008, <NAME>.

use strict;
use warnings;

use Test::More tests => 201;

use Mojo::Filter::Chunked;
use Mojo::Headers;

# When will I learn?
# The answer to life's problems aren't at the bottom of a bottle,
# they're on TV!
use_ok('Mojo::File');
use_ok('Mojo::Content');
use_ok('Mojo::Content::MultiPart');
use_ok('Mojo::Cookie::Request');
use_ok('Mojo::Cookie::Response');
use_ok('Mojo::Headers');
use_ok('Mojo::Message::Request');
use_ok('Mojo::Message::Response');

# Parse HTTP 1.1 start line, no headers and body
my $req = Mojo::Message::Request->new;
$req->parse("GET / HTTP/1.1\x0d\x0a\x0d\x0a");
is($req->state, 'done');
is($req->method, 'GET');
is($req->major_version, 1);
is($req->minor_version, 1);
is($req->url, '/');

# Parse HTTP 1.0 start line and headers, no body
$req = Mojo::Message::Request->new;
$req->parse("GET /foo/bar/baz.html HTTP/1.0\x0d\x0a");
$req->parse("Content-Type: text/plain\x0d\x0a");
$req->parse("Content-Length: 0\x0d\x0a\x0d\x0a");
is($req->state, 'done');
is($req->method, 'GET');
is($req->major_version, 1);
is($req->minor_version, 0);
is($req->url, '/foo/bar/baz.html');
is($req->headers->content_type, 'text/plain');
is($req->headers->content_length, 0);

# Parse full HTTP 1.0 request
$req = Mojo::Message::Request->new;
$req->parse('GET /foo/bar/baz.html?fo');
$req->parse("o=13#23 HTTP/1.0\x0d\x0aContent");
$req->parse('-Type: text/');
$req->parse("plain\x0d\x0aContent-Length: 27\x0d\x0a\x0d\x0aHell");
$req->parse("o World!\n1234\nlalalala\n");
is($req->state, 'done');
is($req->method, 'GET');
is($req->major_version, 1);
is($req->minor_version, 0);
is($req->url, '/foo/bar/baz.html?foo=13#23');
is($req->headers->content_type, 'text/plain');
is($req->headers->content_length, 27);

# Parse HTTP 0.9 request
$req = Mojo::Message::Request->new;
$req->parse("GET /\x0d\x0a\x0d\x0a");
is($req->state, 'done');
is($req->method, 'GET');
is($req->major_version, 0);
is($req->minor_version, 9);
is($req->url, '/');

# Parse HTTP 1.1 chunked request
$req = Mojo::Message::Request->new;
$req->parse("POST /foo/bar/baz.html?foo=13#23 HTTP/1.1\x0d\x0a");
$req->parse("Content-Type: text/plain\x0d\x0a");
$req->parse("Transfer-Encoding: chunked\x0d\x0a\x0d\x0a");
$req->parse("4\x0d\x0a");
$req->parse("abcd\x0d\x0a");
$req->parse("9\x0d\x0a");
$req->parse("abcdefghi\x0d\x0a");
$req->parse("0\x0d\x0a");
is($req->state, 'done');
is($req->method, 'POST');
is($req->major_version, 1);
is($req->minor_version, 1);
is($req->url, '/foo/bar/baz.html?foo=13#23');
is($req->headers->content_type, 'text/plain');
is($req->content->file->length, 13);
is($req->content->file->slurp, 'abcdabcdefghi');

# Parse HTTP 1.1 "x-application-urlencoded"
$req = Mojo::Message::Request->new;
$req->parse("POST /foo/bar/baz.html?foo=13#23 HTTP/1.1\x0d\x0a");
$req->parse("Content-Length: 26\x0d\x0a");
$req->parse("Content-Type: x-application-urlencoded\x0d\x0a\x0d\x0a");
$req->parse('foo=bar& tset=23+;&foo=bar');
is($req->state, 'done');
is($req->method, 'POST');
is($req->major_version, 1);
is($req->minor_version, 1);
is($req->url, '/foo/bar/baz.html?foo=13#23');
is($req->headers->content_type, 'x-application-urlencoded');
is($req->content->file->length, 26);
is($req->content->file->slurp, 'foo=bar& tset=23+;&foo=bar');
is($req->body_params, 'foo=bar&+tset=23+&foo=bar');
is_deeply($req->body_params->to_hash->{foo}, [qw/bar bar/]);
is($req->body_params->to_hash->{' tset'}, '23 ');
is_deeply($req->params->to_hash->{foo}, [qw/bar bar 13/]);

# Parse HTTP 1.1 "application/x-www-form-urlencoded"
$req = Mojo::Message::Request->new;
$req->parse("POST /foo/bar/baz.html?foo=13#23 HTTP/1.1\x0d\x0a");
$req->parse("Content-Length: 26\x0d\x0a");
$req->parse("Content-Type: application/x-www-form-urlencoded\x0d\x0a");
$req->parse("\x0d\x0afoo=bar& tset=23+;&foo=bar");
is($req->state, 'done');
is($req->method, 'POST');
is($req->major_version, 1);
is($req->minor_version, 1);
is($req->url, '/foo/bar/baz.html?foo=13#23');
is($req->headers->content_type, 'application/x-www-form-urlencoded');
is($req->content->file->length, 26);
is($req->content->file->slurp, 'foo=bar& tset=23+;&foo=bar');
is($req->body_params, 'foo=bar&+tset=23+&foo=bar');
is_deeply($req->body_params->to_hash->{foo}, [qw/bar bar/]);
is($req->body_params->to_hash->{' tset'}, '23 ');
is_deeply($req->params->to_hash->{foo}, [qw/bar bar 13/]);
is_deeply($req->param('foo'), [qw/bar bar 13/]);
is($req->param(' tset'), '23 ');

# Parse HTTP 1.1 chunked request with trailing headers
$req = Mojo::Message::Request->new;
$req->parse("POST /foo/bar/baz.html?foo=13&bar=23#23 HTTP/1.1\x0d\x0a");
$req->parse("Content-Type: text/plain\x0d\x0a");
$req->parse("Transfer-Encoding: chunked\x0d\x0a");
$req->parse("Trailer: X-Trailer1; X-Trailer2\x0d\x0a\x0d\x0a");
$req->parse("4\x0d\x0a");
$req->parse("abcd\x0d\x0a");
$req->parse("9\x0d\x0a");<commit_msg>New tests for setting single and muliple values in $req->param()<commit_after>#!perl

# Copyright (C) 2008, <NAME>.

use strict;
use warnings;

use Test::More tests => 203;

use Mojo::Filter::Chunked;
use Mojo::Headers;

# When will I learn?
# The answer to life's problems aren't at the bottom of a bottle,
# they're on TV!
use_ok('Mojo::File');
use_ok('Mojo::Content');
use_ok('Mojo::Content::MultiPart');
use_ok('Mojo::Cookie::Request');
use_ok('Mojo::Cookie::Response');
use_ok('Mojo::Headers');
use_ok('Mojo::Message::Request');
use_ok('Mojo::Message::Response');

# Parse HTTP 1.1 start line, no headers and body
my $req = Mojo::Message::Request->new;
$req->parse("GET / HTTP/1.1\x0d\x0a\x0d\x0a");
is($req->state, 'done');
is($req->method, 'GET');
is($req->major_version, 1);
is($req->minor_version, 1);
is($req->url, '/');

# Parse HTTP 1.0 start line and headers, no body
$req = Mojo::Message::Request->new;
$req->parse("GET /foo/bar/baz.html HTTP/1.0\x0d\x0a");
$req->parse("Content-Type: text/plain\x0d\x0a");
$req->parse("Content-Length: 0\x0d\x0a\x0d\x0a");
is($req->state, 'done');
is($req->method, 'GET');
is($req->major_version, 1);
is($req->minor_version, 0);
is($req->url, '/foo/bar/baz.html');
is($req->headers->content_type, 'text/plain');
is($req->headers->content_length, 0);

# Parse full HTTP 1.0 request
$req = Mojo::Message::Request->new;
$req->parse('GET /foo/bar/baz.html?fo');
$req->parse("o=13#23 HTTP/1.0\x0d\x0aContent");
$req->parse('-Type: text/');
$req->parse("plain\x0d\x0aContent-Length: 27\x0d\x0a\x0d\x0aHell");
$req->parse("o World!\n1234\nlalalala\n");
is($req->state, 'done');
is($req->method, 'GET');
is($req->major_version, 1);
is($req->minor_version, 0);
is($req->url, '/foo/bar/baz.html?foo=13#23');
is($req->headers->content_type, 'text/plain');
is($req->headers->content_length, 27);

# Parse HTTP 0.9 request
$req = Mojo::Message::Request->new;
$req->parse("GET /\x0d\x0a\x0d\x0a");
is($req->state, 'done');
is($req->method, 'GET');
is($req->major_version, 0);
is($req->minor_version, 9);
is($req->url, '/');

# Parse HTTP 1.1 chunked request
$req = Mojo::Message::Request->new;
$req->parse("POST /foo/bar/baz.html?foo=13#23 HTTP/1.1\x0d\x0a");
$req->parse("Content-Type: text/plain\x0d\x0a");
$req->parse("Transfer-Encoding: chunked\x0d\x0a\x0d\x0a");
$req->parse("4\x0d\x0a");
$req->parse("abcd\x0d\x0a");
$req->parse("9\x0d\x0a");
$req->parse("abcdefghi\x0d\x0a");
$req->parse("0\x0d\x0a");
is($req->state, 'done');
is($req->method, 'POST');
is($req->major_version, 1);
is($req->minor_version, 1);
is($req->url, '/foo/bar/baz.html?foo=13#23');
is($req->headers->content_type, 'text/plain');
is($req->content->file->length, 13);
is($req->content->file->slurp, 'abcdabcdefghi');

# Parse HTTP 1.1 "x-application-urlencoded"
$req = Mojo::Message::Request->new;
$req->parse("POST /foo/bar/baz.html?foo=13#23 HTTP/1.1\x0d\x0a");
$req->parse("Content-Length: 26\x0d\x0a");
$req->parse("Content-Type: x-application-urlencoded\x0d\x0a\x0d\x0a");
$req->parse('foo=bar& tset=23+;&foo=bar');
is($req->state, 'done');
is($req->method, 'POST');
is($req->major_version, 1);
is($req->minor_version, 1);
is($req->url, '/foo/bar/baz.html?foo=13#23');
is($req->headers->content_type, 'x-application-urlencoded');
is($req->content->file->length, 26);
is($req->content->file->slurp, 'foo=bar& tset=23+;&foo=bar');
is($req->body_params, 'foo=bar&+tset=23+&foo=bar');
is_deeply($req->body_params->to_hash->{foo}, [qw/bar bar/]);
is($req->body_params->to_hash->{' tset'}, '23 ');
is_deeply($req->params->to_hash->{foo}, [qw/bar bar 13/]);

# Parse HTTP 1.1 "application/x-www-form-urlencoded"
$req = Mojo::Message::Request->new;
$req->parse("POST /foo/bar/baz.html?foo=13#23 HTTP/1.1\x0d\x0a");
$req->parse("Content-Length: 26\x0d\x0a");
$req->parse("Content-Type: application/x-www-form-urlencoded\x0d\x0a");
$req->parse("\x0d\x0afoo=bar& tset=23+;&foo=bar");
is($req->state, 'done');
is($req->method, 'POST');
is($req->major_version, 1);
is($req->minor_version, 1);
is($req->url, '/foo/bar/baz.html?foo=13#23');
is($req->headers->content_type, 'application/x-www-form-urlencoded');
is($req->content->file->length, 26);
is($req->content->file->slurp, 'foo=bar& tset=23+;&foo=bar');
is($req->body_params, 'foo=bar&+tset=23+&foo=bar');
is_deeply($req->body_params->to_hash->{foo}, [qw/bar bar/]);
is($req->body_params->to_hash->{' tset'}, '23 ');
is_deeply($req->params->to_hash->{foo}, [qw/bar bar 13/]);
is_deeply($req->param('foo'), [qw/bar bar 13/]);
is($req->param(' tset'), '23 ');

{
    $req->param('set', 'single'); 
    is($req->param('set'),'single', "setting a single param works"); 
}
{
    $req->param('multi', 1,2,3);
    is_deeply($req->param('multi'), [qw/1 2 3/], "setting multiple param works");
}

# Parse HTTP 1.1 chunked request with trailing headers
$req = Mojo::Message::Request->new;
$req->parse("POST /foo/bar/baz.html?foo=13&bar=23#23 HTTP/1.1\x0d\x0a");
$req->parse("Content-Type: text/plain\x0d\x0a");
$req->parse("Transfer-Encoding: chunked\x0d\x0a");
$req->parse("Trailer: X-Trailer1; X-Trailer2\x0d\x0a\x0d\x0a");
$req->parse("4\x0d\x0a");
$req->parse("abcd\x0d\x0a");
$req->parse("9\x0d\x0a");
{'fraction_non_alphanumeric': 0.2665536497806143, 'fraction_numerical': 0.04327881930594336, 'mean_word_length': 6.215107913669065, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 272, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3169716', 'n_tokens_mistral': 4480, 'n_tokens_neox': 4259, 'n_words': 626}