From 973a24516f2c8ac18a5ad1d1cc2ffdc7fd09d289 Mon Sep 17 00:00:00 2001 From: Riza Sulistyo Date: Tue, 24 Jan 2017 05:59:05 +0000 Subject: Re #1945 (misc): Prevent automatically adding Content-Type and Content-Length on printing multipart data when its already printed. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5545 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/src/pjsip/sip_multipart.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pjsip/src/pjsip/sip_multipart.c b/pjsip/src/pjsip/sip_multipart.c index 9c7aea64..b6a50d0b 100644 --- a/pjsip/src/pjsip/sip_multipart.c +++ b/pjsip/src/pjsip/sip_multipart.c @@ -67,6 +67,7 @@ static int multipart_print_body(struct pjsip_msg_body *msg_body, enum { CLEN_SPACE = 5 }; char *clen_pos; const pjsip_hdr *hdr; + pj_bool_t ctype_printed = PJ_FALSE; clen_pos = NULL; @@ -82,19 +83,24 @@ static int multipart_print_body(struct pjsip_msg_body *msg_body, hdr = part->hdr.next; while (hdr != &part->hdr) { int printed = pjsip_hdr_print_on((pjsip_hdr*)hdr, p, - SIZE_LEFT()-2); + SIZE_LEFT()-2); if (printed < 0) return -1; p += printed; *p++ = '\r'; *p++ = '\n'; + + if (!ctype_printed && hdr->type == PJSIP_H_CONTENT_TYPE) + ctype_printed = PJ_TRUE; + hdr = hdr->next; } /* Automaticly adds Content-Type and Content-Length headers, only - * if content_type is set in the message body. + * if content_type is set in the message body and haven't been printed. */ - if (part->body && part->body->content_type.type.slen) { + if (part->body && part->body->content_type.type.slen && !ctype_printed) + { pj_str_t ctype_hdr = { "Content-Type: ", 14}; const pjsip_media_type *media = &part->body->content_type; -- cgit v1.2.3