{
// check if it is the right resource below!
if (!(fresource instanceof ImageFileResource)) {
return super.putFileResource(request);
}
Reply reply = null;
int status = HTTP.OK;
fresource.checkContent();
updateCachedHeaders();
// Is this resource writable ?
if ( ! getPutableFlag() ) {
Reply error = request.makeReply(HTTP.NOT_ALLOWED) ;
error.setContent("Method PUT not allowed.") ;
throw new HTTPException (error) ;
}
HttpEntityTag etag = getComETag();
// no IfMatch, or no matching ETag, maybe a PUT on the image
int cim = checkIfMatch(request, etag);
if ((request.getIfMatch() == null) ||
(cim == COND_FAILED) || (cim == COND_WEAK)) {
return super.putFileResource(request);
}
// check all the others validator
// Check remaining validators (checking if-none-match is lame
// as we already require the If-Match
if ((checkIfNoneMatch(request, etag) == COND_FAILED)
|| (checkIfModifiedSince(request) == COND_FAILED)
|| (checkIfUnmodifiedSince(request) == COND_FAILED)) {
Reply r = request.makeReply(HTTP.PRECONDITION_FAILED);
r.setContent("Pre-condition failed.");
return r;
}
// Check the request:
InputStream in = null;
try {
in = request.getInputStream();
if ( in == null ) {
Reply error = request.makeReply(HTTP.BAD_REQUEST) ;
error.setContent ("<p>Request doesn't have a valid content.");
throw new HTTPException (error) ;
}
} catch (IOException ex) {
throw new ClientException(request.getClient(), ex);
}
// We do not support (for the time being) put with ranges:
if ( request.hasContentRange() ) {
Reply error = request.makeReply(HTTP.BAD_REQUEST);
error.setContent("partial PUT not supported.");
throw new HTTPException(error);
}
// Check that if some type is provided it doesn't conflict:
if ( request.hasContentType() ) {
MimeType rtype = request.getContentType() ;
MimeType type = getCommentType() ;
if ( type == null ) {
setValue (ATTR_CONTENT_TYPE, rtype) ;
} else if ( rtype.match (type) < 0 ) {
if (debug) {
System.out.println("No match between: ["+
rtype.toString()+"] and ["+
type.toString()+"]");
}
Reply error = request.makeReply(HTTP.UNSUPPORTED_MEDIA_TYPE) ;
error.setContent ("<p>Invalid content type: "+type.toString());
throw new HTTPException (error) ;
}
}
ImageFileResource ifresource = (ImageFileResource) fresource;
// Write the body back to the file: