I am trying to create a response like this
-------------Request----------- HEAD /external/images/media/21.jpg HTTP/1.0
getcontentFeatures.dlna.org: 1
Host: 192.168.1.130:57645
-----------My desired answer------------------ HTTP/1.1 200 OK
Date: Tue, 21 Aug 2012 10:24:59 GMT
Cache-Control: no-cache
transferMode.dlna.org: Streaming
contentFeatures.dlna.org: DLNA.ORG_PN=JPEG_LRG;DLNA.ORG_OP=01;DLNA.ORG_CI=0
Content-Type: image/jpeg
Last-Modified: Sat, 25 Feb 2012 15:11:58 GMT
Content-Length: 60909
Accept-Ranges: bytes
but i have a problem when i try to put "Content-Length: 60909" this exception is thrown "Content-Length header already present", if i dont put the Header Content-Length is always 0, so is not what i want.
This is my code:
public void handle(HttpRequest request,
HttpResponse response,
HttpContext context) throws HttpException, IOException {
String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
if(method.equals("HEAD"))
{
String objectId = getUrlBuilder().getObjectId(request.getRequestLine().getUri());
DIDLObject obj = findObjectWithId(objectId);
if (obj == null) {
response.setStatusCode(HttpStatus.SC_NOT_FOUND);
return;
}
MimeType mimeType = getMimeType(obj);
long sizeInBytes = getSizeInBytes(obj);
response.setHeader("Cache-control", "no-cache");
response.setHeader("transferMode.dlna.org", "Streaming");
String aMimeType = mimeType.toString();
String dlnaspec="";
if (aMimeType.equals("image/jpeg"))
dlnaspec = "DLNA.ORG_PN=JPEG_LRG";
else if (aMimeType.equals("audio/mpeg"))
dlnaspec = "DLNA.ORG_PN=MP3";
else if (aMimeType.equals("audio/L16") || aMimeType.equals("audio/wav"))
dlnaspec = "DLNA.ORG_PN=LPCM";
response.setHeader("contentFeatures.dlna.org", dlnaspec+";DLNA.ORG_OP=01;DLNA.ORG_CI=0");
response.setHeader("Content-Type", mimeType.toString());
response.setHeader("Accept-Ranges", "bytes");
response.setHeader("Content-Length", String.valueOf(sizeInBytes));
response.setStatusCode(HttpStatus.SC_OK);
}
}
any ideas? i have tried also to put an Entity in this way
ByteArrayInputStream stream=new ByteArrayInputStream(new byte[(int) sizeInBytes]);
InputStreamEntity entity = new InputStreamEntity(stream, sizeInBytes);
response.setEntity(entity);
but the problem is that the HEAD method dont have a body so this approach is not valid