|
@@ -139,6 +139,7 @@ static void http_rx_response ( struct http_request *http, char *response ) {
|
139
|
139
|
static int http_rx_content_length ( struct http_request *http,
|
140
|
140
|
const char *value ) {
|
141
|
141
|
char *endp;
|
|
142
|
+ int rc;
|
142
|
143
|
|
143
|
144
|
http->content_length = strtoul ( value, &endp, 10 );
|
144
|
145
|
if ( *endp != '\0' ) {
|
|
@@ -147,6 +148,15 @@ static int http_rx_content_length ( struct http_request *http,
|
147
|
148
|
return -EIO;
|
148
|
149
|
}
|
149
|
150
|
|
|
151
|
+ /* Try to presize the receive buffer */
|
|
152
|
+ if ( ( rc = expand_buffer ( http->buffer,
|
|
153
|
+ http->content_length ) ) != 0 ) {
|
|
154
|
+ /* May as well abandon the download now; it will fail */
|
|
155
|
+ DBGC ( http, "HTTP %p could not presize buffer: %s\n",
|
|
156
|
+ http, strerror ( rc ) );
|
|
157
|
+ return rc;
|
|
158
|
+ }
|
|
159
|
+
|
150
|
160
|
return 0;
|
151
|
161
|
}
|
152
|
162
|
|
|
@@ -162,6 +172,8 @@ struct http_header_handler {
|
162
|
172
|
* @v http HTTP request
|
163
|
173
|
* @v value HTTP header value
|
164
|
174
|
* @ret rc Return status code
|
|
175
|
+ *
|
|
176
|
+ * If an error is returned, the download will be aborted.
|
165
|
177
|
*/
|
166
|
178
|
int ( * rx ) ( struct http_request *http, const char *value );
|
167
|
179
|
};
|