Removed the automatic 302 redirects for ARI URL's that end with a slash.

There were some problems redirecting RESTful API requests; notably the client
would change the request method to GET on the redirected requests. After some
looking into, I decided that a 404 would be simpler and have more consistent
behavior.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393083 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
David M. Lee
2013-06-28 01:07:32 +00:00
parent 0008f15a77
commit 1426b2b228

View File

@@ -702,10 +702,24 @@ static void remove_trailing_slash(const char *uri,
char *slashless = ast_strdupa(uri); char *slashless = ast_strdupa(uri);
slashless[strlen(slashless) - 1] = '\0'; slashless[strlen(slashless) - 1] = '\0';
ast_str_append(&response->headers, 0, /* While it's tempting to redirect the client to the slashless URL,
"Location: /stasis/%s\r\n", slashless); * that is problematic. A 302 Found is the most appropriate response,
stasis_http_response_error(response, 302, "Found", * but most clients issue a GET on the location you give them,
"Redirecting to %s", slashless); * regardless of the method of the original request.
*
* While there are some ways around this, it gets into a lot of client
* specific behavior and corner cases in the HTTP standard. There's also
* very little practical benefit of redirecting; only GET and HEAD can
* be redirected automagically; all other requests "MUST NOT
* automatically redirect the request unless it can be confirmed by the
* user, since this might change the conditions under which the request
* was issued."
*
* Given all of that, a 404 with a nice message telling them what to do
* is probably our best bet.
*/
stasis_http_response_error(response, 404, "Not Found",
"ARI URL's do not end with a slash. Try /%s", slashless);
} }
/*! /*!