Advertisement
sbalko74

nacl_io patch for blob URLs

May 1st, 2014
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.00 KB | None | 0 0
  1. --- a/nacl_sdk/pepper_canary/src/nacl_io/httpfs/http_fs.cc
  2. +++ b/nacl_sdk/pepper_canary/src/nacl_io/httpfs/http_fs.cc
  3. @@ -213,9 +213,11 @@ Error HttpFs::Init(const FsInitArgs& args) {
  4.         ++iter) {
  5.      if (iter->first == "SOURCE") {
  6.        url_root_ = iter->second;
  7. +      is_blob_url_ = url_root_.substr(0,5) == "blob:";
  8.  
  9.        // Make sure url_root_ ends with a slash.
  10. -      if (!url_root_.empty() && url_root_[url_root_.length() - 1] != '/') {
  11. +      // Blob URLs must not get a slash appended.
  12. +      if (!url_root_.empty() && !is_blob_url_ && url_root_[url_root_.length() - 1] != '/') {
  13.          url_root_ += '/';
  14.        }
  15.      } else if (iter->first == "manifest") {
  16.  
  17.  
  18. --- a/nacl_sdk/pepper_canary/src/nacl_io/httpfs/http_fs_node.cc
  19. +++ b/nacl_sdk/pepper_canary/src/nacl_io/httpfs/http_fs_node.cc
  20. @@ -234,18 +236,36 @@ Error HttpFsNode::GetStat_Locked(struct stat* stat) {
  21.      ScopedResource response(filesystem_->ppapi());
  22.      int32_t statuscode;
  23.      StringMap_t response_headers;
  24. -    Error error = OpenUrl("HEAD",
  25. -                          &headers,
  26. -                          &loader,
  27. -                          &request,
  28. -                          &response,
  29. -                          &statuscode,
  30. -                          &response_headers);
  31. +    Error error(0);
  32. +
  33. +    // TODO: data URLs
  34. +    if (filesystem->is_blob_url_) {
  35. +      // Blob URLs do not support HEAD requests, but do give the content length
  36. +      // in their response headers. We issue a single-byte GET request to retrieve
  37. +      // the content length.
  38. +      headers["Range"] = "bytes=0-0";
  39. +      error = OpenUrl("GET",
  40. +                      &headers,
  41. +                      &loader,
  42. +                      &request,
  43. +                      &response,
  44. +                      &statuscode,
  45. +                      &response_headers);
  46. +    } else {
  47. +      error = OpenUrl("HEAD",
  48. +                      &headers,
  49. +                      &loader,
  50. +                      &request,
  51. +                      &response,
  52. +                      &statuscode,
  53. +                      &response_headers);
  54. +    }
  55. +
  56.      if (error)
  57.        return error;
  58.  
  59. -    size_t entity_length;
  60. -    if (ParseContentLength(response_headers, &entity_length)) {
  61. +    size_t read_start, read_end, entity_length;
  62. +    if ((filesystem->is_blob_url_ && ParseContentRange(response_headers, &read_start, &read_end, &entity_length)) || (!filesystem->is_blob_url_ && ParseContentLength(response_headers, &entity_length))) {
  63.        SetCachedSize(static_cast<off_t>(entity_length));
  64.      } else if (cache_content_) {
  65.        // The server didn't give a content length; download the data to memory
  66.  
  67.  
  68.  
  69. --- a/nacl_sdk/pepper_canary/include/nacl_io/httpfs/http_fs.h
  70. +++ b/nacl_sdk/pepper_canary/include/nacl_io/httpfs/http_fs.h
  71. @@ -53,6 +53,7 @@ class HttpFs : public Filesystem {
  72.    bool allow_credentials_;
  73.    bool cache_stat_;
  74.    bool cache_content_;
  75. +  bool is_blob_url_;
  76.  
  77.    friend class TypedFsFactory<HttpFs>;
  78.    friend class HttpFsNode;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement