// Is this resource writable ?
if ( ! getPutableFlag() ) {
Reply error = request.makeReply(HTTP.NOT_ALLOWED) ;
error.setHeaderValue(Reply.H_ALLOW, getAllow());
error.setContent("Method PUT not allowed.") ;
throw new HTTPException (error) ;
}
// Check validators:
int cim = checkIfMatch(request);
if ((cim == COND_FAILED) || (cim == COND_WEAK)
|| (checkIfNoneMatch(request) == 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.NOT_IMPLEMENTED);
error.setContent("partial PUT not supported.");
throw new HTTPException(error);
}
// REMOVED as it is impossile for clients to behave properly.
// Of course it is fare more unsafe now, but it was too impractical IRL.
// Check that if some type is provided it doesn't conflict:
// if ( request.hasContentType() ) {
// MimeType rtype = request.getContentType() ;
// MimeType type = getContentType() ;
// if ( type == null ) {
// setValue (ATTR_CONTENT_TYPE, rtype) ;
// } else if ( (rtype.match (type) < 0 ) && !rtype.equiv(type) ) {
// 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: "+rtype.toString()
// + " is not matching resource MIME type: "
// +type.toString());
// throw new HTTPException (error) ;
// }
// }
// Write the body back to the file:
try {
// We are about to accept the put, notify client before continuing
Client client = request.getClient();
if ( client != null && request.getExpect() != null ) {
// FIXME we should check for "100-continue" explicitely
client.sendContinue();
}
if ( fresource.newContent(request.getInputStream()) )
status = HTTP.CREATED;
else
status = HTTP.NO_CONTENT;
} catch (IOException ex) {
if (debug)
ex.printStackTrace();
// so we have a problem replacing or creating the content
// it is then a configuration problem (access right for the
// underlying fle resource for example...
Reply error = request.makeReply(HTTP.INTERNAL_SERVER_ERROR) ;
error.setReason("File Access Error");
error.setContent("<p>Unable to save " + request.getURL()
+" due to IO problems");
throw new HTTPException (error) ;
}
if ( status == HTTP.CREATED ) {
reply = request.makeReply(status);
reply.setContent("<P>Resource succesfully created");
if (request.hasState(STATE_CONTENT_LOCATION))