From a4e3dcc5159d07966a27cef3c3607ecd63660a8c Mon Sep 17 00:00:00 2001 From: Gabor Adam Toth Date: Fri, 29 Apr 2011 03:15:36 +0200 Subject: [PATCH] render: no \n after routing headers if content is empty --- src/packet.c | 11 ++++++++--- src/render.c | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/packet.c b/src/packet.c index 3676c2c..8455636 100644 --- a/src/packet.c +++ b/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; } diff --git a/src/render.c b/src/render.c index eb76494..e7b5793 100644 --- a/src/render.c +++ b/src/render.c @@ -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++)