summaryrefslogtreecommitdiffstats
path: root/native_client_sdk/src/libraries/nacl_io/mount_http.h
blob: 145140d9bcc7cf26c74109c691e76c152bff4bde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


#ifndef LIBRARIES_NACL_IO_MOUNT_HTTP_H_
#define LIBRARIES_NACL_IO_MOUNT_HTTP_H_

#include <string>
#include "nacl_io/mount.h"
#include "nacl_io/pepper_interface.h"
#include "nacl_io/typed_mount_factory.h"

namespace nacl_io {

std::string NormalizeHeaderKey(const std::string& s);

class MountHttp : public Mount {
 public:
  typedef std::map<std::string, ScopedMountNode> NodeMap_t;

  virtual Error Access(const Path& path, int a_mode);
  virtual Error Open(const Path& path, int mode, ScopedMountNode* out_node);
  virtual Error Unlink(const Path& path);
  virtual Error Mkdir(const Path& path, int permissions);
  virtual Error Rmdir(const Path& path);
  virtual Error Remove(const Path& path);
  virtual Error Rename(const Path& path, const Path& newpath);

  PP_Resource MakeUrlRequestInfo(const std::string& url,
                                 const char* method,
                                 StringMap_t* additional_headers);

 protected:
  MountHttp();

  virtual Error Init(const MountInitArgs& args);
  virtual void Destroy();
  Error FindOrCreateDir(const Path& path, ScopedMountNode* out_node);
  Error LoadManifest(const std::string& path, char** out_manifest);
  Error ParseManifest(const char *text);

  NodeMap_t* GetNodeCacheForTesting() { return &node_cache_; }

 private:
  // Gets the URL to fetch for |path|.
  // |path| is relative to the mount point for the HTTP filesystem.
  std::string MakeUrl(const Path& path);

  std::string url_root_;
  StringMap_t headers_;
  NodeMap_t node_cache_;
  bool allow_cors_;
  bool allow_credentials_;
  bool cache_stat_;
  bool cache_content_;

  friend class TypedMountFactory<MountHttp>;
  friend class MountNodeHttp;
};

}  // namespace nacl_io

#endif  // LIBRARIES_NACL_IO_MOUNT_HTTP_H_