• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_MIME_OPTIONS
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_HTTPPOST (3)
9  - CURLOPT_MIMEPOST (3)
10---
11
12# NAME
13
14CURLOPT_MIME_OPTIONS - set MIME option flags
15
16# SYNOPSIS
17
18~~~c
19#include <curl/curl.h>
20
21CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MIME_OPTIONS, long options);
22~~~
23
24# DESCRIPTION
25
26Pass a long that holds a bitmask of CURLMIMEOPT_* defines. Each bit is a
27Boolean flag used while encoding a MIME tree or multipart form data.
28
29Available bits are:
30
31## CURLMIMEOPT_FORMESCAPE
32
33Tells libcurl to escape multipart form field and file names using the
34backslash-escaping algorithm rather than percent-encoding (HTTP only).
35
36Backslash-escaping consists in preceding backslashes and double quotes with
37a backslash. Percent encoding maps all occurrences of double quote,
38carriage return and line feed to %22, %0D and %0A respectively.
39
40Before version 7.81.0, percent-encoding was never applied.
41
42HTTP browsers used to do backslash-escaping in the past but have over time
43transitioned to use percent-encoding. This option allows one to address
44server-side applications that have not yet have been converted.
45
46As an example, consider field or filename *strangename"kind*. When the
47containing multipart form is sent, this is normally transmitted as
48*strangename%22kind*. When this option is set, it is sent as
49*strangename"kind*.
50
51# DEFAULT
52
530, meaning disabled.
54
55# PROTOCOLS
56
57HTTP, IMAP, SMTP
58
59# EXAMPLE
60
61~~~c
62int main(void)
63{
64  CURL *curl = curl_easy_init();
65  curl_mime *form = NULL;
66
67  if(curl) {
68    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
69    curl_easy_setopt(curl, CURLOPT_MIME_OPTIONS, CURLMIMEOPT_FORMESCAPE);
70
71    form = curl_mime_init(curl);
72    if(form) {
73      curl_mimepart *part = curl_mime_addpart(form);
74
75      if(part) {
76        curl_mime_filedata(part, "strange\\file\\name");
77        curl_mime_name(part, "strange\"field\"name");
78        curl_easy_setopt(curl, CURLOPT_MIMEPOST, form);
79
80        /* Perform the request */
81        curl_easy_perform(curl);
82      }
83    }
84
85    curl_easy_cleanup(curl);
86    curl_mime_free(form);
87  }
88}
89~~~
90
91# AVAILABILITY
92
93Option added in 7.81.0.
94
95# RETURN VALUE
96
97Returns CURLE_OK
98