Skip to content

Commit

Permalink
Fix gateway part of #263
Browse files Browse the repository at this point in the history
  • Loading branch information
mocchira committed Oct 29, 2014
1 parent de41591 commit cf3c58c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/leo_http.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
-define(HTTP_ST_BAD_REQ, 400).
-define(HTTP_ST_FORBIDDEN, 403).
-define(HTTP_ST_NOT_FOUND, 404).
-define(HTTP_ST_CONFLICT, 409).
-define(HTTP_ST_BAD_RANGE, 416).
-define(HTTP_ST_INTERNAL_ERROR, 500).
-define(HTTP_ST_SERVICE_UNAVAILABLE, 503).
Expand Down Expand Up @@ -130,6 +131,8 @@
-define(XML_ERROR_CODE_InvalidRange, "InvalidRange").
-define(XML_ERROR_CODE_InternalError, "InternalError").
-define(XML_ERROR_CODE_ServiceUnavailable, "ServiceUnavailable").
-define(XML_ERROR_CODE_BucketAlreadyExists, "BucketAlreadyExists").
-define(XML_ERROR_CODE_BucketAlreadyOwnedByYou, "BucketAlreadyOwnedByYou").

%% error messages used in a error response
-define(XML_ERROR_MSG_EntityTooLarge, "Your proposed upload exceeds the maximum allowed object size.").
Expand All @@ -139,6 +142,8 @@
-define(XML_ERROR_MSG_InvalidRange, "The requested range cannot be satisfied.").
-define(XML_ERROR_MSG_InternalError, "We encountered an internal error. Please try again.").
-define(XML_ERROR_MSG_ServiceUnavailable, "Please reduce your request rate.").
-define(XML_ERROR_MSG_BucketAlreadyExists, "Please select a different name and try again.").
-define(XML_ERROR_MSG_BucketAlreadyOwnedByYou, "Your previous request to create the named bucket succeeded and you already own it.").

%% Macros
-define(reply_ok(_H,_R), cowboy_req:reply(?HTTP_ST_OK, _H,_R)). %% 200
Expand Down Expand Up @@ -169,6 +174,10 @@
io_lib:format(?XML_ERROR, [?XML_ERROR_CODE_NoSuchKey,
?XML_ERROR_MSG_NoSuchKey,
xmerl_lib:export_text(_Key), _ReqId]), _R)).
-define(reply_conflict(_H, _Code, _Msg, _Key, _ReqId, _R),
cowboy_req:reply(?HTTP_ST_CONFLICT, _H,
io_lib:format(?XML_ERROR, [_Code, _Msg,
xmerl_lib:export_text(_Key), _ReqId]), _R)).
-define(reply_bad_range(_H, _Key, _ReqId, _R),
cowboy_req:reply(?HTTP_ST_BAD_RANGE, _H,
io_lib:format(?XML_ERROR, [?XML_ERROR_CODE_InvalidRange,
Expand Down
8 changes: 8 additions & 0 deletions src/leo_gateway_s3_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ put_bucket(Req, Key, #req_params{access_key_id = AccessKeyId,
?reply_ok([?SERVER_HEADER], Req);
{error, ?ERR_TYPE_INTERNAL_ERROR} ->
?reply_internal_error([?SERVER_HEADER], Key, <<>>, Req);
{error, invalid_access} ->
?reply_forbidden([?SERVER_HEADER], Key, <<>>, Req);
{error, already_exists} ->
?reply_conflict([?SERVER_HEADER], ?XML_ERROR_CODE_BucketAlreadyExists,
?XML_ERROR_MSG_BucketAlreadyExists, Key, <<>>, Req);
{error, already_yours} ->
?reply_conflict([?SERVER_HEADER], ?XML_ERROR_CODE_BucketAlreadyOwnedByYou,
?XML_ERROR_MSG_BucketAlreadyOwnedByYou, Key, <<>>, Req);
{error, timeout} ->
?reply_timeout([?SERVER_HEADER], Key, <<>>, Req)
end;
Expand Down

0 comments on commit cf3c58c

Please sign in to comment.