Example usage for org.apache.http.client.methods HttpPutHC4 addHeader

List of usage examples for org.apache.http.client.methods HttpPutHC4 addHeader

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpPutHC4 addHeader.

Prototype

public void addHeader(String str, String str2) 

Source Link

Usage

From source file:at.bitfire.davdroid.webdav.WebDavResource.java

public String put(byte[] data, PutMode mode) throws URISyntaxException, IOException, HttpException {
    HttpPutHC4 put = new HttpPutHC4(location);
    put.setEntity(new ByteArrayEntityHC4(data));

    switch (mode) {
    case ADD_DONT_OVERWRITE:
        put.addHeader("If-None-Match", "*");
        break;//from w  w  w.j  av  a2  s .  c om
    case UPDATE_DONT_OVERWRITE:
        put.addHeader("If-Match", (properties.eTag != null) ? properties.eTag : "*");
        break;
    }

    if (properties.contentType != null)
        put.addHeader("Content-Type", properties.contentType.toString());

    @Cleanup
    CloseableHttpResponse response = httpClient.execute(put, context);
    checkResponse(response);

    Header eTag = response.getLastHeader("ETag");
    if (eTag != null)
        return eTag.getValue();

    return null;
}

From source file:com.granita.icloudcalsync.webdav.WebDavResource.java

public String put(byte[] data, PutMode mode) throws URISyntaxException, IOException, HttpException {
    HttpPutHC4 put = new HttpPutHC4(location);
    put.setEntity(new ByteArrayEntityHC4(data));

    switch (mode) {
    case ADD_DONT_OVERWRITE:
        put.addHeader("If-None-Match", "*");
        break;//w w  w  .j a v  a  2  s.c o m
    case UPDATE_DONT_OVERWRITE:
        put.addHeader("If-Match", (getETag() != null) ? getETag() : "*");
        break;
    }

    if (getContentType() != null)
        put.addHeader("Content-Type", getContentType());

    @Cleanup
    CloseableHttpResponse response = httpClient.execute(put, context);
    checkResponse(response);

    Header eTag = response.getLastHeader("ETag");
    if (eTag != null)
        return eTag.getValue();

    return null;
}