mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
render: no \n after routing headers if content is empty
This commit is contained in:
parent
8037bf35fa
commit
35e33b7a2d
2 changed files with 10 additions and 4 deletions
11
src/packet.c
11
src/packet.c
|
@ -146,9 +146,14 @@ inline size_t psyc_setPacketLength(psycPacket *p)
|
|||
p->contentLength += p->data.length + 1; // data\n
|
||||
|
||||
// set total length: routing-header \n content |\n
|
||||
p->length = p->routingLength + 1 + p->contentLength + sizeof(PSYC_PACKET_DELIMITER) - 2;
|
||||
if (p->flag == PSYC_PACKET_NEED_LENGTH) // add length of length if needed
|
||||
p->length += log10((double)p->data.length) + 1;
|
||||
p->length = p->routingLength + p->contentLength + sizeof(PSYC_PACKET_DELIMITER) - 2;
|
||||
if (p->contentLength > 0)
|
||||
{
|
||||
p->contentLength--; // subtract the \n from the delimiter, as that doesn't belong to the content part
|
||||
p->length++; // add \n at the start of the content part
|
||||
if (p->flag == PSYC_PACKET_NEED_LENGTH) // add length of length if needed
|
||||
p->length += log10((double)p->data.length) + 1;
|
||||
}
|
||||
|
||||
return p->length;
|
||||
}
|
||||
|
|
|
@ -76,7 +76,8 @@ psycRenderRC psyc_render(psycPacket *packet, char *buffer, size_t buflen)
|
|||
cur += itoa(packet->contentLength, buffer + cur, 10);
|
||||
}
|
||||
|
||||
buffer[cur++] = '\n'; // start of content part
|
||||
if (packet->entity.lines || packet->method.length || packet->data.length)
|
||||
buffer[cur++] = '\n'; // start of content part if there's content
|
||||
|
||||
// render entity modifiers
|
||||
for (i = 0; i < packet->entity.lines; i++)
|
||||
|
|
Loading…
Reference in a new issue