Example usage for org.apache.commons.httpclient.methods DeleteMethod removeRequestHeader

List of usage examples for org.apache.commons.httpclient.methods DeleteMethod removeRequestHeader

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods DeleteMethod removeRequestHeader.

Prototype

@Override
public void removeRequestHeader(String headerName) 

Source Link

Document

Remove the request header associated with the given name.

Usage

From source file:ar.com.zauber.commons.web.proxy.HttpClientRequestProxy.java

/**
 * @param request/*from ww w.  j a va 2s.  co  m*/
 * @return
 */
private HttpMethod buildRequest(final HttpServletRequest request, final URLResult urlResult) {
    final String method = request.getMethod().toUpperCase();
    final HttpMethod ret;

    final String uri = urlResult.getURL().toExternalForm();
    if ("GET".equals(method)) {
        ret = new GetMethod(uri);
        proxyHeaders(request, ret);
    } else if ("POST".equals(method) || "PUT".equals(method)) {
        final EntityEnclosingMethod pm = "POST".equals(method) ? new PostMethod(uri) : new PutMethod(uri);
        proxyHeaders(request, pm);
        try {
            pm.setRequestEntity(new InputStreamRequestEntity(request.getInputStream()));
        } catch (IOException e) {
            throw new UnhandledException("No pudo abrirse el InputStream" + "del request.", e);
        }
        ret = pm;

    } else if ("DELETE".equals(method)) {
        /*
        rfc2616
        The Content-Length field of a request or response is added or deleted
        according to the rules in section 4.4. A transparent proxy MUST
        preserve the entity-length (section 7.2.2) of the entity-body,
        although it MAY change the transfer-length (section 4.4).
        */
        final DeleteMethod dm = new DeleteMethod(uri);
        proxyHeaders(request, dm);
        //No body => No Header
        dm.removeRequestHeader("Content-Length");
        ret = dm;
    } else {
        throw new NotImplementedException("i accept patches :)");
    }

    if (request.getQueryString() != null) {
        ret.setQueryString(request.getQueryString());
    }

    return ret;
}