Skip to content
Permalink
Browse files

Improve Rhizome HTTP status codes

Also improve some reason phrases and test them
  • Loading branch information...
quixotique committed Sep 21, 2015
1 parent 96055e6 commit 6123503c152b1f4cbe21a93005f6d9477892c651
@@ -1118,7 +1118,7 @@ static int http_request_start_body(struct http_request *r)
else if (r->verb == HTTP_VERB_POST) {
if (r->request_header.content_length == CONTENT_LENGTH_UNKNOWN) {
IDEBUGF(r->debug, "Malformed HTTP %s request: missing Content-Length header", r->verb);
return 411;
return 411; // Length Required
}
if (r->request_header.content_length == 0) {
r->parser = http_request_reject_content;
@@ -1142,7 +1142,7 @@ static int http_request_start_body(struct http_request *r)
} else {
IDEBUGF(r->debug, "Unsupported HTTP %s request: Content-Type %s not supported",
r->verb, alloca_mime_content_type(&r->request_header.content_type));
return 415;
return 415; // Unsupported Media Type
}
}
}
@@ -1917,6 +1917,9 @@ static const char *httpResultString(int response_code)
case 414: return "Request-URI Too Long";
case 415: return "Unsupported Media Type";
case 416: return "Requested Range Not Satisfiable";
case 422: return "Unprocessable Entity";
case 423: return "Locked";
case 429: return "Too Many Requests";
case 431: return "Request Header Fields Too Large";
case 500: return "Internal Server Error";
case 501: return "Not Implemented";
@@ -93,10 +93,16 @@ protected static Status receiveResponse(HttpURLConnection conn, int[] expected_r
JSONTokeniser json = new JSONTokeniser(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
decodeRestfulStatus(status, json);
}
if (status.http_status_code == HttpURLConnection.HTTP_FORBIDDEN)
switch (status.http_status_code) {
case HttpURLConnection.HTTP_FORBIDDEN: // for crypto failure (missing secret)
case HttpURLConnection.HTTP_NOT_FOUND: // for unknown BID
case 422: // Unprocessable Entity, for invalid/malformed manifest
case 423: // Locked, for database busy
case 429: // Too Many Requests, for out of manifests
return status;
if (status.http_status_code == HttpURLConnection.HTTP_NOT_IMPLEMENTED)
case HttpURLConnection.HTTP_NOT_IMPLEMENTED:
throw new ServalDNotImplementedException(status.http_status_message);
}
throw new ServalDInterfaceException("unexpected HTTP response: " + status.http_status_code + " " + status.http_status_message);
}

@@ -1658,6 +1658,14 @@ enum rhizome_bundle_status rhizome_find_duplicate(const rhizome_manifest *m, rhi
return ret;
}

/* Unpacks a database MANIFESTS table row into a manifest structure.
*
* Returns RHIZOME_BUNDLE_STATUS_SAME if unpack succeeds
* Returns RHIZOME_BUNDLE_STATUS_NEW if manifest is not found
* Returns RHIZOME_BUNDLE_STATUS_ERROR on error
* Returns RHIZOME_BUNDLE_STATUS_BUSY if the database is locked
* Caller is responsible for allocating and freeing rhizome_manifest
*/
static enum rhizome_bundle_status unpack_manifest_row(sqlite_retry_state *retry, rhizome_manifest *m, sqlite3_stmt *statement)
{
int r=sqlite_step_retry(retry, statement);
@@ -107,22 +107,22 @@ static int rhizome_direct_import_end(struct http_request *hr)
http_request_simple_response(&r->http, 201, "Bundle succesfully imported");
return 0;
case RHIZOME_BUNDLE_STATUS_SAME:
http_request_simple_response(&r->http, 200, "Bundle already imported");
http_request_simple_response(&r->http, 200, "Bundle already imported"); // OK
return 0;
case RHIZOME_BUNDLE_STATUS_OLD:
http_request_simple_response(&r->http, 403, "Newer bundle already stored");
http_request_simple_response(&r->http, 202, "Newer bundle already stored"); // Accepted
return 0;
case RHIZOME_BUNDLE_STATUS_INVALID:
http_request_simple_response(&r->http, 403, "Manifest is invalid");
http_request_simple_response(&r->http, 422, "Manifest is invalid"); // Unprocessable Entity
return 0;
case RHIZOME_BUNDLE_STATUS_INCONSISTENT:
http_request_simple_response(&r->http, 403, "Manifest is inconsistent with file");
http_request_simple_response(&r->http, 422, "Manifest is inconsistent with file"); // Unprocessable Entity
return 0;
case RHIZOME_BUNDLE_STATUS_FAKE:
http_request_simple_response(&r->http, 403, "Manifest not signed");
http_request_simple_response(&r->http, 403, "Manifest not signed"); // Forbidden
return 0;
case RHIZOME_BUNDLE_STATUS_NO_ROOM:
http_request_simple_response(&r->http, 403, "Not enough space");
http_request_simple_response(&r->http, 202, "Not enough space"); // Accepted
return 0;
case RHIZOME_BUNDLE_STATUS_READONLY:
case RHIZOME_BUNDLE_STATUS_DUPLICATE:

0 comments on commit 6123503

Please sign in to comment.
You can’t perform that action at this time.