| 247 | } |
| 248 | |
| 249 | static int http_connect(URLContext *h, const char *path, const char *hoststr, |
| 250 | const char *auth, int *new_location) |
| 251 | { |
| 252 | HTTPContext *s = h->priv_data; |
| 253 | int post, err; |
| 254 | char line[1024]; |
| 255 | char *authstr = NULL; |
| 256 | int64_t off = s->off; |
| 257 | |
| 258 | |
| 259 | /* send http header */ |
| 260 | post = h->flags & URL_WRONLY; |
| 261 | authstr = ff_http_auth_create_response(&s->auth_state, auth, path, |
| 262 | post ? "POST" : "GET"); |
| 263 | snprintf(s->buffer, sizeof(s->buffer), |
| 264 | "%s %s HTTP/1.1\r\n" |
| 265 | "User-Agent: %s\r\n" |
| 266 | "Accept: */*\r\n" |
| 267 | "Range: bytes=%"PRId64"-\r\n" |
| 268 | "Host: %s\r\n" |
| 269 | "%s" |
| 270 | "Connection: close\r\n" |
| 271 | "%s" |
| 272 | "\r\n", |
| 273 | post ? "POST" : "GET", |
| 274 | path, |
| 275 | LIBAVFORMAT_IDENT, |
| 276 | s->off, |
| 277 | hoststr, |
| 278 | authstr ? authstr : "", |
| 279 | post ? "Transfer-Encoding: chunked\r\n" : ""); |
| 280 | |
| 281 | av_freep(&authstr); |
| 282 | if (http_write(h, s->buffer, strlen(s->buffer)) < 0) |
| 283 | return AVERROR(EIO); |
| 284 | |
| 285 | /* init input buffer */ |
| 286 | s->buf_ptr = s->buffer; |
| 287 | s->buf_end = s->buffer; |
| 288 | s->line_count = 0; |
| 289 | s->off = 0; |
| 290 | s->filesize = -1; |
| 291 | if (post) { |
| 292 | /* always use chunked encoding for upload data */ |
| 293 | s->chunksize = 0; |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | /* wait for header */ |
| 298 | for(;;) { |
| 299 | if (http_get_line(s, line, sizeof(line)) < 0) |
| 300 | return AVERROR(EIO); |
| 301 | |
| 302 | dprintf(NULL, "header='%s'\n", line); |
| 303 | |
| 304 | err = process_line(h, line, s->line_count, new_location); |
| 305 | if (err < 0) |
| 306 | return err; |
no test coverage detected