1Mojo::Content(3) User Contributed Perl Documentation Mojo::Content(3)
2
3
4
6 Mojo::Content - HTTP 1.1 Content Base Class
7
9 use base 'Mojo::Content';
10
12 Mojo::Content is an abstract base class for HTTP 1.1 content as
13 described in RFC 2616.
14
16 Mojo::Content implements the following attributes.
17
18 "body_cb"
19 my $cb = $content->body_cb;
20
21 $counter = 1;
22 $content = $content->body_cb(sub {
23 my $self = shift;
24 my $chunk = '';
25 $chunk = "hello world!" if $counter == 1;
26 $chunk = "hello world2!\n\n" if $counter == 2;
27 $counter++;
28 return $chunk;
29 });
30
31 Content generator callback.
32
33 "buffer"
34 my $buffer = $content->buffer;
35 $content = $content->buffer(Mojo::ByteStream->new);
36
37 Parser buffer.
38
39 "filter"
40 my $filter = $content->filter;
41 $content = $content->filter(Mojo::Filter::Chunked->new);
42
43 Input filter.
44
45 "filter_buffer"
46 my $filter_buffer = $content->filter_buffer;
47 $content = $content->filter_buffer(Mojo::ByteStream->new);
48
49 Input buffer for filtering.
50
51 "headers"
52 my $headers = $content->headers;
53 $content = $content->headers(Mojo::Headers->new);
54
55 The headers.
56
57 "relaxed"
58 my $relaxed = $content->relaxed;
59 $content = $content->relaxed(1);
60
61 Activate relaxed filtering for HTTP 0.9.
62
63 "raw_header_size"
64 my $size = $content->raw_header_size;
65
66 Raw size of headers in bytes.
67
69 Mojo::Content inherits all methods from Mojo::Base and implements the
70 following new ones.
71
72 "body_contains"
73 my $found = $content->body_contains('foo bar baz');
74
75 Check if content contains a specific string.
76
77 "body_size"
78 my $size = $content->body_size;
79
80 Content size in bytes.
81
82 "build_body"
83 my $string = $content->build_body;
84
85 Render whole body.
86
87 "build_headers"
88 my $string = $content->build_headers;
89
90 Render all headers.
91
92 "generate_body_chunk"
93 my $chunk = $content->generate_body_chunk(0);
94
95 Generate content from "body_cb".
96
97 "get_body_chunk"
98 my $chunk = $content->get_body_chunk(0);
99
100 Get a chunk of content starting from a specfic position.
101
102 "get_header_chunk"
103 my $chunk = $content->get_header_chunk(13);
104
105 Get a chunk of the headers starting from a specfic position.
106
107 "has_leftovers"
108 my $leftovers = $content->has_leftovers;
109
110 Check if there are leftovers in the buffer.
111
112 "header_size"
113 my $size = $content->header_size;
114
115 Size of headers in bytes.
116
117 "is_chunked"
118 my $chunked = $content->is_chunked;
119
120 Chunked transfer encoding.
121
122 "is_done"
123 my $done = $content->is_done;
124
125 Check if parser is done.
126
127 "is_multipart"
128 my $multipart = $content->is_multipart;
129
130 Multipart content.
131
132 "is_parsing_body"
133 my $body = $content->is_parsing_body;
134
135 Check if body parsing started yet.
136
137 "leftovers"
138 my $bytes = $content->leftovers;
139
140 Leftovers for next HTTP message in buffer.
141
142 "parse"
143 $content = $content->parse("Content-Length: 12\r\n\r\nHello World!");
144
145 Parse content.
146
147 "parse_body"
148 $content = $content->parse_body("Hi!");
149
150 Parse body.
151
152 "parse_body_once"
153 $content = $content->parse_body_once("Hi!");
154
155 Parse body once.
156
157 "parse_until_body"
158 $content = $content->parse_until_body(
159 "Content-Length: 12\r\n\r\nHello World!"
160 );
161
162 Parse and stop after headers.
163
164 "raw_body_size"
165 my $size = $content->raw_body_size;
166
167 Raw size of body in bytes.
168
170 Mojolicious, Mojolicious::Guides, <http://mojolicious.org>.
171
172
173
174perl v5.12.3 2010-08-12 Mojo::Content(3)