when a POST supplies content encoding, dont assume UTF8
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Request / PartData.pm
CommitLineData
0d94e986 1package Catalyst::Request::PartData;
2
3use Moose;
4use HTTP::Headers;
5
6has [qw/raw_data name size/] => (is=>'ro', required=>1);
7
8has headers => (
9 is=>'ro',
10 required=>1,
11 handles=>[qw/content_type content_encoding content_type_charset/]);
12
13sub build_from_part_data {
14 my ($class, $part_data) = @_;
15 return $part_data->{data} unless $class->part_data_has_complex_headers($part_data);
16 return $class->new(
17 raw_data => $part_data->{data},
18 name => $part_data->{name},
19 size => $part_data->{size},
20 headers => HTTP::Headers->new(%{ $part_data->{headers} }));
21}
22
23sub part_data_has_complex_headers {
24 my ($class, $part_data) = @_;
25 return scalar keys %{$part_data->{headers}} > 1 ? 1:0;
26}
27
28__PACKAGE__->meta->make_immutable;
29
30=head1 NAME
31
32Catalyst::Request::Upload - handles file upload requests
33
34=head1 SYNOPSIS
35
36 my $data_part =
37
38To specify where Catalyst should put the temporary files, set the 'uploadtmp'
39option in the Catalyst config. If unset, Catalyst will use the system temp dir.
40
41 __PACKAGE__->config( uploadtmp => '/path/to/tmpdir' );
42
43See also L<Catalyst>.
44
45=head1 DESCRIPTION
46
47=head1 ATTRIBUTES
48
49This class defines the following immutable attributes
50
51=head2 raw_data
52
53The raw data as returned via L<HTTP::Body>.
54
55=head2 name
56
57The part name that gets extracted from the content-disposition header.
58
59=head2 size
60
61The raw byte count (over http) of the data. This is not the same as the character
62length
63
64=head2 headers
65
66An L<HTTP::Headers> object that represents the submitted headers of the POST. This
67object will handle the following methods:
68
69=head3 content_type
70
71=head3 content_encoding
72
73=head3 content_type_charset
74
75These three methods are the same as methods described in L<HTTP::Headers>.
76
77=head1 METHODS
78
79=head2 build_from_part_data
80
81Factory method to build an object from part data returned by L<HTTP::Body>
82
83=head2 part_data_has_complex_headers
84
85Returns true if there more than one header (indicates the part data is complex and
86contains content type and encoding information.).
87
88=head1 AUTHORS
89
90Catalyst Contributors, see Catalyst.pm
91
92=head1 COPYRIGHT
93
94This library is free software. You can redistribute it and/or modify
95it under the same terms as Perl itself.
96
97=cut