summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2010-06-24 16:33:27 +0000
committerJohn Christopher Anderson <jchris@apache.org>2010-06-24 16:33:27 +0000
commit9721b8f6b1bd5d71ddfdb5175b5776ece26f1551 (patch)
tree83681f2aeb518abc80969c5c9d848f8432f734e2 /src
parent3c7ed52bc634c05f476fce11b2f7a758ba30fe57 (diff)
close COUCHDB-795 add X-HTTP-METHOD-OVERRIDE support. Thanks Brian Jenkins
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@957610 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_httpd.erl21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 331546eb..cb71203a 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -218,9 +218,26 @@ handle_request_int(MochiReq, DefaultFun,
Meth -> couch_util:to_existing_atom(Meth)
end,
increment_method_stats(Method1),
+
+ % allow broken HTTP clients to fake a full method vocabulary with an X-HTTP-METHOD-OVERRIDE header
+ MethodOverride = MochiReq:get_primary_header_value("X-HTTP-Method-Override"),
+ Method2 = case lists:member(MethodOverride, ["GET", "HEAD", "POST", "PUT", "DELETE", "TRACE", "CONNECT", "COPY"]) of
+ true ->
+ ?LOG_INFO("MethodOverride: ~s (real method was ~s)", [MethodOverride, Method1]),
+ case Method1 of
+ 'POST' -> list_to_atom(MethodOverride);
+ _ ->
+ % Ignore X-HTTP-Method-Override when the original verb isn't POST.
+ % I'd like to send a 406 error to the client, but that'd require a nasty refactor.
+ % throw({not_acceptable, <<"X-HTTP-Method-Override may only be used with POST requests.">>})
+ Method1
+ end;
+ _ -> Method1
+ end,
+
% alias HEAD to GET as mochiweb takes care of stripping the body
- Method = case Method1 of
- 'HEAD' -> 'GET';
+ Method = case Method2 of
+ 'HEAD' -> 'GET';
Other -> Other
end,