File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,14 @@ impl<R: AsyncRead> Body<R> {
31
31
}
32
32
}
33
33
34
+ /// Create a new instance from a reader with a known size.
35
+ pub fn new_with_size ( reader : R , size : usize ) -> Self {
36
+ Self {
37
+ reader,
38
+ length : Some ( size) ,
39
+ }
40
+ }
41
+
34
42
/// Create a new empty body.
35
43
pub fn empty ( reader : R ) -> Self {
36
44
Self {
Original file line number Diff line number Diff line change @@ -126,9 +126,20 @@ where
126
126
let body = match httparse_res
127
127
. headers
128
128
. iter ( )
129
- . find ( |h| h. name == "Content-Length" )
129
+ . find ( |h| h. name . eq_ignore_ascii_case ( "Content-Length" ) )
130
130
{
131
- Some ( _header) => Body :: new ( reader) , // TODO: use the header value
131
+ Some ( content_length) => {
132
+ let length = std:: str:: from_utf8 ( content_length. value )
133
+ . ok ( )
134
+ . map ( |s| s. parse :: < usize > ( ) . ok ( ) )
135
+ . flatten ( ) ;
136
+
137
+ if let Some ( len) = length {
138
+ Body :: new_with_size ( reader, len)
139
+ } else {
140
+ return Err ( "Invalid value for Content-Length" . into ( ) ) ;
141
+ }
142
+ }
132
143
None => Body :: empty ( reader) ,
133
144
} ;
134
145
Original file line number Diff line number Diff line change @@ -210,9 +210,20 @@ where
210
210
let body = match httparse_req
211
211
. headers
212
212
. iter ( )
213
- . find ( |h| h. name == "Content-Length" )
213
+ . find ( |h| h. name . eq_ignore_ascii_case ( "Content-Length" ) )
214
214
{
215
- Some ( _header) => Body :: new ( reader) , // TODO: use the header value
215
+ Some ( content_length) => {
216
+ let length = std:: str:: from_utf8 ( content_length. value )
217
+ . ok ( )
218
+ . map ( |s| s. parse :: < usize > ( ) . ok ( ) )
219
+ . flatten ( ) ;
220
+
221
+ if let Some ( len) = length {
222
+ Body :: new_with_size ( reader, len)
223
+ } else {
224
+ return Err ( "Invalid value for Content-Length" . into ( ) ) ;
225
+ }
226
+ }
216
227
None => Body :: empty ( reader) ,
217
228
} ;
218
229
You can’t perform that action at this time.
0 commit comments