Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
ddde5d9d
Commit
ddde5d9d
authored
May 21, 2010
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
range support for PUT request by Yan Jabin
parent
f65d3ca6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
6 deletions
+17
-6
mongoose.c
mongoose.c
+17
-6
No files found.
mongoose.c
View file @
ddde5d9d
...
...
@@ -2690,6 +2690,12 @@ send_opened_file_stream(struct mg_connection *conn, FILE *fp, int64_t len)
}
}
static
int
parse_range_header
(
const
char
*
header
,
int64_t
*
a
,
int64_t
*
b
)
{
return
sscanf
(
header
,
"bytes=%"
INT64_FMT
"u-%"
INT64_FMT
"u"
,
a
,
b
);
}
/*
* Send regular file contents.
*/
...
...
@@ -2719,8 +2725,7 @@ send_file(struct mg_connection *conn, const char *path, struct mgstat *stp)
/* If Range: header specified, act accordingly */
r1
=
r2
=
0
;
hdr
=
mg_get_header
(
conn
,
"Range"
);
if
(
hdr
!=
NULL
&&
(
n
=
sscanf
(
hdr
,
"bytes=%"
INT64_FMT
"-%"
INT64_FMT
,
&
r1
,
&
r2
))
>
0
)
{
if
(
hdr
!=
NULL
&&
(
n
=
parse_range_header
(
hdr
,
&
r1
,
&
r2
))
>
0
)
{
conn
->
request_info
.
status_code
=
206
;
(
void
)
fseeko
(
fp
,
(
off_t
)
r1
,
SEEK_SET
);
cl
=
n
==
2
?
r2
-
r1
+
1
:
cl
-
r1
;
...
...
@@ -3304,15 +3309,14 @@ static void
put_file
(
struct
mg_connection
*
conn
,
const
char
*
path
)
{
struct
mgstat
st
;
const
char
*
range
;
int64_t
r1
,
r2
;
FILE
*
fp
;
int
rc
;
conn
->
request_info
.
status_code
=
mg_stat
(
path
,
&
st
)
==
0
?
200
:
201
;
if
(
mg_get_header
(
conn
,
"Range"
))
{
send_error
(
conn
,
501
,
"Not Implemented"
,
"%s"
,
"Range support for PUT requests is not implemented"
);
}
else
if
((
rc
=
put_dir
(
path
))
==
0
)
{
if
((
rc
=
put_dir
(
path
))
==
0
)
{
(
void
)
mg_printf
(
conn
,
"HTTP/1.1 %d OK
\r\n\r\n
"
,
conn
->
request_info
.
status_code
);
}
else
if
(
rc
==
-
1
)
{
...
...
@@ -3323,6 +3327,13 @@ put_file(struct mg_connection *conn, const char *path)
"fopen(%s): %s"
,
path
,
strerror
(
ERRNO
));
}
else
{
set_close_on_exec
(
fileno
(
fp
));
range
=
mg_get_header
(
conn
,
"Content-Range"
);
r1
=
r2
=
0
;
if
(
range
!=
NULL
&&
parse_range_header
(
range
,
&
r1
,
&
r2
)
>
0
)
{
conn
->
request_info
.
status_code
=
206
;
/* TODO(lsm): handle seek error */
(
void
)
fseeko
(
fp
,
(
off_t
)
r1
,
SEEK_SET
);
}
if
(
handle_request_body
(
conn
,
fp
))
(
void
)
mg_printf
(
conn
,
"HTTP/1.1 %d OK
\r\n\r\n
"
,
conn
->
request_info
.
status_code
);
...
...
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