Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
mongoose
Commits
6cfc6964
Commit
6cfc6964
authored
Nov 21, 2015
by
Sergey Lyubka
Committed by
rojer
Nov 24, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add helper function mg_send_head()
PUBLISHED_FROM=5c9d11d21d34fa72974a021f0342068d87159634
parent
a93b3a06
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
mongoose.c
mongoose.c
+11
-0
mongoose.h
mongoose.h
+18
-2
No files found.
mongoose.c
View file @
6cfc6964
...
...
@@ -4503,6 +4503,17 @@ void mg_send_response_line(struct mg_connection *nc, int status_code,
}
}
void
mg_send_head
(
struct
mg_connection
*
c
,
int
status_code
,
int64_t
content_length
,
const
char
*
extra_headers
)
{
mg_send_response_line
(
c
,
status_code
,
extra_headers
);
if
(
content_length
<
0
)
{
mg_printf
(
c
,
"%s"
,
"Transfer-Encoding: chunked
\r\n
"
);
}
else
{
mg_printf
(
c
,
"Content-Length: %"
INT64_FMT
"
\r\n
"
,
content_length
);
}
mg_send
(
c
,
"
\r\n
"
,
2
);
}
static
void
send_http_error
(
struct
mg_connection
*
nc
,
int
code
,
const
char
*
reason
)
{
if
(
reason
==
NULL
)
{
...
...
mongoose.h
View file @
6cfc6964
...
...
@@ -1534,7 +1534,7 @@ void mg_printf_http_chunk(struct mg_connection *, const char *, ...);
/*
* Send response status line.
* If `extra_headers` is not NULL, then `extra_headers` are also sent
* after the reponse line
, followed by a
new line.
* after the reponse line
. `extra_headers` must NOT end end with
new line.
* Example:
*
* mg_send_response_line(nc, 200, "Access-Control-Allow-Origin: *");
...
...
@@ -1544,9 +1544,25 @@ void mg_printf_http_chunk(struct mg_connection *, const char *, ...);
* HTTP/1.1 200 OK\r\n
* Access-Control-Allow-Origin: *\r\n
*/
void
mg_send_response_line
(
struct
mg_connection
*
n
c
,
int
status_code
,
void
mg_send_response_line
(
struct
mg_connection
*
c
,
int
status_code
,
const
char
*
extra_headers
);
/*
* Send response line and headers.
* This function sends response line with the `status_code`, and automatically
* sends one header: either "Content-Length", or "Transfer-Encoding".
* If `content_length` is negative, then "Transfer-Encoding: chunked" header
* is sent, otherwise, "Content-Length" header is sent.
*
* NOTE: If `Transfer-Encoding` is `chunked`, then message body must be sent
* using `mg_send_http_chunk()` or `mg_printf_http_chunk()` functions.
* Otherwise, `mg_send()` or `mg_printf()` must be used.
* Extra headers could be set through `extra_headers` - and note `extra_headers`
* must NOT be terminated by a new line.
*/
void
mg_send_head
(
struct
mg_connection
*
n
,
int
status_code
,
int64_t
content_length
,
const
char
*
extra_headers
);
/*
* Send printf-formatted HTTP chunk, escaping HTML tags.
*/
...
...
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