Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Unified Diff: native_client_sdk/src/libraries/nacl_io/mount_node_http.cc

Issue 16959007: [NaCl SDK] httpfs now sets errno to an appropriate value on non-200 response. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Simplify code using HTTPStatusCodeToErrno. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | native_client_sdk/src/libraries/nacl_io_test/mount_http_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/libraries/nacl_io/mount_node_http.cc
diff --git a/native_client_sdk/src/libraries/nacl_io/mount_node_http.cc b/native_client_sdk/src/libraries/nacl_io/mount_node_http.cc
index 5005ff48d30c292b81b345f80164497f10c55b49..29058d461d8539b194423d43e6854e500fe37ed0 100644
--- a/native_client_sdk/src/libraries/nacl_io/mount_node_http.cc
+++ b/native_client_sdk/src/libraries/nacl_io/mount_node_http.cc
@@ -27,6 +27,8 @@ namespace {
const size_t MAX_READ_BUFFER_SIZE = 64 * 1024;
const int32_t STATUSCODE_OK = 200;
const int32_t STATUSCODE_PARTIAL_CONTENT = 206;
+const int32_t STATUSCODE_FORBIDDEN = 403;
+const int32_t STATUSCODE_NOT_FOUND = 404;
StringMap_t ParseHeaders(const char* headers, int32_t headers_length) {
enum State {
@@ -124,6 +126,22 @@ bool ParseContentRange(const StringMap_t& headers,
return false;
}
+// Maps an HTTP |status_code| onto the appropriate errno code.
+int HTTPStatusCodeToErrno(int status_code) {
+ switch (status_code) {
+ case STATUSCODE_OK:
+ case STATUSCODE_PARTIAL_CONTENT:
+ return 0;
+ case STATUSCODE_FORBIDDEN:
+ return EACCES;
+ case STATUSCODE_NOT_FOUND:
+ return ENOENT;
+ }
+ if (status_code >= 400 && status_code < 500)
+ return EINVAL;
+ return EIO;
+}
+
} // namespace
void MountNodeHttp::SetCachedSize(off_t size) {
@@ -298,10 +316,9 @@ Error MountNodeHttp::OpenUrl(const char* method,
*out_statuscode = statuscode.value.as_int;
// Only accept OK or Partial Content.
- if (*out_statuscode != STATUSCODE_OK &&
- *out_statuscode != STATUSCODE_PARTIAL_CONTENT) {
- return EINVAL;
- }
+ Error error = HTTPStatusCodeToErrno(*out_statuscode);
+ if (error)
+ return error;
// Get response headers.
PP_Var response_headers_var = response_interface->GetProperty(
« no previous file with comments | « no previous file | native_client_sdk/src/libraries/nacl_io_test/mount_http_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698