[ios] [android] Use Response::NotFound in other HTTP implementations too

This commit is contained in:
John Firebaugh
2015-09-29 17:27:38 -07:00
parent 7112d43609
commit 686c967c8e
5 changed files with 26 additions and 2 deletions

View File

@@ -292,6 +292,9 @@ void HTTPAndroidRequest::onResponse(int code, std::string message, std::string e
} else if (code == 200) {
response->status = Response::Successful;
status = ResponseStatus::Successful;
} else if (responseCode == 404) {
response->status = Response::NotFound;
status = ResponseStatus::Successful;
} else if (code >= 500 && code < 600) {
response->status = Response::Error;
response->message = "HTTP status code " + util::toString(code);

View File

@@ -294,6 +294,9 @@ void HTTPNSURLRequest::handleResult(NSData *data, NSURLResponse *res, NSError *e
} else if (responseCode == 200) {
response->status = Response::Successful;
status = ResponseStatus::Successful;
} else if (responseCode == 404) {
response->status = Response::NotFound;
status = ResponseStatus::Successful;
} else if (responseCode >= 500 && responseCode < 600) {
// Server errors may be temporary, so back off exponentially.
response->status = Response::Error;

View File

@@ -703,6 +703,9 @@ void HTTPCURLRequest::handleResult(CURLcode code) {
} else if (responseCode == 200) {
response->status = Response::Successful;
return finish(ResponseStatus::Successful);
} else if (responseCode == 404) {
response->status = Response::NotFound;
return finish(ResponseStatus::Successful);
} else if (responseCode >= 500 && responseCode < 600) {
// Server errors may be temporary, so back off exponentially.
response->status = Response::Error;

View File

@@ -9,6 +9,7 @@
TEST_F(Storage, HTTPReading) {
SCOPED_TEST(HTTPTest)
SCOPED_TEST(HTTP404)
SCOPED_TEST(HTTP500)
using namespace mbgl;
@@ -31,14 +32,25 @@ TEST_F(Storage, HTTPReading) {
fs.request({ Resource::Unknown, "http://127.0.0.1:3000/doesnotexist" }, uv_default_loop(),
[&](const Response &res) {
EXPECT_EQ(uv_thread_self(), mainThread);
EXPECT_EQ(Response::Error, res.status);
EXPECT_EQ("HTTP status code 404", res.message);
EXPECT_EQ(Response::NotFound, res.status);
EXPECT_EQ("", res.message);
EXPECT_EQ(0, res.expires);
EXPECT_EQ(0, res.modified);
EXPECT_EQ("", res.etag);
HTTP404.finish();
});
fs.request({ Resource::Unknown, "http://127.0.0.1:3000/permanent-error" }, uv_default_loop(),
[&](const Response &res) {
EXPECT_EQ(uv_thread_self(), mainThread);
EXPECT_EQ(Response::Error, res.status);
EXPECT_EQ("HTTP status code 500", res.message);
EXPECT_EQ(0, res.expires);
EXPECT_EQ(0, res.modified);
EXPECT_EQ("", res.etag);
HTTP500.finish();
});
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
}

View File

@@ -73,6 +73,9 @@ app.get('/revalidate-etag', function(req, res) {
revalidateEtagCounter++;
});
app.get('/permanent-error', function(req, res) {
res.status(500).end();
});
var temporaryErrorCounter = 0;
app.get('/temporary-error', function(req, res) {