Skip to content

Commit 1654c22

Browse files
committed
Merge branch 'pr/422'
2 parents 1332b89 + e7d1935 commit 1654c22

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

changelog.org

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ List of user-visible changes that have gone into each release
1919
context
2020
- Merged https://github.com/dakrone/clj-http/pull/424 to add :mime-subtype request parameter to
2121
override mime subtype
22+
- create-multipart-entity with three arguments arity lets the selection of =HttpMultipartMode=
23+
- new request key :http-multipart-mode which is HttpMultipartMode/STRICT by default
2224

2325
** 3.8.0
2426
- Reintroduce the =:save-request= and =:debug-body= options

src/clj_http/core.clj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
HttpAsyncClients
4040
CloseableHttpAsyncClient)
4141
(org.apache.http.message BasicHttpResponse)
42-
(java.util.concurrent ExecutionException)))
42+
(java.util.concurrent ExecutionException)
43+
(org.apache.http.entity.mime HttpMultipartMode)))
4344

4445
(defn parse-headers
4546
"Takes a HeaderIterator and returns a map of names to values.
@@ -376,9 +377,9 @@
376377
([req] (request req nil nil))
377378
([{:keys [body conn-timeout conn-request-timeout connection-manager
378379
cookie-store cookie-policy headers multipart mime-subtype
379-
query-string redirect-strategy max-redirects retry-handler
380-
request-method scheme server-name server-port socket-timeout
381-
uri response-interceptor proxy-host proxy-port async?
380+
http-multipart-mode query-string redirect-strategy max-redirects
381+
retry-handler request-method scheme server-name server-port
382+
socket-timeout uri response-interceptor proxy-host proxy-port async?
382383
http-client-context http-request-config
383384
proxy-ignore-hosts proxy-user proxy-pass digest-auth ntlm-auth]
384385
:as req} respond raise]
@@ -423,7 +424,7 @@
423424
(.setCredentials authscope creds)))))
424425
(if multipart
425426
(.setEntity ^HttpEntityEnclosingRequest http-req
426-
(mp/create-multipart-entity multipart mime-subtype))
427+
(mp/create-multipart-entity multipart mime-subtype http-multipart-mode))
427428
(when (and body (instance? HttpEntityEnclosingRequest http-req))
428429
(if (instance? HttpEntity body)
429430
(.setEntity ^HttpEntityEnclosingRequest http-req body)

src/clj_http/multipart.clj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,17 @@
126126
content)
127127

128128
(defn create-multipart-entity
129-
"Takes a multipart vector of maps and creates a MultipartEntity with each
130-
map added as a part, depending on the type of content."
131-
[multipart mime-subtype]
129+
"Takes a multipart vector of maps and creates a MultipartEntity with each map
130+
added as a part, depending on the type of content. If a mime-subtype or
131+
multipart-mode are specified, they are set on the multipart builder, otherwise
132+
'form-data' and strict mode are used."
133+
[multipart mime-subtype multipart-mode]
132134
(let [mp-entity (doto (MultipartEntityBuilder/create)
133-
(.setStrictMode)
134135
(.setCharset (encoding-to-charset "UTF-8"))
135136
(.setMimeSubtype (or mime-subtype "form-data")))]
137+
(if multipart-mode
138+
(.setMode mp-entity multipart-mode)
139+
(.setStrictMode mp-entity))
136140
(doseq [m multipart]
137141
(let [name (or (:part-name m) (:name m))
138142
part (make-multipart-body m)]

0 commit comments

Comments
 (0)