Skip to content

Instantly share code, notes, and snippets.

@chansen
Created November 24, 2011 10:04
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save chansen/1391017 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use HTTP::Response;
my $response = HTTP::Response->new(
200, 'OK', [ 'Content-Type' => 'multipart/form-data' ]
);
$response->protocol('HTTP/1.1');
$response->date(time);
$response->server('Foo/1.0');
my $name = HTTP::Message->new([
'Content-Type' => 'text/plain; charset=UTF-8',
'Content-Disposition' => 'form-data; name="name"',
], 'John Doe');
$response->add_part($name);
my $note = HTTP::Message->new([
'Content-Type' => 'text/plain; charset=UTF-8',
'Content-Disposition' => 'form-data; name="note"',
], <<'NOTE');
Resources:
o http://search.cpan.org/dist/HTTP-Message/lib/HTTP/Message.pm
o http://search.cpan.org/dist/HTTP-Message/lib/HTTP/Response.pm
o http://tools.ietf.org/html/rfc2388
o http://tools.ietf.org/html/rfc2616
NOTE
$response->add_part($note);
my $blob = HTTP::Message->new([
'Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'form-data; name="blob"; filename="blob.bin"',
]);
$blob->add_content('a chunk');
$blob->add_content(' of data');
$response->add_part($blob);
print $response->as_string;
__END__
HTTP/1.1 200 OK
Date: Thu, 24 Nov 2011 10:03:25 GMT
Server: Foo/1.0
Content-Type: multipart/form-data; boundary=xYzZY
--xYzZY
Content-Type: text/plain; charset=UTF-8
Content-Disposition: form-data; name="name"
John Doe
--xYzZY
Content-Type: text/plain; charset=UTF-8
Content-Disposition: form-data; name="note"
Resources:
o http://search.cpan.org/dist/HTTP-Message/lib/HTTP/Message.pm
o http://search.cpan.org/dist/HTTP-Message/lib/HTTP/Response.pm
o http://tools.ietf.org/html/rfc2388
o http://tools.ietf.org/html/rfc2616
--xYzZY
Content-Type: application/octet-stream
Content-Disposition: form-data; name="blob"; filename="blob.bin"
a chunk of data
--xYzZY--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment