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