Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
053c00fd
Commit
053c00fd
authored
Dec 09, 2015
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HTTP file reader tests
parent
914343cd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
253 additions
and
2 deletions
+253
-2
modules/access/http/Makefile.am
modules/access/http/Makefile.am
+6
-2
modules/access/http/file_test.c
modules/access/http/file_test.c
+247
-0
No files found.
modules/access/http/Makefile.am
View file @
053c00fd
...
...
@@ -12,6 +12,10 @@ h2output_test_SOURCES = access/http/h2output_test.c \
h2output_test_LDADD
=
$(LIBPTHREAD)
http_msg_test_SOURCES
=
access/http/message_test.c
\
access/http/message.c access/http/message.h
http_file_test_SOURCES
=
access/http/file_test.c
\
access/http/message.c access/http/message.h
\
access/http/file.c access/http/file.h
check_PROGRAMS
+=
hpack_test hpackenc_test h2frame_test h2output_test
\
http_msg_test
TESTS
+=
hpack_test hpackenc_test h2frame_test h2output_test http_msg_test
http_msg_test http_file_test
TESTS
+=
hpack_test hpackenc_test h2frame_test h2output_test
\
http_msg_test http_file_test
modules/access/http/file_test.c
0 → 100644
View file @
053c00fd
/*****************************************************************************
* message.c: HTTP request/response
*****************************************************************************
* Copyright (C) 2015 Rémi Denis-Courmont
*
* This program 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.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#undef NDEBUG
#include <assert.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <vlc_common.h>
#include "file.h"
#include "message.h"
static
const
char
url
[]
=
"https://www.example.com:8443/dir/file.ext?a=b"
;
static
const
char
ua
[]
=
PACKAGE_NAME
"/"
PACKAGE_VERSION
" (test suite)"
;
static
const
char
*
replies
[
2
]
=
{
NULL
,
NULL
};
static
uint64_t
offset
=
0
;
int
main
(
void
)
{
struct
vlc_http_file
*
f
;
char
*
str
;
/* Request failure test */
f
=
vlc_http_file_create
(
NULL
,
url
,
ua
,
NULL
);
assert
(
f
!=
NULL
);
vlc_http_file_seek
(
f
,
0
);
assert
(
vlc_http_file_get_status
(
f
)
<
0
);
assert
(
vlc_http_file_get_redirect
(
f
)
==
NULL
);
assert
(
vlc_http_file_get_size
(
f
)
==
UINT64_MAX
);
assert
(
!
vlc_http_file_can_seek
(
f
));
assert
(
vlc_http_file_get_type
(
f
)
==
NULL
);
assert
(
vlc_http_file_read
(
f
)
==
NULL
);
vlc_http_file_destroy
(
f
);
/* Non-seekable stream test */
replies
[
0
]
=
"HTTP/1.1 200 OK
\r\n
"
"ETag:
\"
foobar42
\"\r\n
"
"Content-Type: video/mpeg
\r\n
"
"
\r\n
"
;
offset
=
0
;
f
=
vlc_http_file_create
(
NULL
,
url
,
ua
,
NULL
);
assert
(
f
!=
NULL
);
assert
(
vlc_http_file_get_status
(
f
)
==
200
);
assert
(
!
vlc_http_file_can_seek
(
f
));
assert
(
vlc_http_file_get_size
(
f
)
==
UINT64_MAX
);
str
=
vlc_http_file_get_type
(
f
);
assert
(
str
!=
NULL
&&
!
strcmp
(
str
,
"video/mpeg"
));
free
(
str
);
/* Seek failure */
replies
[
0
]
=
"HTTP/1.1 200 OK
\r\n
ETag:
\"
foobar42
\"\r\n\r\n
"
;
assert
(
vlc_http_file_seek
(
f
,
offset
=
1234
)
<
0
);
vlc_http_file_destroy
(
f
);
/* Seekable file test */
replies
[
0
]
=
"HTTP/1.1 206 Partial Content
\r\n
"
"Content-Range: bytes 0-2344/2345
\r\n
"
"ETag: W/
\"
foobar42
\"\r\n
"
"
\r\n
"
;
offset
=
0
;
f
=
vlc_http_file_create
(
NULL
,
url
,
ua
,
NULL
);
assert
(
f
!=
NULL
);
assert
(
vlc_http_file_can_seek
(
f
));
assert
(
vlc_http_file_get_size
(
f
)
==
2345
);
/* Seek success */
replies
[
0
]
=
"HTTP/1.1 206 Partial Content
\r\n
"
"Content-Range: bytes 1234-3455/3456
\r\n
"
"ETag: W/
\"
foobar42
\"\r\n
"
"
\r\n
"
;
assert
(
vlc_http_file_seek
(
f
,
offset
=
1234
)
==
0
);
assert
(
vlc_http_file_can_seek
(
f
));
assert
(
vlc_http_file_get_size
(
f
)
==
3456
);
/* Seek too far */
replies
[
0
]
=
"HTTP/1.1 416 Range Not Satisfiable
\r\n
"
"Content-Range: bytes */4567
\r\n
"
"ETag: W/
\"
foobar42
\"\r\n
"
"
\r\n
"
;
vlc_http_file_seek
(
f
,
offset
=
5678
);
assert
(
vlc_http_file_can_seek
(
f
));
assert
(
vlc_http_file_get_size
(
f
)
==
4567
);
assert
(
vlc_http_file_read
(
f
)
==
NULL
);
vlc_http_file_destroy
(
f
);
/* Redirect */
replies
[
0
]
=
"HTTP/1.1 301 Permanent Redirect
\r\n
"
"Location: /somewhere/else/#here
\r\n
"
"
\r\n
"
;
offset
=
0
;
f
=
vlc_http_file_create
(
NULL
,
url
,
ua
,
NULL
);
assert
(
f
!=
NULL
);
assert
(
!
vlc_http_file_can_seek
(
f
));
assert
(
vlc_http_file_get_size
(
f
)
==
UINT64_MAX
);
str
=
vlc_http_file_get_redirect
(
f
);
assert
(
str
!=
NULL
&&
!
strcmp
(
str
,
"https://www.example.com:8443/somewhere/else/"
));
free
(
str
);
vlc_http_file_destroy
(
f
);
/* Continuation */
replies
[
0
]
=
"HTTP/1.1 100 Standby
\r\n
"
"
\r\n
"
;
replies
[
1
]
=
"HTTP/1.1 200 OK
\r\n
"
"Content-Length: 9999
\r\n
"
"
\r\n
"
;
offset
=
0
;
f
=
vlc_http_file_create
(
NULL
,
url
,
ua
,
NULL
);
assert
(
f
!=
NULL
);
assert
(
vlc_http_file_get_size
(
f
)
==
9999
);
assert
(
vlc_http_file_get_redirect
(
f
)
==
NULL
);
vlc_http_file_destroy
(
f
);
/* Dummy API calls */
f
=
vlc_http_file_create
(
NULL
,
"ftp://localhost/foo"
,
NULL
,
NULL
);
assert
(
f
==
NULL
);
return
0
;
}
/* Callback for vlc_http_msg_h2_frame */
#include "h2frame.h"
struct
vlc_h2_frame
*
vlc_h2_frame_headers
(
uint_fast32_t
id
,
uint_fast32_t
mtu
,
bool
eos
,
unsigned
count
,
const
char
*
const
tab
[][
2
])
{
(
void
)
id
;
(
void
)
mtu
;
(
void
)
count
,
(
void
)
tab
;
assert
(
!
eos
);
return
NULL
;
}
/* Callback for the HTTP request */
#include "connmgr.h"
static
struct
vlc_http_stream
stream
;
static
struct
vlc_http_msg
*
stream_read_headers
(
struct
vlc_http_stream
*
s
)
{
assert
(
s
==
&
stream
);
/* return next reply */
struct
vlc_http_msg
*
m
=
NULL
;
const
char
*
answer
=
replies
[
0
];
if
(
answer
!=
NULL
)
{
m
=
vlc_http_msg_headers
(
answer
);
assert
(
m
!=
NULL
);
vlc_http_msg_attach
(
m
,
s
);
}
memmove
(
replies
,
replies
+
1
,
sizeof
(
replies
)
-
sizeof
(
replies
[
0
]));
replies
[(
sizeof
(
replies
)
/
sizeof
(
replies
[
0
]))
-
1
]
=
NULL
;
return
m
;
}
static
struct
block_t
*
stream_read
(
struct
vlc_http_stream
*
s
)
{
assert
(
s
==
&
stream
);
return
NULL
;
}
static
void
stream_close
(
struct
vlc_http_stream
*
s
)
{
assert
(
s
==
&
stream
);
}
static
const
struct
vlc_http_stream_cbs
stream_callbacks
=
{
stream_read_headers
,
stream_read
,
stream_close
,
};
static
struct
vlc_http_stream
stream
=
{
&
stream_callbacks
};
struct
vlc_http_msg
*
vlc_https_request
(
struct
vlc_http_mgr
*
mgr
,
const
char
*
host
,
unsigned
port
,
const
struct
vlc_http_msg
*
req
)
{
const
char
*
str
;
char
*
end
;
assert
(
mgr
==
NULL
);
assert
(
!
strcmp
(
host
,
"www.example.com"
));
assert
(
port
==
8443
);
str
=
vlc_http_msg_get_method
(
req
);
assert
(
!
strcmp
(
str
,
"GET"
));
str
=
vlc_http_msg_get_scheme
(
req
);
assert
(
!
strcmp
(
str
,
"https"
));
str
=
vlc_http_msg_get_authority
(
req
);
assert
(
!
strcmp
(
str
,
"www.example.com:8443"
));
str
=
vlc_http_msg_get_path
(
req
);
assert
(
!
strcmp
(
str
,
"/dir/file.ext?a=b"
));
str
=
vlc_http_msg_get_agent
(
req
);
assert
(
!
strcmp
(
str
,
ua
));
str
=
vlc_http_msg_get_header
(
req
,
"Referer"
);
assert
(
str
==
NULL
);
str
=
vlc_http_msg_get_header
(
req
,
"Accept"
);
assert
(
str
==
NULL
||
strstr
(
str
,
"*/*"
)
!=
NULL
);
str
=
vlc_http_msg_get_header
(
req
,
"Accept-Language"
);
assert
(
str
==
NULL
||
strstr
(
str
,
"*"
)
!=
NULL
);
str
=
vlc_http_msg_get_header
(
req
,
"Range"
);
assert
(
str
!=
NULL
&&
!
strncmp
(
str
,
"bytes="
,
6
)
&&
strtoul
(
str
+
6
,
&
end
,
10
)
==
offset
&&
*
end
==
'-'
);
str
=
vlc_http_msg_get_header
(
req
,
"If-Match"
);
if
(
offset
!=
0
)
assert
(
str
!=
NULL
&&
!
strcmp
(
str
,
"
\"
foobar42
\"
"
));
else
assert
(
str
==
NULL
||
strcmp
(
str
,
"*"
)
||
strcmp
(
str
,
"
\"
foobar42
\"
"
));
return
vlc_http_stream_read_headers
(
&
stream
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment