curl-library
[PATCH] merge user-defined content-type with content-type built by formdata.c
Date: Mon, 24 Jul 2006 11:44:53 +0200
Hello,
Here is a patch of http.c for curl 7.15.4, which make it possible to
specify a Content-Type header for the HTTP message,
when using the -form options.
The new code extracts the "boundary" parameter generated by formdata.c,
and addst to the user-defined header.
This make it possible for instance to send simple "multipart/related"
messages.
I am using this to send SOAP With Attachment messages, to run unitary
tests of a web service.
I hope you will like the patch, and insert it in the code base: please
tell me if there is something wrong.
Best regards,
Yves Lejeune.
===========================================================================================================
--- http.c-7.15.4 Sat May 6 00:14:40 2006
+++ http.c-result-patch Mon Jul 24 11:17:38 2006
@@ -1556,6 +1556,10 @@
header as that will produce *two* in the same request! */
curl_strnequal("Host:", headers->data, 5))
;
+ else if(conn->data->set.httpreq == HTTPREQ_POST_FORM &&
+ /* this header is sent later, after it is merged with the one
generated by formdata.c */
+ curl_strnequal("Content-Type:", headers->data,
strlen("Content-Type:")))
+ ;
else {
result = add_bufferf(req_buffer, "%s\r\n", headers->data);
@@ -2134,12 +2138,9 @@
if(result)
return result;
- if(!checkheaders(data, "Content-Type:")) {
- /* Get Content-Type: line from Curl_formpostheader.
+ {
- The Content-Type header line also contains the MIME boundary
- string etc why disabling this header is likely to not make
things
- work, but we support disabling it anyway.
+ /* Get Content-Type: line from Curl_formpostheader.
*/
char *contentType;
size_t linelength=0;
@@ -2149,9 +2150,35 @@
failf(data, "Could not get Content-Type header line!");
return CURLE_HTTP_POST_ERROR;
}
- result = add_buffer(req_buffer, contentType, linelength);
- if(result)
- return result;
+
+ ptr = checkheaders(data, "Content-Type:");
+ if(ptr) {
+
+ /* Add the MIME boundary string generated by formdata.c to the
custom Content-Type.
+ This make it possible for instance to build a simple
multiple/related,
+ to post a SOAP With Attachments message to a web service.
+ */
+
+ char *boundary;
+ char *endboundary;
+
+ boundary = strstr(contentType, "boundary=");
+ /* not sure strpbrk() is portable enough */
+ for (endboundary = boundary; *endboundary; ++endboundary) {
+ if (isspace(*endboundary) || *endboundary == ',') break;
+ }
+ *endboundary = 0; /* the rest won't be needed any more */
+
+ result = add_bufferf(req_buffer, "%s%c %s\r\n", ptr,
strchr(ptr, ';') ? ',' : ';', bounda
ry);
+ if(result)
+ return result;
+
+ }
+ else {
+ result = add_buffer(req_buffer, contentType, linelength);
+ if(result)
+ return result;
+ }
}
/* make the request end in a true CRLF */
===========================================================================================================
Received on 2006-07-24