Fix headers closing
This commit is contained in:
parent
2af6556748
commit
85f427ad91
|
@ -86,7 +86,7 @@ aisl_client_parse(AislClient client, char *data, int32_t size)
|
|||
case HTTP_PARSER_READY:
|
||||
client->flags &= ~FLAG_CAN_READ;
|
||||
client->flags |= FLAG_CAN_WRITE;
|
||||
|
||||
client->stream->content_length = AISL_AUTO_LENGTH;
|
||||
aisl_raise(client->server->instance, (void *)s, AISL_EVENT_STREAM_REQUEST,
|
||||
result);
|
||||
break;
|
||||
|
|
21
src/stream.c
21
src/stream.c
|
@ -289,7 +289,7 @@ aisl_stream_close_headers(AislStream stream)
|
|||
return AISL_MALLOC_ERROR;
|
||||
|
||||
if (!(stream->flags & FLAG_SERVER_HEADER_SENT)) {
|
||||
l = buffer_append( &stream->buffer, "Server: AISL\r\n", 14);
|
||||
l = buffer_append(&stream->buffer, "Server: AISL\r\n", 14);
|
||||
if (l == -1)
|
||||
return AISL_MALLOC_ERROR;
|
||||
|
||||
|
@ -298,7 +298,7 @@ aisl_stream_close_headers(AislStream stream)
|
|||
|
||||
if (!(stream->flags & FLAG_CONTENT_TYPE_HEADER_SENT)) {
|
||||
l = buffer_append(&stream->buffer,
|
||||
"Content-type: text/html; encoding=utf-8\r\n", 41);
|
||||
"Content-Type: text/html; encoding=utf-8\r\n", 41);
|
||||
|
||||
if (l == -1)
|
||||
return AISL_MALLOC_ERROR;
|
||||
|
@ -307,8 +307,8 @@ aisl_stream_close_headers(AislStream stream)
|
|||
}
|
||||
|
||||
if (!(stream->flags & FLAG_CONTENT_LENGTH_HEADER_SENT)) {
|
||||
if (stream->content_length == AISL_AUTO_LENGTH) {
|
||||
l = buffer_append_printf(&stream->buffer, "Content-length: %"PRIu64"\r\n",
|
||||
if (stream->content_length != AISL_AUTO_LENGTH) {
|
||||
l = buffer_append_printf(&stream->buffer, "Content-Length: %"PRIu64"\r\n",
|
||||
stream->content_length);
|
||||
|
||||
if (l == -1)
|
||||
|
@ -360,8 +360,6 @@ aisl_response(AislStream stream, AislHttpResponse rs_code, uint64_t c_len)
|
|||
if (l == -1)
|
||||
return AISL_MALLOC_ERROR;
|
||||
|
||||
stream->head_offset = l;
|
||||
stream->body_offset = l;
|
||||
stream->state = AISL_STREAM_STATE_SEND_HEADER;
|
||||
|
||||
return AISL_SUCCESS;
|
||||
|
@ -374,15 +372,18 @@ aisl_flush(AislStream s)
|
|||
{
|
||||
if (!(s->flags & FLAG_CONTENT_LENGTH_HEADER_SENT)) {
|
||||
char hdr[ 40 ];
|
||||
uint64_t c_len = s->buffer.used - s->body_offset;
|
||||
uint64_t c_len;
|
||||
int32_t l;
|
||||
|
||||
l = snprintf(hdr, sizeof (hdr), "Content-length: %"PRIu64"\r\n", c_len);
|
||||
if (s->body_offset) {
|
||||
c_len = s->buffer.used - s->body_offset;
|
||||
l = snprintf(hdr, sizeof (hdr), "Content-Length: %"PRIu64"\r\n", c_len);
|
||||
l = buffer_insert(&s->buffer, s->body_offset - 2, hdr, l);
|
||||
|
||||
if (l == -1)
|
||||
return AISL_MALLOC_ERROR;
|
||||
|
||||
} else {
|
||||
aisl_stream_close_headers(s);
|
||||
}
|
||||
s->flags |= FLAG_CONTENT_LENGTH_HEADER_SENT;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue