11package com .sendgrid ;
22
33import org .apache .http .Header ;
4+ import org .apache .http .annotation .NotThreadSafe ;
45import org .apache .http .client .ResponseHandler ;
56import org .apache .http .client .methods .CloseableHttpResponse ;
7+ import org .apache .http .client .methods .HttpEntityEnclosingRequestBase ;
68import org .apache .http .client .methods .HttpDelete ;
79import org .apache .http .client .methods .HttpGet ;
810import org .apache .http .client .methods .HttpPatch ;
3335import java .util .Map ;
3436import java .util .Scanner ;
3537
38+ // Hack to get DELETE to accept a request body
39+ @ NotThreadSafe
40+ class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase {
41+ public static final String METHOD_NAME = "DELETE" ;
42+
43+ public String getMethod () {
44+ return METHOD_NAME ;
45+ }
46+
47+ public HttpDeleteWithBody (final String uri ) {
48+ super ();
49+ setURI (URI .create (uri ));
50+ }
51+ }
52+
3653/**
3754 * Class Client allows for quick and easy access any REST or REST-like API.
3855 */
@@ -286,11 +303,11 @@ public Response delete(Request request) throws URISyntaxException, IOException {
286303 CloseableHttpResponse serverResponse = null ;
287304 Response response = new Response ();
288305 URI uri = null ;
289- HttpDelete httpDelete = null ;
306+ HttpDeleteWithBody httpDelete = null ;
290307
291308 try {
292309 uri = buildUri (request .baseUri , request .endpoint , request .queryParams );
293- httpDelete = new HttpDelete (uri .toString ());
310+ httpDelete = new HttpDeleteWithBody (uri .toString ());
294311 } catch (URISyntaxException ex ) {
295312 throw ex ;
296313 }
@@ -301,6 +318,12 @@ public Response delete(Request request) throws URISyntaxException, IOException {
301318 }
302319 }
303320
321+ try {
322+ httpDelete .setEntity (new StringEntity (request .body ));
323+ } catch (IOException ex ) {
324+ throw ex ;
325+ }
326+
304327 try {
305328 serverResponse = httpClient .execute (httpDelete );
306329 response = getResponse (serverResponse );
0 commit comments