{
final DefaultHttpClient client = new DefaultHttpClient();
Sardine sardine = new SardineImpl(client);
// mod_dav supports Range headers for PUT
final String url = "http://sudo.ch/dav/anon/sardine/" + UUID.randomUUID().toString();
client.addResponseInterceptor(new HttpResponseInterceptor()
{
public void process(final HttpResponse r, final HttpContext context) throws HttpException, IOException
{
assertEquals(201, r.getStatusLine().getStatusCode());
client.removeResponseInterceptorByClass(this.getClass());
}
});
sardine.put(url, new ByteArrayInputStream("Te".getBytes("UTF-8")));
try
{
// Append to existing file
final Map<String, String> header = Collections.singletonMap(HttpHeaders.CONTENT_RANGE,
"bytes " + 2 + "-" + 3 + "/" + 4);
client.addRequestInterceptor(new HttpRequestInterceptor()
{
public void process(final HttpRequest r, final HttpContext context) throws HttpException, IOException
{
assertNotNull(r.getHeaders(HttpHeaders.CONTENT_RANGE));
assertEquals(1, r.getHeaders(HttpHeaders.CONTENT_RANGE).length);
client.removeRequestInterceptorByClass(this.getClass());
}
});
client.addResponseInterceptor(new HttpResponseInterceptor()
{
public void process(final HttpResponse r, final HttpContext context) throws HttpException, IOException
{
assertEquals(204, r.getStatusLine().getStatusCode());
client.removeResponseInterceptorByClass(this.getClass());