Mercurial > libavformat.hg
comparison http.c @ 6352:3472338a5e13 libavformat
http: Return EOF at the end of the content even if the connection isn't closed
We do request Connection: close, but some servers ignore it.
author | mstorsjo |
---|---|
date | Mon, 09 Aug 2010 08:14:48 +0000 |
parents | 89adb1f9ff50 |
children | 27242bd0812c |
comparison
equal
deleted
inserted
replaced
6351:05a6d7c6813e | 6352:3472338a5e13 |
---|---|
47 int64_t chunksize; /**< Used if "Transfer-Encoding: chunked" otherwise -1. */ | 47 int64_t chunksize; /**< Used if "Transfer-Encoding: chunked" otherwise -1. */ |
48 int64_t off, filesize; | 48 int64_t off, filesize; |
49 char location[URL_SIZE]; | 49 char location[URL_SIZE]; |
50 HTTPAuthState auth_state; | 50 HTTPAuthState auth_state; |
51 unsigned char headers[BUFFER_SIZE]; | 51 unsigned char headers[BUFFER_SIZE]; |
52 int willclose; /**< Set if the server correctly handles Connection: close and will close the connection after feeding us the content. */ | |
52 } HTTPContext; | 53 } HTTPContext; |
53 | 54 |
54 #define OFFSET(x) offsetof(HTTPContext, x) | 55 #define OFFSET(x) offsetof(HTTPContext, x) |
55 static const AVOption options[] = { | 56 static const AVOption options[] = { |
56 {"chunksize", "use chunked transfer-encoding for posts, -1 disables it, 0 enables it", OFFSET(chunksize), FF_OPT_TYPE_INT64, 0, -1, 0 }, /* Default to 0, for chunked POSTs */ | 57 {"chunksize", "use chunked transfer-encoding for posts, -1 disables it, 0 enables it", OFFSET(chunksize), FF_OPT_TYPE_INT64, 0, -1, 0 }, /* Default to 0, for chunked POSTs */ |
265 s->chunksize = 0; | 266 s->chunksize = 0; |
266 } else if (!strcmp (tag, "WWW-Authenticate")) { | 267 } else if (!strcmp (tag, "WWW-Authenticate")) { |
267 ff_http_auth_handle_header(&s->auth_state, tag, p); | 268 ff_http_auth_handle_header(&s->auth_state, tag, p); |
268 } else if (!strcmp (tag, "Authentication-Info")) { | 269 } else if (!strcmp (tag, "Authentication-Info")) { |
269 ff_http_auth_handle_header(&s->auth_state, tag, p); | 270 ff_http_auth_handle_header(&s->auth_state, tag, p); |
271 } else if (!strcmp (tag, "Connection")) { | |
272 if (!strcmp(p, "close")) | |
273 s->willclose = 1; | |
270 } | 274 } |
271 } | 275 } |
272 return 1; | 276 return 1; |
273 } | 277 } |
274 | 278 |
335 s->buf_ptr = s->buffer; | 339 s->buf_ptr = s->buffer; |
336 s->buf_end = s->buffer; | 340 s->buf_end = s->buffer; |
337 s->line_count = 0; | 341 s->line_count = 0; |
338 s->off = 0; | 342 s->off = 0; |
339 s->filesize = -1; | 343 s->filesize = -1; |
344 s->willclose = 0; | |
340 if (post) { | 345 if (post) { |
341 /* Pretend that it did work. We didn't read any header yet, since | 346 /* Pretend that it did work. We didn't read any header yet, since |
342 * we've still to send the POST data, but the code calling this | 347 * we've still to send the POST data, but the code calling this |
343 * function will check http_code after we return. */ | 348 * function will check http_code after we return. */ |
344 s->http_code = 200; | 349 s->http_code = 200; |
397 if (len > size) | 402 if (len > size) |
398 len = size; | 403 len = size; |
399 memcpy(buf, s->buf_ptr, len); | 404 memcpy(buf, s->buf_ptr, len); |
400 s->buf_ptr += len; | 405 s->buf_ptr += len; |
401 } else { | 406 } else { |
407 if (!s->willclose && s->filesize >= 0 && s->off >= s->filesize) | |
408 return AVERROR_EOF; | |
402 len = url_read(s->hd, buf, size); | 409 len = url_read(s->hd, buf, size); |
403 } | 410 } |
404 if (len > 0) { | 411 if (len > 0) { |
405 s->off += len; | 412 s->off += len; |
406 if (s->chunksize > 0) | 413 if (s->chunksize > 0) |