Commit 9bbf4c83 authored by Sergey Lyubka's avatar Sergey Lyubka

Fixed problem with mg_printf_data()

parent c39a7125
......@@ -2256,19 +2256,26 @@ void mg_printf_data(struct mg_connection *c, const char *fmt, ...) {
struct connection *conn = MG_CONN_2_CONN(c);
struct iobuf *io = &conn->ns_conn->send_iobuf;
va_list ap;
static const char chunk_len[] = " \r\n";
int len, n, cl = sizeof(chunk_len) - 1;
char *p, buf[9];
int len, n;
char *p;
terminate_headers(c);
// Write the placeholder for the chunk size
p = io->buf + io->len;
iobuf_append(io, " \r\n", 10);
// Write chunk itself
va_start(ap, fmt);
ns_send(conn->ns_conn, chunk_len, cl);
p = io->buf + io->len - cl;
len = ns_vprintf(conn->ns_conn, fmt, ap);
n = mg_snprintf(buf, sizeof(buf), "%X", len);
memcpy(p, buf, n < 9 ? n : 8);
va_end(ap);
// Record size
n = mg_snprintf(p, 7, "%X", len);
p[n] = ' ';
// Write terminating new line
mg_write(c, "\r\n", 2);
}
#if !defined(MONGOOSE_NO_WEBSOCKET) || !defined(MONGOOSE_NO_AUTH)
......
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