Skip to content

Commit

Permalink
Adds HttpDeleteWithEntity
Browse files Browse the repository at this point in the history
Some REST APIs accept entity bodies for DELETE requests. This allows
the DELETE to have a body.
  • Loading branch information
David Abdemoulaie committed Oct 7, 2015
1 parent 4380dc6 commit 123c087
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
27 changes: 27 additions & 0 deletions ext/manticore/org/manticore/HttpDeleteWithEntity.java
@@ -0,0 +1,27 @@
package org.manticore;

import java.net.URI;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;

public class HttpDeleteWithEntity extends HttpEntityEnclosingRequestBase {
public final static String METHOD_NAME = "DELETE";

public HttpDeleteWithEntity() {
super();
}

public HttpDeleteWithEntity(URI url) {
super();
setURI(url);
}

public HttpDeleteWithEntity(String url) {
super();
setURI(URI.create(url));
}

@Override
public String getMethod() {
return METHOD_NAME;
}
}
Binary file modified lib/jar/manticore-ext.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions lib/manticore/client.rb
Expand Up @@ -87,6 +87,7 @@ class Client
java_import "org.apache.http.HttpHost"
java_import "javax.net.ssl.SSLContext"
java_import "org.manticore.HttpGetWithEntity"
java_import "org.manticore.HttpDeleteWithEntity"
java_import "org.apache.http.auth.UsernamePasswordCredentials"

include ProxiesInterface
Expand Down Expand Up @@ -249,7 +250,7 @@ def post(url, options = {}, &block)
# @macro http_method_shared_sync
def delete(url, options = {}, &block)
options = treat_params_as_query(options)
request HttpDelete, url, options, &block
request HttpDeleteWithEntity, url, options, &block
end

# Perform a HTTP OPTIONS request
Expand Down Expand Up @@ -423,7 +424,7 @@ def request_from_options(klass, url, options)
req = klass.new uri_from_url_and_options(url, options).to_s

if ( options[:params] || options[:body] || options[:entity]) &&
( req.instance_of?(HttpPost) || req.instance_of?(HttpPatch) || req.instance_of?(HttpPut) || req.instance_of?(HttpGetWithEntity))
( req.instance_of?(HttpPost) || req.instance_of?(HttpPatch) || req.instance_of?(HttpPut) || req.instance_of?(HttpGetWithEntity) || req.instance_of?(HttpDeleteWithEntity))
if options[:params]
pairs = struct_to_name_value_pairs(options[:params])
encoding = minimum_encoding_for options[:params].to_s
Expand Down
12 changes: 12 additions & 0 deletions spec/manticore/client_spec.rb
Expand Up @@ -462,6 +462,18 @@
end
end

describe "#delete" do
it "works" do
response = client.delete(local_server)
expect(JSON.load(response.body)["method"]).to eq "DELETE"
end

it "sends a body" do
response = client.delete(local_server, body: "This is a delete body")
expect(JSON.load(response.body)["body"]).to eq "This is a delete body"
end
end

describe "#head" do
it "works" do
response = client.head(local_server)
Expand Down

0 comments on commit 123c087

Please sign in to comment.