On 5 June 2010 01:28, Josh Allmann <[email protected]> wrote: > On 4 June 2010 02:39, Martin Storsjö <[email protected]> wrote: >> On Fri, 4 Jun 2010, Josh Allmann wrote: > > I am starting another thread that should address the issue of the > subsequent HTTP writes not updating the header. >
Until the other thread on the dictionary gets resolved, this patch should make everything dandy. The only thing that's missing now is the ability to extract the x-server-ip from the response... but other than that, everything is good to go. > Josh >
From 004f4a60761fd7dc3d299525b7f337550f0cc5cd Mon Sep 17 00:00:00 2001 From: Josh Allmann <[email protected]> Date: Thu, 3 Jun 2010 13:55:02 -0700 Subject: [PATCH 2/6] Added in capability to write custom HTTP headers. --- libavformat/http.c | 33 +++++++++++++++++++++++++-------- libavformat/http.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 libavformat/http.h diff --git a/libavformat/http.c b/libavformat/http.c index 3d79869..796f422 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -25,6 +25,7 @@ #include <strings.h> #include "internal.h" #include "network.h" +#include "http.h" #include "os_support.h" #include "httpauth.h" @@ -46,12 +47,20 @@ typedef struct { char location[URL_SIZE]; HTTPAuthState auth_state; int init; + int custom_headers; + unsigned char headers[BUFFER_SIZE]; } HTTPContext; static int http_connect(URLContext *h, const char *path, const char *hoststr, const char *auth, int *new_location); static int http_write(URLContext *h, const uint8_t *buf, int size); +void ff_http_set_headers(URLContext *h, const char *headers) +{ + HTTPContext *s = h->priv_data; + s->custom_headers = 1; + snprintf(s->headers, sizeof(s->headers), "%s", headers); +} /* return non zero if error */ static int http_open_cnx(URLContext *h) @@ -137,6 +146,7 @@ static int http_open(URLContext *h, const char *uri, int flags) s->chunksize = -1; s->off = 0; s->init = 0; + s->custom_headers = 0; memset(&s->auth_state, 0, sizeof(s->auth_state)); av_strlcpy(s->location, uri, URL_SIZE); @@ -259,23 +269,30 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr, post = h->flags & URL_WRONLY; authstr = ff_http_auth_create_response(&s->auth_state, auth, path, post ? "POST" : "GET"); - snprintf(s->buffer, sizeof(s->buffer), - "%s %s HTTP/1.1\r\n" - "User-Agent: %s\r\n" + if (!s->custom_headers) { + snprintf(s->headers, sizeof(s->headers), "Accept: */*\r\n" "Range: bytes=%"PRId64"-\r\n" "Host: %s\r\n" - "%s" "Connection: close\r\n" + "\r\n", + s->off, + hoststr); + } + + snprintf(s->buffer, sizeof(s->buffer), + "%s %s HTTP/1.1\r\n" + "User-Agent: %s\r\n" + "%s" + "%s" "%s" "\r\n", post ? "POST" : "GET", path, LIBAVFORMAT_IDENT, - s->off, - hoststr, - authstr ? authstr : "", - post ? "Transfer-Encoding: chunked\r\n" : ""); + post ? "Transfer-Encoding: chunked\r\n" : "", + s->headers, + authstr ? authstr : ""); av_freep(&authstr); if (http_write(h, s->buffer, strlen(s->buffer)) < 0) diff --git a/libavformat/http.h b/libavformat/http.h new file mode 100644 index 0000000..56c6680 --- /dev/null +++ b/libavformat/http.h @@ -0,0 +1,48 @@ +/* + * HTTP definitions + * Copyright (c) 2010 Josh Allmann + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef AVFORMAT_HTTP_H +#define AVFORMAT_HTTP_H + +/** + * Sets custom HTTP headers. Note this overwrites all default options. + * + * The following headers will always be set, no matter what: + * -HTTP verb, path, HTTP version + * -User-Agent + * -Transfer-Encoding (if applicable) + * - Authorization (if applicable) + * + * The following headers are set by default, and will be overwritten if + * custom headers are set. Be sure to re-specify them if needed. + * -Accept + * -Range + * -Host + * -Connection + * + * If seeking is needed with custom headers, Range will need + * to be manually specified before each request. + * + * @param h URL context for this HTTP connection + * @param is_chunked 0 to disable chunking, nonzero otherwise. + */ +void ff_http_set_headers(URLContext *h, const char *headers); + +#endif /* AVFORMAT_HTTP_H */ -- 1.7.0.4
_______________________________________________ FFmpeg-soc mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc
