Commit 5d603f1b authored by Samuel Pitoiset's avatar Samuel Pitoiset Committed by Martin Storsjö

http: Factorize the code by adding http_read_header()

This function is used for reading http reply headers.
Signed-off-by: 's avatarMartin Storsjö <martin@martin.st>
parent 4f04f5cc
...@@ -324,13 +324,35 @@ static inline int has_header(const char *str, const char *header) ...@@ -324,13 +324,35 @@ static inline int has_header(const char *str, const char *header)
return av_stristart(str, header + 2, NULL) || av_stristr(str, header); return av_stristart(str, header + 2, NULL) || av_stristr(str, header);
} }
static int http_read_header(URLContext *h, int *new_location)
{
HTTPContext *s = h->priv_data;
char line[1024];
int err = 0;
for (;;) {
if (http_get_line(s, line, sizeof(line)) < 0)
return AVERROR(EIO);
av_dlog(NULL, "header='%s'\n", line);
err = process_line(h, line, s->line_count, new_location);
if (err < 0)
return err;
if (err == 0)
break;
s->line_count++;
}
return err;
}
static int http_connect(URLContext *h, const char *path, const char *local_path, static int http_connect(URLContext *h, const char *path, const char *local_path,
const char *hoststr, const char *auth, const char *hoststr, const char *auth,
const char *proxyauth, int *new_location) const char *proxyauth, int *new_location)
{ {
HTTPContext *s = h->priv_data; HTTPContext *s = h->priv_data;
int post, err; int post, err;
char line[1024];
char headers[1024] = ""; char headers[1024] = "";
char *authstr = NULL, *proxyauthstr = NULL; char *authstr = NULL, *proxyauthstr = NULL;
int64_t off = s->off; int64_t off = s->off;
...@@ -403,19 +425,9 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, ...@@ -403,19 +425,9 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
s->chunksize = -1; s->chunksize = -1;
/* wait for header */ /* wait for header */
for(;;) { err = http_read_header(h, new_location);
if (http_get_line(s, line, sizeof(line)) < 0) if (err < 0)
return AVERROR(EIO); return err;
av_dlog(NULL, "header='%s'\n", line);
err = process_line(h, line, s->line_count, new_location);
if (err < 0)
return err;
if (err == 0)
break;
s->line_count++;
}
return (off == s->off) ? 0 : -1; return (off == s->off) ? 0 : -1;
} }
...@@ -603,10 +615,11 @@ static int http_proxy_open(URLContext *h, const char *uri, int flags) ...@@ -603,10 +615,11 @@ static int http_proxy_open(URLContext *h, const char *uri, int flags)
HTTPContext *s = h->priv_data; HTTPContext *s = h->priv_data;
char hostname[1024], hoststr[1024]; char hostname[1024], hoststr[1024];
char auth[1024], pathbuf[1024], *path; char auth[1024], pathbuf[1024], *path;
char line[1024], lower_url[100]; char lower_url[100];
int port, ret = 0, attempts = 0; int port, ret = 0, attempts = 0;
HTTPAuthType cur_auth_type; HTTPAuthType cur_auth_type;
char *authstr; char *authstr;
int new_loc;
h->is_streamed = 1; h->is_streamed = 1;
...@@ -647,30 +660,19 @@ redo: ...@@ -647,30 +660,19 @@ redo:
s->filesize = -1; s->filesize = -1;
cur_auth_type = s->proxy_auth_state.auth_type; cur_auth_type = s->proxy_auth_state.auth_type;
for (;;) { /* Note: This uses buffering, potentially reading more than the
int new_loc; * HTTP header. If tunneling a protocol where the server starts
// Note: This uses buffering, potentially reading more than the * the conversation, we might buffer part of that here, too.
// HTTP header. If tunneling a protocol where the server starts * Reading that requires using the proper ffurl_read() function
// the conversation, we might buffer part of that here, too. * on this URLContext, not using the fd directly (as the tls
// Reading that requires using the proper ffurl_read() function * protocol does). This shouldn't be an issue for tls though,
// on this URLContext, not using the fd directly (as the tls * since the client starts the conversation there, so there
// protocol does). This shouldn't be an issue for tls though, * is no extra data that we might buffer up here.
// since the client starts the conversation there, so there */
// is no extra data that we might buffer up here. ret = http_read_header(h, &new_loc);
if (http_get_line(s, line, sizeof(line)) < 0) { if (ret < 0)
ret = AVERROR(EIO); goto fail;
goto fail;
}
av_dlog(h, "header='%s'\n", line);
ret = process_line(h, line, s->line_count, &new_loc);
if (ret < 0)
goto fail;
if (ret == 0)
break;
s->line_count++;
}
attempts++; attempts++;
if (s->http_code == 407 && if (s->http_code == 407 &&
(cur_auth_type == HTTP_AUTH_NONE || s->proxy_auth_state.stale) && (cur_auth_type == HTTP_AUTH_NONE || s->proxy_auth_state.stale) &&
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment