1
0
Fork 0
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:
tg(x) 2011-04-29 03:15:36 +02:00
parent 8037bf35fa
commit 35e33b7a2d
2 changed files with 10 additions and 4 deletions

View file

@ -146,9 +146,14 @@ inline size_t psyc_setPacketLength(psycPacket *p)
p->contentLength += p->data.length + 1; // data\n p->contentLength += p->data.length + 1; // data\n
// set total length: routing-header \n content |\n // set total length: routing-header \n content |\n
p->length = p->routingLength + 1 + p->contentLength + sizeof(PSYC_PACKET_DELIMITER) - 2; p->length = p->routingLength + p->contentLength + sizeof(PSYC_PACKET_DELIMITER) - 2;
if (p->flag == PSYC_PACKET_NEED_LENGTH) // add length of length if needed if (p->contentLength > 0)
p->length += log10((double)p->data.length) + 1; {
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; return p->length;
} }

View file

@ -76,7 +76,8 @@ psycRenderRC psyc_render(psycPacket *packet, char *buffer, size_t buflen)
cur += itoa(packet->contentLength, buffer + cur, 10); 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 // render entity modifiers
for (i = 0; i < packet->entity.lines; i++) for (i = 0; i < packet->entity.lines; i++)