]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: dump content type when listing objects (swift)
authorYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 23 Mar 2011 23:50:21 +0000 (16:50 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 23 Mar 2011 23:50:21 +0000 (16:50 -0700)
src/rgw/rgw_access.h
src/rgw/rgw_common.h
src/rgw/rgw_fs.cc
src/rgw/rgw_fs.h
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_rest_os.cc

index dae8bcc481b96fb4c4fb691d237132f98c2faccb..134c5bdd447a9743444e2dc62c9a5a99af2bdc09 100644 (file)
@@ -39,7 +39,8 @@ public:
    *     here.
    */
   virtual int list_objects(std::string& id, std::string& bucket, int max, std::string& prefix, std::string& delim,
-                           std::string& marker, std::vector<RGWObjEnt>& result, map<string, bool>& common_prefixes) = 0;
+                           std::string& marker, std::vector<RGWObjEnt>& result, map<string, bool>& common_prefixes,
+                           bool get_content_type) = 0;
 
   /** Create a new bucket*/
   virtual int create_bucket(std::string& id, std::string& bucket, map<std::string, bufferlist>& attrs, uint64_t auid=0) = 0;
index f6ce42ca2cbaf8d459d22d2abcc739f7f4066a84..5730c9feaf478a2440fe081646e50ebf36f408f1 100644 (file)
@@ -48,6 +48,9 @@ using ceph::crypto::MD5;
 #define RGW_FORMAT_XML          1
 #define RGW_FORMAT_JSON         2
 
+#define RGW_REST_OPENSTACK      0x1
+#define RGW_REST_OPENSTACK_AUTH 0x2
+
 #define CGI_PRINTF(state, format, ...) do { \
    int __ret = FCGX_FPrintF(state->fcgx->out, format, __VA_ARGS__); \
    if (state->header_ended) \
@@ -263,29 +266,8 @@ struct RGWObjEnt {
   time_t mtime;
   // two md5 digests and a terminator
   char etag[ceph::crypto::MD5::DIGESTSIZE * 2 + 1];
-
-  void encode(bufferlist& bl) const {
-    __u8 struct_v = 1;
-    ::encode(struct_v, bl);
-    uint64_t s = size;
-    __u32 mt = mtime;
-    ::encode(name, bl);
-    ::encode(s, bl);
-    ::encode(mt, bl);
-  }
-  void decode(bufferlist::iterator& bl) {
-    __u8 struct_v;
-    ::decode(struct_v, bl);
-    __u32 mt;
-    uint64_t s;
-    ::decode(name, bl);
-    ::decode(s, bl);
-    ::decode(mt, bl);
-    size = s;
-    mtime = mt;
-  }
+  string content_type;
 };
-WRITE_CLASS_ENCODER(RGWObjEnt)
 
 /** Store basic data on an object */
 struct RGWBucketEnt {
index 95bec10310aec08b08f4e0a90192c1044d60ac8c..243db5c3e10c73d66613a12a2f2513e4cb9e9292 100644 (file)
@@ -90,7 +90,8 @@ int RGWFS::obj_stat(string& bucket, string& obj, uint64_t *psize, time_t *pmtime
 }
 
 int RGWFS::list_objects(string& id, string& bucket, int max, string& prefix, string& delim,
-                       string& marker, vector<RGWObjEnt>& result, map<string, bool>& common_prefixes)
+                       string& marker, vector<RGWObjEnt>& result, map<string, bool>& common_prefixes,
+                       bool get_content_type)
 {
   map<string, bool> dir_map;
   char path[BUF_SIZE];
index 2b5a5096c2fd57d8c7a3d6c3cd3f4f895d668b0a..b2e424d6181821905fe8bb1c670f8b818e33a0fb 100644 (file)
@@ -14,7 +14,8 @@ public:
   int list_buckets_next(std::string& id, RGWObjEnt& obj, RGWAccessHandle *handle);
 
   int list_objects(std::string& id, std::string& bucket, int max, std::string& prefix, std::string& delim,
-                   std::string& marker, std::vector<RGWObjEnt>& result, map<string, bool>& common_prefixes);
+                   std::string& marker, std::vector<RGWObjEnt>& result, map<string, bool>& common_prefixes,
+                   bool get_content_type);
 
   int create_bucket(std::string& id, std::string& bucket, map<std::string, bufferlist>& attrs, uint64_t auid=0);
   int put_obj_meta(std::string& id, std::string& bucket, std::string& obj, time_t *mtime,
index 00ab428af89b5492f7218d4f11716caf823cf028..e319ad0b0f87df28c31ba74e12e42f269ba6c6e2 100644 (file)
@@ -280,7 +280,8 @@ void RGWListBucket::execute()
   }
   url_decode(s->args.get("delimiter"), delimiter);
 
-  ret = rgwstore->list_objects(s->user.user_id, s->bucket_str, max, prefix, delimiter, marker, objs, common_prefixes);
+  ret = rgwstore->list_objects(s->user.user_id, s->bucket_str, max, prefix, delimiter, marker, objs, common_prefixes,
+                               !!(s->prot_flags & RGW_REST_OPENSTACK));
 done:
   send_response();
 }
index 77d497d816a6606a00fa7a5ae12be4ded9368db1..e84c8022e7f017bbbb45cc141a8e753a43eea803 100644 (file)
@@ -18,9 +18,6 @@ using namespace std;
 
 struct req_state;
 
-#define RGW_REST_OPENSTACK      0x1
-#define RGW_REST_OPENSTACK_AUTH 0x2
-
 /** Get the HTTP request metadata */
 extern void get_request_metadata(struct req_state *s, map<string, bufferlist>& attrs);
 /**
index 2ee7c557f12cc707713a85258cd22c77e5ab0517..a624b46ff32bbf8f4e4879b379e1a686dd59d1a6 100644 (file)
@@ -133,7 +133,8 @@ int RGWRados::list_buckets_next(std::string& id, RGWObjEnt& obj, RGWAccessHandle
  *     here.
  */
 int RGWRados::list_objects(string& id, string& bucket, int max, string& prefix, string& delim,
-                          string& marker, vector<RGWObjEnt>& result, map<string, bool>& common_prefixes)
+                          string& marker, vector<RGWObjEnt>& result, map<string, bool>& common_prefixes,
+                          bool get_content_type)
 {
   librados::IoCtx io_ctx;
   int r = rados->ioctx_create(bucket.c_str(), io_ctx);
@@ -188,6 +189,13 @@ int RGWRados::list_objects(string& id, string& bucket, int max, string& prefix,
       strncpy(obj.etag, bl.c_str(), sizeof(obj.etag));
       obj.etag[sizeof(obj.etag)-1] = '\0';
     }
+    if (get_content_type) {
+      bl.clear();
+      obj.content_type = "";
+      if (io_ctx.getxattr(*p, RGW_ATTR_CONTENT_TYPE, bl) >= 0) {
+        obj.content_type = bl.c_str();
+      }
+    }
     result.push_back(obj);
   }
 
index 7be06ee0730341055075555079cb767d67bb1990..e88224c19d5a207b08969570c487024d77c4d28c 100644 (file)
@@ -30,7 +30,8 @@ public:
 
   /** get listing of the objects in a bucket */
   virtual int list_objects(std::string& id, std::string& bucket, int max, std::string& prefix, std::string& delim,
-                   std::string& marker, std::vector<RGWObjEnt>& result, map<string, bool>& common_prefixes);
+                   std::string& marker, std::vector<RGWObjEnt>& result, map<string, bool>& common_prefixes,
+                  bool get_content_type);
 
   /**
    * create a bucket with name bucket and the given list of attrs
index c1d21396da013c45056f44469a1d7dd875ff0add..6692589b5f14e0392cad54719867ebbc25139fa3 100644 (file)
@@ -83,6 +83,8 @@ void RGWListBucket_REST_OS::send_response()
       s->formatter->dump_value_str("name", iter->name.c_str());
       s->formatter->dump_value_str("hash", "&quot;%s&quot;", iter->etag);
       s->formatter->dump_value_int("bytes", "%lld", iter->size);
+      if (iter->content_type.size())
+        s->formatter->dump_value_str("content_type", iter->content_type.c_str());
       dump_time(s, "last_modified", &iter->mtime);
       s->formatter->close_section("object");
     }