copy gitweblite soruce code
|
1 |
package Mojo::Content; |
2 |
use Mojo::Base 'Mojo::EventEmitter'; |
|
3 | ||
4 |
use Carp 'croak'; |
|
upgraded Mojolicious to v3.7...
|
5 |
BEGIN {eval {require Compress::Raw::Zlib; import Compress::Raw::Zlib qw(WANT_GZIP Z_STREAM_END)}} |
copy gitweblite soruce code
|
6 |
use Mojo::Headers; |
7 | ||
upgraded Mojolicious to v3.7...
|
8 |
has [qw(auto_relax relaxed skip_body)]; |
9 |
has headers => sub { Mojo::Headers->new }; |
|
10 |
has max_buffer_size => sub { $ENV{MOJO_MAX_BUFFER_SIZE} || 262144 }; |
|
copy gitweblite soruce code
|
11 |
has max_leftover_size => sub { $ENV{MOJO_MAX_LEFTOVER_SIZE} || 262144 }; |
12 | ||
13 |
sub body_contains { |
|
14 |
croak 'Method "body_contains" not implemented by subclass'; |
|
15 |
} |
|
16 | ||
17 |
sub body_size { croak 'Method "body_size" not implemented by subclass' } |
|
18 | ||
19 |
sub boundary { |
|
upgraded Mojolicious to v3.7...
|
20 |
return undef unless my $type = shift->headers->content_type; |
update Mojolicious to 4.57
|
21 |
$type =~ m!multipart.*boundary\s*=\s*(?:"([^"]+)"|([\w'(),.:?\-+/]+))!i |
upgraded Mojolicious to v3.7...
|
22 |
and return defined $1 ? $1 : $2; |
23 |
return undef; |
|
copy gitweblite soruce code
|
24 |
} |
25 | ||
upgraded Mojolicious to v3.7...
|
26 |
sub build_body { shift->_build('get_body_chunk') } |
27 |
sub build_headers { shift->_build('get_header_chunk') } |
|
copy gitweblite soruce code
|
28 | |
29 |
sub charset { |
|
update Mojolicious to 4.57
|
30 |
my $type = do { my $type = shift->headers->content_type; defined $type ? $type : ''}; |
31 |
return $type =~ /charset\s*=\s*"?([^"\s;]+)"?/i ? $1 : undef; |
|
copy gitweblite soruce code
|
32 |
} |
33 | ||
34 |
sub clone { |
|
35 |
my $self = shift; |
|
upgraded Mojolicious to v3.7...
|
36 |
return undef if $self->is_dynamic; |
copy gitweblite soruce code
|
37 |
return $self->new(headers => $self->headers->clone); |
38 |
} |
|
39 | ||
40 |
sub generate_body_chunk { |
|
41 |
my ($self, $offset) = @_; |
|
42 | ||
43 |
$self->emit(drain => $offset) |
|
upgraded Mojolicious to v3.7...
|
44 |
if !delete $self->{delay} && !length(defined $self->{body_buffer} ? $self->{body_buffer} : ''); |
update Mojolicious and added...
|
45 |
my $chunk = do { my $tmp = delete $self->{body_buffer}; defined $tmp ? $tmp : '' }; |
copy gitweblite soruce code
|
46 |
return $self->{eof} ? '' : undef unless length $chunk; |
47 | ||
48 |
return $chunk; |
|
49 |
} |
|
50 | ||
51 |
sub get_body_chunk { |
|
52 |
croak 'Method "get_body_chunk" not implemented by subclass'; |
|
53 |
} |
|
54 | ||
55 |
sub get_header_chunk { |
|
56 |
my ($self, $offset) = @_; |
|
57 | ||
58 |
unless (defined $self->{header_buffer}) { |
|
59 |
my $headers = $self->headers->to_string; |
|
60 |
$self->{header_buffer} |
|
61 |
= $headers ? "$headers\x0d\x0a\x0d\x0a" : "\x0d\x0a"; |
|
62 |
} |
|
63 | ||
upgraded Mojolicious to v3.7...
|
64 |
return substr $self->{header_buffer}, $offset, 131072; |
copy gitweblite soruce code
|
65 |
} |
66 | ||
67 |
sub header_size { length shift->build_headers } |
|
68 | ||
upgraded Mojolicious to v3.7...
|
69 |
sub is_chunked { !!shift->headers->transfer_encoding } |
copy gitweblite soruce code
|
70 | |
update Mojolicious 4.07
|
71 |
sub is_compressed { (do {my $tmp = shift->headers->content_encoding; defined $tmp ? $tmp : ''}) =~ /^gzip$/i } |
upgraded Mojolicious to v3.7...
|
72 | |
update Mojolicious 4.07
|
73 |
sub is_dynamic { $_[0]{dynamic} && !defined $_[0]->headers->content_length } |
upgraded Mojolicious to v3.7...
|
74 | |
75 |
sub is_finished { my $tmp = shift->{state}; (defined $tmp ? $tmp : '') eq 'finished' } |
|
copy gitweblite soruce code
|
76 | |
upgraded Mojolicious to v3.7...
|
77 |
sub is_limit_exceeded { !!shift->{limit} } |
copy gitweblite soruce code
|
78 | |
79 |
sub is_multipart {undef} |
|
80 | ||
upgraded Mojolicious to v3.7...
|
81 |
sub is_parsing_body { my $tmp = shift->{state}; (defined $tmp ? $tmp : '') eq 'body' } |
copy gitweblite soruce code
|
82 | |
83 |
sub leftovers { shift->{buffer} } |
|
84 | ||
85 |
sub parse { |
|
86 |
my $self = shift; |
|
87 | ||
update Mojolicious and added...
|
88 |
# Headers |
upgraded Mojolicious to v3.7...
|
89 |
$self->_parse_until_body(@_); |
copy gitweblite soruce code
|
90 |
return $self if $self->{state} eq 'headers'; |
upgraded Mojolicious to v3.7...
|
91 |
$self->emit('body') unless $self->{body}++; |
copy gitweblite soruce code
|
92 | |
update Mojolicious and added...
|
93 |
# Chunked content |
upgraded Mojolicious to v3.7...
|
94 |
$self->{real_size} = defined $self->{real_size} ? $self->{real_size} : 0; |
95 |
if ($self->is_chunked && $self->{state} ne 'headers') { |
|
copy gitweblite soruce code
|
96 |
$self->_parse_chunked; |
upgraded Mojolicious to v3.7...
|
97 |
$self->{state} = 'finished' if (defined $self->{chunk_state} ? $self->{chunk_state} : '') eq 'finished'; |
copy gitweblite soruce code
|
98 |
} |
99 | ||
100 |
# Not chunked, pass through to second buffer |
|
101 |
else { |
|
102 |
$self->{real_size} += length $self->{pre_buffer}; |
|
upgraded Mojolicious to v3.7...
|
103 |
my $limit = $self->is_finished |
104 |
&& length($self->{buffer}) > $self->max_leftover_size; |
|
105 |
$self->{buffer} .= $self->{pre_buffer} unless $limit; |
|
copy gitweblite soruce code
|
106 |
$self->{pre_buffer} = ''; |
107 |
} |
|
108 | ||
upgraded Mojolicious to v3.7...
|
109 |
# No content |
110 |
if ($self->skip_body) { |
|
111 |
$self->{state} = 'finished'; |
|
112 |
return $self; |
|
113 |
} |
|
114 | ||
115 |
# Relaxed parsing |
|
116 |
my $headers = $self->headers; |
|
117 |
if ($self->auto_relax) { |
|
update Mojolicious 4.07
|
118 |
my $connection = defined $headers->connection ? $headers->connection : ''; |
119 |
my $len = defined $headers->content_length ? $headers->content_length : ''; |
|
upgraded Mojolicious to v3.7...
|
120 |
$self->relaxed(1) |
121 |
if !length $len && ($connection =~ /close/i || $headers->content_type); |
|
122 |
} |
|
123 | ||
copy gitweblite soruce code
|
124 |
# Chunked or relaxed content |
125 |
if ($self->is_chunked || $self->relaxed) { |
|
update Mojolicious and added...
|
126 |
$self->{size} += length($self->{buffer} = defined $self->{buffer} ? $self->{buffer} : ''); |
upgraded Mojolicious to v3.7...
|
127 |
$self->_uncompress($self->{buffer}); |
128 |
$self->{buffer} = ''; |
|
copy gitweblite soruce code
|
129 |
} |
130 | ||
131 |
# Normal content |
|
132 |
else { |
|
upgraded Mojolicious to v3.7...
|
133 |
my $len = $headers->content_length || 0; |
copy gitweblite soruce code
|
134 |
$self->{size} ||= 0; |
upgraded Mojolicious to v3.7...
|
135 |
if ((my $need = $len - $self->{size}) > 0) { |
update Mojolicious and added...
|
136 |
my $len = length $self->{buffer}; |
137 |
my $chunk = substr $self->{buffer}, 0, $need > $len ? $len : $need, ''; |
|
upgraded Mojolicious to v3.7...
|
138 |
$self->_uncompress($chunk); |
copy gitweblite soruce code
|
139 |
$self->{size} += length $chunk; |
140 |
} |
|
141 |
$self->{state} = 'finished' if $len <= $self->progress; |
|
142 |
} |
|
143 | ||
144 |
return $self; |
|
145 |
} |
|
146 | ||
147 |
sub parse_body { |
|
148 |
my $self = shift; |
|
149 |
$self->{state} = 'body'; |
|
150 |
return $self->parse(@_); |
|
151 |
} |
|
152 | ||
153 |
sub progress { |
|
154 |
my $self = shift; |
|
upgraded Mojolicious to v3.7...
|
155 |
return 0 unless my $state = $self->{state}; |
update Mojolicious 4.07
|
156 |
return 0 unless $state eq 'body' || $state eq 'finished'; |
copy gitweblite soruce code
|
157 |
return $self->{raw_size} - ($self->{header_size} || 0); |
158 |
} |
|
159 | ||
160 |
sub write { |
|
161 |
my ($self, $chunk, $cb) = @_; |
|
162 | ||
163 |
$self->{dynamic} = 1; |
|
164 |
if (defined $chunk) { $self->{body_buffer} .= $chunk } |
|
update Mojolicious and added...
|
165 |
else { $self->{delay} = 1 } |
copy gitweblite soruce code
|
166 |
$self->once(drain => $cb) if $cb; |
167 |
$self->{eof} = 1 if defined $chunk && $chunk eq ''; |
|
upgraded Mojolicious to v3.7...
|
168 | |
169 |
return $self; |
|
copy gitweblite soruce code
|
170 |
} |
171 | ||
172 |
sub write_chunk { |
|
173 |
my ($self, $chunk, $cb) = @_; |
|
174 |
$self->headers->transfer_encoding('chunked') unless $self->is_chunked; |
|
175 |
$self->write(defined $chunk ? $self->_build_chunk($chunk) : $chunk, $cb); |
|
176 |
$self->{eof} = 1 if defined $chunk && $chunk eq ''; |
|
upgraded Mojolicious to v3.7...
|
177 |
return $self; |
copy gitweblite soruce code
|
178 |
} |
179 | ||
180 |
sub _build { |
|
upgraded Mojolicious to v3.7...
|
181 |
my ($self, $method) = @_; |
copy gitweblite soruce code
|
182 | |
183 |
my $buffer = ''; |
|
184 |
my $offset = 0; |
|
185 |
while (1) { |
|
186 | ||
187 |
# No chunk yet, try again |
|
upgraded Mojolicious to v3.7...
|
188 |
next unless defined(my $chunk = $self->$method($offset)); |
copy gitweblite soruce code
|
189 | |
190 |
# End of part |
|
upgraded Mojolicious to v3.7...
|
191 |
last unless my $len = length $chunk; |
copy gitweblite soruce code
|
192 | |
upgraded Mojolicious to v3.7...
|
193 |
$offset += $len; |
copy gitweblite soruce code
|
194 |
$buffer .= $chunk; |
195 |
} |
|
196 | ||
197 |
return $buffer; |
|
198 |
} |
|
199 | ||
200 |
sub _build_chunk { |
|
201 |
my ($self, $chunk) = @_; |
|
202 | ||
203 |
# End |
|
upgraded Mojolicious to v3.7...
|
204 |
return "\x0d\x0a0\x0d\x0a\x0d\x0a" if length $chunk == 0; |
copy gitweblite soruce code
|
205 | |
upgraded Mojolicious to v3.7...
|
206 |
# First chunk has no leading CRLF |
207 |
my $crlf = $self->{chunks}++ ? "\x0d\x0a" : ''; |
|
208 |
return $crlf . sprintf('%x', length $chunk) . "\x0d\x0a$chunk"; |
|
copy gitweblite soruce code
|
209 |
} |
210 | ||
211 |
sub _parse_chunked { |
|
212 |
my $self = shift; |
|
213 | ||
214 |
# Trailing headers |
|
215 |
return $self->_parse_chunked_trailing_headers |
|
upgraded Mojolicious to v3.7...
|
216 |
if (defined $self->{chunk_state} ? $self->{chunk_state} : '') eq 'trailing_headers'; |
copy gitweblite soruce code
|
217 | |
upgraded Mojolicious to v3.7...
|
218 |
while (my $len = length $self->{pre_buffer}) { |
copy gitweblite soruce code
|
219 | |
upgraded Mojolicious to v3.7...
|
220 |
# Start new chunk (ignore the chunk extension) |
221 |
unless ($self->{chunk_len}) { |
|
222 |
last |
|
update Mojolicious to 4.57
|
223 |
unless $self->{pre_buffer} =~ s/^(?:\x0d?\x0a)?([0-9a-fA-F]+).*\x0a//; |
upgraded Mojolicious to v3.7...
|
224 |
next if $self->{chunk_len} = hex $1; |
copy gitweblite soruce code
|
225 | |
226 |
# Last chunk |
|
upgraded Mojolicious to v3.7...
|
227 |
$self->{chunk_state} = 'trailing_headers'; |
228 |
last; |
|
copy gitweblite soruce code
|
229 |
} |
230 | ||
upgraded Mojolicious to v3.7...
|
231 |
# Remove as much as possible from payload |
232 |
$len = $self->{chunk_len} if $self->{chunk_len} < $len; |
|
233 |
$self->{buffer} .= substr $self->{pre_buffer}, 0, $len, ''; |
|
234 |
$self->{real_size} += $len; |
|
235 |
$self->{chunk_len} -= $len; |
|
copy gitweblite soruce code
|
236 |
} |
237 | ||
238 |
# Trailing headers |
|
239 |
$self->_parse_chunked_trailing_headers |
|
upgraded Mojolicious to v3.7...
|
240 |
if (defined $self->{chunk_state} ? $self->{chunk_state} : '') eq 'trailing_headers'; |
241 | ||
242 |
# Check buffer size |
|
243 |
$self->{limit} = $self->{state} = 'finished' |
|
244 |
if length(defined $self->{pre_buffer} ? $self->{pre_buffer} : '') > $self->max_buffer_size; |
|
copy gitweblite soruce code
|
245 |
} |
246 | ||
247 |
sub _parse_chunked_trailing_headers { |
|
248 |
my $self = shift; |
|
249 | ||
upgraded Mojolicious to v3.7...
|
250 |
my $headers = $self->headers->parse(delete $self->{pre_buffer}); |
251 |
return unless $headers->is_finished; |
|
252 |
$self->{chunk_state} = 'finished'; |
|
253 | ||
254 |
# Replace Transfer-Encoding with Content-Length |
|
255 |
$headers->remove('Transfer-Encoding'); |
|
256 |
$headers->content_length($self->{real_size}) unless $headers->content_length; |
|
copy gitweblite soruce code
|
257 |
} |
258 | ||
259 |
sub _parse_headers { |
|
260 |
my $self = shift; |
|
261 | ||
upgraded Mojolicious to v3.7...
|
262 |
my $headers = $self->headers->parse(delete $self->{pre_buffer}); |
263 |
return unless $headers->is_finished; |
|
264 |
$self->{state} = 'body'; |
|
265 | ||
266 |
# Take care of leftovers |
|
267 |
my $leftovers = $self->{pre_buffer} = $headers->leftovers; |
|
268 |
$self->{header_size} = $self->{raw_size} - length $leftovers; |
|
269 |
$self->emit('body') unless $self->{body}++; |
|
270 |
} |
|
271 | ||
272 |
sub _parse_until_body { |
|
273 |
my ($self, $chunk) = @_; |
|
274 | ||
275 |
$self->{raw_size} += length($chunk = defined $chunk ? $chunk : ''); |
|
276 |
$self->{pre_buffer} .= $chunk; |
|
277 | ||
278 |
unless ($self->{state}) { |
|
279 |
$self->{header_size} = $self->{raw_size} - length $self->{pre_buffer}; |
|
update Mojolicious and added...
|
280 |
$self->{state} = 'headers'; |
copy gitweblite soruce code
|
281 |
} |
upgraded Mojolicious to v3.7...
|
282 |
$self->_parse_headers if (defined $self->{state} ? $self->{state} : '') eq 'headers'; |
283 |
} |
|
284 | ||
285 |
sub _uncompress { |
|
286 |
my ($self, $chunk) = @_; |
|
287 | ||
288 |
# No compression |
|
289 |
return $self->emit(read => $chunk) unless $self->is_compressed; |
|
290 | ||
291 |
# Uncompress |
|
292 |
$self->{post_buffer} .= $chunk; |
|
293 |
my $gz = $self->{gz} = defined $self->{gz} ? $self->{gz} : |
|
294 |
Compress::Raw::Zlib::Inflate->new(WindowBits => WANT_GZIP()); |
|
295 |
my $status = $gz->inflate(\$self->{post_buffer}, my $out); |
|
296 |
$self->emit(read => $out) if defined $out; |
|
297 | ||
298 |
# Replace Content-Encoding with Content-Length |
|
299 |
$self->headers->content_length($gz->total_out)->remove('Content-Encoding') |
|
300 |
if $status == Z_STREAM_END(); |
|
301 | ||
302 |
# Check buffer size |
|
303 |
$self->{limit} = $self->{state} = 'finished' |
|
304 |
if length(defined $self->{post_buffer} ? $self->{post_buffer} : '') > $self->max_buffer_size; |
|
copy gitweblite soruce code
|
305 |
} |
306 | ||
307 |
1; |
|
308 | ||
update Mojolicious to 4.57
|
309 |
=encoding utf8 |
310 | ||
copy gitweblite soruce code
|
311 |
=head1 NAME |
312 | ||
upgraded Mojolicious to v3.7...
|
313 |
Mojo::Content - HTTP content base class |
copy gitweblite soruce code
|
314 | |
315 |
=head1 SYNOPSIS |
|
316 | ||
upgraded Mojolicious to v3.7...
|
317 |
package Mojo::Content::MyContent; |
copy gitweblite soruce code
|
318 |
use Mojo::Base 'Mojo::Content'; |
319 | ||
upgraded Mojolicious to v3.7...
|
320 |
sub body_contains {...} |
321 |
sub body_size {...} |
|
322 |
sub get_body_chunk {...} |
|
323 | ||
copy gitweblite soruce code
|
324 |
=head1 DESCRIPTION |
325 | ||
upgraded Mojolicious to v3.7...
|
326 |
L<Mojo::Content> is an abstract base class for HTTP content as described in |
327 |
RFC 2616. |
|
copy gitweblite soruce code
|
328 | |
329 |
=head1 EVENTS |
|
330 | ||
update Mojolicious and added...
|
331 |
L<Mojo::Content> inherits all events from L<Mojo::EventEmitter> and can emit |
332 |
the following new ones. |
|
copy gitweblite soruce code
|
333 | |
update Mojolicious and added...
|
334 |
=head2 body |
copy gitweblite soruce code
|
335 | |
upgraded Mojolicious to v3.7...
|
336 |
$content->on(body => sub { |
337 |
my $content = shift; |
|
copy gitweblite soruce code
|
338 |
... |
339 |
}); |
|
340 | ||
upgraded Mojolicious to v3.7...
|
341 |
Emitted once all headers have been parsed and the body starts. |
copy gitweblite soruce code
|
342 | |
upgraded Mojolicious to v3.7...
|
343 |
$content->on(body => sub { |
copy gitweblite soruce code
|
344 |
my $content = shift; |
upgraded Mojolicious to v3.7...
|
345 |
$content->auto_upgrade(0) if $content->headers->header('X-No-MultiPart'); |
copy gitweblite soruce code
|
346 |
}); |
347 | ||
update Mojolicious and added...
|
348 |
=head2 drain |
copy gitweblite soruce code
|
349 | |
upgraded Mojolicious to v3.7...
|
350 |
$content->on(drain => sub { |
351 |
my ($content, $offset) = @_; |
|
copy gitweblite soruce code
|
352 |
... |
353 |
}); |
|
354 | ||
upgraded Mojolicious to v3.7...
|
355 |
Emitted once all data has been written. |
copy gitweblite soruce code
|
356 | |
upgraded Mojolicious to v3.7...
|
357 |
$content->on(drain => sub { |
copy gitweblite soruce code
|
358 |
my $content = shift; |
upgraded Mojolicious to v3.7...
|
359 |
$content->write_chunk(time); |
copy gitweblite soruce code
|
360 |
}); |
361 | ||
update Mojolicious and added...
|
362 |
=head2 read |
copy gitweblite soruce code
|
363 | |
364 |
$content->on(read => sub { |
|
update Mojolicious and added...
|
365 |
my ($content, $bytes) = @_; |
copy gitweblite soruce code
|
366 |
... |
367 |
}); |
|
368 | ||
369 |
Emitted when a new chunk of content arrives. |
|
370 | ||
371 |
$content->unsubscribe('read'); |
|
372 |
$content->on(read => sub { |
|
update Mojolicious and added...
|
373 |
my ($content, $bytes) = @_; |
374 |
say "Streaming: $bytes"; |
|
copy gitweblite soruce code
|
375 |
}); |
376 | ||
377 |
=head1 ATTRIBUTES |
|
378 | ||
379 |
L<Mojo::Content> implements the following attributes. |
|
380 | ||
update Mojolicious and added...
|
381 |
=head2 auto_relax |
copy gitweblite soruce code
|
382 | |
update Mojolicious to 4.57
|
383 |
my $bool = $content->auto_relax; |
384 |
$content = $content->auto_relax($bool); |
|
copy gitweblite soruce code
|
385 | |
upgraded Mojolicious to v3.7...
|
386 |
Try to detect when relaxed parsing is necessary. |
copy gitweblite soruce code
|
387 | |
update Mojolicious and added...
|
388 |
=head2 headers |
copy gitweblite soruce code
|
389 | |
390 |
my $headers = $content->headers; |
|
391 |
$content = $content->headers(Mojo::Headers->new); |
|
392 | ||
393 |
Content headers, defaults to a L<Mojo::Headers> object. |
|
394 | ||
update Mojolicious and added...
|
395 |
=head2 max_buffer_size |
upgraded Mojolicious to v3.7...
|
396 | |
397 |
my $size = $content->max_buffer_size; |
|
398 |
$content = $content->max_buffer_size(1024); |
|
399 | ||
400 |
Maximum size in bytes of buffer for content parser, defaults to the value of |
|
update Mojolicious 4.07
|
401 |
the MOJO_MAX_BUFFER_SIZE environment variable or C<262144>. |
upgraded Mojolicious to v3.7...
|
402 | |
update Mojolicious and added...
|
403 |
=head2 max_leftover_size |
copy gitweblite soruce code
|
404 | |
405 |
my $size = $content->max_leftover_size; |
|
406 |
$content = $content->max_leftover_size(1024); |
|
407 | ||
408 |
Maximum size in bytes of buffer for pipelined HTTP requests, defaults to the |
|
update Mojolicious 4.07
|
409 |
value of the MOJO_MAX_LEFTOVER_SIZE environment variable or C<262144>. |
copy gitweblite soruce code
|
410 | |
update Mojolicious and added...
|
411 |
=head2 relaxed |
copy gitweblite soruce code
|
412 | |
update Mojolicious to 4.57
|
413 |
my $bool = $content->relaxed; |
414 |
$content = $content->relaxed($bool); |
|
copy gitweblite soruce code
|
415 | |
upgraded Mojolicious to v3.7...
|
416 |
Activate relaxed parsing for responses that are terminated with a connection |
417 |
close. |
|
418 | ||
update Mojolicious and added...
|
419 |
=head2 skip_body |
upgraded Mojolicious to v3.7...
|
420 | |
update Mojolicious to 4.57
|
421 |
my $bool = $content->skip_body; |
422 |
$content = $content->skip_body($bool); |
|
upgraded Mojolicious to v3.7...
|
423 | |
424 |
Skip body parsing and finish after headers. |
|
copy gitweblite soruce code
|
425 | |
426 |
=head1 METHODS |
|
427 | ||
428 |
L<Mojo::Content> inherits all methods from L<Mojo::EventEmitter> and |
|
429 |
implements the following new ones. |
|
430 | ||
update Mojolicious and added...
|
431 |
=head2 body_contains |
copy gitweblite soruce code
|
432 | |
update Mojolicious to 4.57
|
433 |
my $bool = $content->body_contains('foo bar baz'); |
copy gitweblite soruce code
|
434 | |
435 |
Check if content contains a specific string. Meant to be overloaded in a |
|
436 |
subclass. |
|
437 | ||
update Mojolicious and added...
|
438 |
=head2 body_size |
copy gitweblite soruce code
|
439 | |
440 |
my $size = $content->body_size; |
|
441 | ||
442 |
Content size in bytes. Meant to be overloaded in a subclass. |
|
443 | ||
update Mojolicious and added...
|
444 |
=head2 boundary |
copy gitweblite soruce code
|
445 | |
446 |
my $boundary = $content->boundary; |
|
447 | ||
448 |
Extract multipart boundary from C<Content-Type> header. |
|
449 | ||
update Mojolicious and added...
|
450 |
=head2 build_body |
copy gitweblite soruce code
|
451 | |
update Mojolicious 4.07
|
452 |
my $str = $content->build_body; |
copy gitweblite soruce code
|
453 | |
454 |
Render whole body. |
|
455 | ||
update Mojolicious and added...
|
456 |
=head2 build_headers |
copy gitweblite soruce code
|
457 | |
update Mojolicious 4.07
|
458 |
my $str = $content->build_headers; |
copy gitweblite soruce code
|
459 | |
460 |
Render all headers. |
|
461 | ||
update Mojolicious and added...
|
462 |
=head2 charset |
copy gitweblite soruce code
|
463 | |
464 |
my $charset = $content->charset; |
|
465 | ||
466 |
Extract charset from C<Content-Type> header. |
|
467 | ||
update Mojolicious and added...
|
468 |
=head2 clone |
copy gitweblite soruce code
|
469 | |
470 |
my $clone = $content->clone; |
|
471 | ||
472 |
Clone content if possible, otherwise return C<undef>. |
|
473 | ||
update Mojolicious and added...
|
474 |
=head2 generate_body_chunk |
copy gitweblite soruce code
|
475 | |
update Mojolicious and added...
|
476 |
my $bytes = $content->generate_body_chunk(0); |
copy gitweblite soruce code
|
477 | |
478 |
Generate dynamic content. |
|
479 | ||
update Mojolicious and added...
|
480 |
=head2 get_body_chunk |
copy gitweblite soruce code
|
481 | |
update Mojolicious and added...
|
482 |
my $bytes = $content->get_body_chunk(0); |
copy gitweblite soruce code
|
483 | |
update Mojolicious 4.07
|
484 |
Get a chunk of content starting from a specific position. Meant to be |
copy gitweblite soruce code
|
485 |
overloaded in a subclass. |
486 | ||
update Mojolicious and added...
|
487 |
=head2 get_header_chunk |
copy gitweblite soruce code
|
488 | |
update Mojolicious and added...
|
489 |
my $bytes = $content->get_header_chunk(13); |
copy gitweblite soruce code
|
490 | |
update Mojolicious 4.07
|
491 |
Get a chunk of the headers starting from a specific position. |
copy gitweblite soruce code
|
492 | |
update Mojolicious and added...
|
493 |
=head2 header_size |
copy gitweblite soruce code
|
494 | |
495 |
my $size = $content->header_size; |
|
496 | ||
497 |
Size of headers in bytes. |
|
498 | ||
update Mojolicious and added...
|
499 |
=head2 is_chunked |
copy gitweblite soruce code
|
500 | |
update Mojolicious to 4.57
|
501 |
my $bool = $content->is_chunked; |
copy gitweblite soruce code
|
502 | |
503 |
Check if content is chunked. |
|
504 | ||
update Mojolicious and added...
|
505 |
=head2 is_compressed |
upgraded Mojolicious to v3.7...
|
506 | |
update Mojolicious to 4.57
|
507 |
my $bool = $content->is_compressed; |
upgraded Mojolicious to v3.7...
|
508 | |
509 |
Check if content is C<gzip> compressed. |
|
510 | ||
update Mojolicious and added...
|
511 |
=head2 is_dynamic |
copy gitweblite soruce code
|
512 | |
update Mojolicious to 4.57
|
513 |
my $bool = $content->is_dynamic; |
copy gitweblite soruce code
|
514 | |
update Mojolicious to 4.57
|
515 |
Check if content will be dynamically generated, which prevents L</"clone"> |
516 |
from working. |
|
copy gitweblite soruce code
|
517 | |
update Mojolicious and added...
|
518 |
=head2 is_finished |
copy gitweblite soruce code
|
519 | |
update Mojolicious to 4.57
|
520 |
my $bool = $content->is_finished; |
copy gitweblite soruce code
|
521 | |
522 |
Check if parser is finished. |
|
523 | ||
update Mojolicious and added...
|
524 |
=head2 is_limit_exceeded |
upgraded Mojolicious to v3.7...
|
525 | |
update Mojolicious to 4.57
|
526 |
my $bool = $content->is_limit_exceeded; |
upgraded Mojolicious to v3.7...
|
527 | |
update Mojolicious to 4.57
|
528 |
Check if buffer has exceeded L</"max_buffer_size">. |
upgraded Mojolicious to v3.7...
|
529 | |
update Mojolicious and added...
|
530 |
=head2 is_multipart |
copy gitweblite soruce code
|
531 | |
532 |
my $false = $content->is_multipart; |
|
533 | ||
534 |
False. |
|
535 | ||
update Mojolicious and added...
|
536 |
=head2 is_parsing_body |
copy gitweblite soruce code
|
537 | |
update Mojolicious to 4.57
|
538 |
my $bool = $content->is_parsing_body; |
copy gitweblite soruce code
|
539 | |
540 |
Check if body parsing started yet. |
|
541 | ||
update Mojolicious and added...
|
542 |
=head2 leftovers |
copy gitweblite soruce code
|
543 | |
544 |
my $bytes = $content->leftovers; |
|
545 | ||
546 |
Get leftover data from content parser. |
|
547 | ||
update Mojolicious and added...
|
548 |
=head2 parse |
copy gitweblite soruce code
|
549 | |
update Mojolicious and added...
|
550 |
$content |
551 |
= $content->parse("Content-Length: 12\x0d\x0a\x0d\x0aHello World!"); |
|
copy gitweblite soruce code
|
552 | |
553 |
Parse content chunk. |
|
554 | ||
update Mojolicious and added...
|
555 |
=head2 parse_body |
copy gitweblite soruce code
|
556 | |
upgraded Mojolicious to v3.7...
|
557 |
$content = $content->parse_body('Hi!'); |
copy gitweblite soruce code
|
558 | |
upgraded Mojolicious to v3.7...
|
559 |
Parse body chunk and skip headers. |
copy gitweblite soruce code
|
560 | |
update Mojolicious and added...
|
561 |
=head2 progress |
copy gitweblite soruce code
|
562 | |
563 |
my $size = $content->progress; |
|
564 | ||
565 |
Size of content already received from message in bytes. |
|
566 | ||
update Mojolicious and added...
|
567 |
=head2 write |
copy gitweblite soruce code
|
568 | |
update Mojolicious and added...
|
569 |
$content = $content->write($bytes); |
570 |
$content = $content->write($bytes => sub {...}); |
|
copy gitweblite soruce code
|
571 | |
572 |
Write dynamic content non-blocking, the optional drain callback will be |
|
573 |
invoked once all data has been written. |
|
574 | ||
update Mojolicious and added...
|
575 |
=head2 write_chunk |
copy gitweblite soruce code
|
576 | |
update Mojolicious and added...
|
577 |
$content = $content->write_chunk($bytes); |
578 |
$content = $content->write_chunk($bytes => sub {...}); |
|
copy gitweblite soruce code
|
579 | |
580 |
Write dynamic content non-blocking with C<chunked> transfer encoding, the |
|
581 |
optional drain callback will be invoked once all data has been written. |
|
582 | ||
583 |
=head1 SEE ALSO |
|
584 | ||
585 |
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>. |
|
586 | ||
587 |
=cut |