Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFmpeg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libremedia
Tethys
FFmpeg
Commits
10da1e91
Commit
10da1e91
authored
13 years ago
by
Martin Storsjö
Browse files
Options
Downloads
Patches
Plain Diff
http: Make custom headers settable via an AVOption
Signed-off-by:
Martin Storsjö
<
martin@martin.st
>
parent
eaa8c1f9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libavformat/http.c
+14
-7
14 additions, 7 deletions
libavformat/http.c
with
14 additions
and
7 deletions
libavformat/http.c
+
14
−
7
View file @
10da1e91
...
@@ -47,13 +47,14 @@ typedef struct {
...
@@ -47,13 +47,14 @@ typedef struct {
int64_t
off
,
filesize
;
int64_t
off
,
filesize
;
char
location
[
MAX_URL_SIZE
];
char
location
[
MAX_URL_SIZE
];
HTTPAuthState
auth_state
;
HTTPAuthState
auth_state
;
unsigned
char
headers
[
BUFFER_SIZE
]
;
char
*
headers
;
int
willclose
;
/**< Set if the server correctly handles Connection: close and will close the connection after feeding us the content. */
int
willclose
;
/**< Set if the server correctly handles Connection: close and will close the connection after feeding us the content. */
}
HTTPContext
;
}
HTTPContext
;
#define OFFSET(x) offsetof(HTTPContext, x)
#define OFFSET(x) offsetof(HTTPContext, x)
static
const
AVOption
options
[]
=
{
static
const
AVOption
options
[]
=
{
{
"chunksize"
,
"use chunked transfer-encoding for posts, -1 disables it, 0 enables it"
,
OFFSET
(
chunksize
),
AV_OPT_TYPE_INT64
,
{.
dbl
=
0
},
-
1
,
0
},
/* Default to 0, for chunked POSTs */
{
"chunksize"
,
"use chunked transfer-encoding for posts, -1 disables it, 0 enables it"
,
OFFSET
(
chunksize
),
AV_OPT_TYPE_INT64
,
{.
dbl
=
0
},
-
1
,
0
},
/* Default to 0, for chunked POSTs */
{
"headers"
,
"custom HTTP headers, can override built in default headers"
,
OFFSET
(
headers
),
AV_OPT_TYPE_STRING
},
{
NULL
}
{
NULL
}
};
};
static
const
AVClass
httpcontext_class
=
{
static
const
AVClass
httpcontext_class
=
{
...
@@ -69,12 +70,9 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
...
@@ -69,12 +70,9 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
void
ff_http_set_headers
(
URLContext
*
h
,
const
char
*
headers
)
void
ff_http_set_headers
(
URLContext
*
h
,
const
char
*
headers
)
{
{
HTTPContext
*
s
=
h
->
priv_data
;
HTTPContext
*
s
=
h
->
priv_data
;
int
len
=
strlen
(
headers
);
if
(
len
&&
strcmp
(
"
\r\n
"
,
headers
+
len
-
2
))
av_freep
(
&
s
->
headers
);
av_log
(
h
,
AV_LOG_ERROR
,
"No trailing CRLF found in HTTP header.
\n
"
);
s
->
headers
=
av_strdup
(
headers
);
av_strlcpy
(
s
->
headers
,
headers
,
sizeof
(
s
->
headers
));
}
}
void
ff_http_init_auth_state
(
URLContext
*
dest
,
const
URLContext
*
src
)
void
ff_http_init_auth_state
(
URLContext
*
dest
,
const
URLContext
*
src
)
...
@@ -168,6 +166,12 @@ static int http_open(URLContext *h, const char *uri, int flags)
...
@@ -168,6 +166,12 @@ static int http_open(URLContext *h, const char *uri, int flags)
s
->
filesize
=
-
1
;
s
->
filesize
=
-
1
;
av_strlcpy
(
s
->
location
,
uri
,
sizeof
(
s
->
location
));
av_strlcpy
(
s
->
location
,
uri
,
sizeof
(
s
->
location
));
if
(
s
->
headers
)
{
int
len
=
strlen
(
s
->
headers
);
if
(
len
<
2
||
strcmp
(
"
\r\n
"
,
s
->
headers
+
len
-
2
))
av_log
(
h
,
AV_LOG_ERROR
,
"No trailing CRLF found in HTTP header.
\n
"
);
}
return
http_open_cnx
(
h
);
return
http_open_cnx
(
h
);
}
}
static
int
http_getc
(
HTTPContext
*
s
)
static
int
http_getc
(
HTTPContext
*
s
)
...
@@ -285,6 +289,8 @@ static int process_line(URLContext *h, char *line, int line_count,
...
@@ -285,6 +289,8 @@ static int process_line(URLContext *h, char *line, int line_count,
static
inline
int
has_header
(
const
char
*
str
,
const
char
*
header
)
static
inline
int
has_header
(
const
char
*
str
,
const
char
*
header
)
{
{
/* header + 2 to skip over CRLF prefix. (make sure you have one!) */
/* header + 2 to skip over CRLF prefix. (make sure you have one!) */
if
(
!
str
)
return
0
;
return
av_stristart
(
str
,
header
+
2
,
NULL
)
||
av_stristr
(
str
,
header
);
return
av_stristart
(
str
,
header
+
2
,
NULL
)
||
av_stristr
(
str
,
header
);
}
}
...
@@ -323,7 +329,8 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
...
@@ -323,7 +329,8 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
"Host: %s
\r\n
"
,
hoststr
);
"Host: %s
\r\n
"
,
hoststr
);
/* now add in custom headers */
/* now add in custom headers */
av_strlcpy
(
headers
+
len
,
s
->
headers
,
sizeof
(
headers
)
-
len
);
if
(
s
->
headers
)
av_strlcpy
(
headers
+
len
,
s
->
headers
,
sizeof
(
headers
)
-
len
);
snprintf
(
s
->
buffer
,
sizeof
(
s
->
buffer
),
snprintf
(
s
->
buffer
,
sizeof
(
s
->
buffer
),
"%s %s HTTP/1.1
\r\n
"
"%s %s HTTP/1.1
\r\n
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment