Skip to content

Commit

Permalink
Merge remote-tracking branch 'radoslaw/wip-conf-md-add' into wip-rgw-…
Browse files Browse the repository at this point in the history
…yehuda

PR #5969
  • Loading branch information
yehudasa committed Sep 29, 2015
2 parents cd3b9b3 + 88cffd8 commit 7f31d67
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 52 deletions.
11 changes: 6 additions & 5 deletions doc/radosgw/config-ref.rst
Expand Up @@ -231,14 +231,15 @@ Ceph configuration file, the default value will be set automatically.

``rgw extended http attrs``

:Description: Add new set of attributes that could be set on an object. These
extra attributes can be set through HTTP header fields when
putting the objects. If set, these attributes will return as HTTP
fields when doing GET/HEAD on the object.
:Description: Add new set of attributes that could be set on an entity
(user, bucket or object). These extra attributes can be set
through HTTP header fields when putting the entity or modifying
it using POST method. If set, these attributes will return as
HTTP fields when doing GET/HEAD on the entity.

:Type: String
:Default: None
:Example: "content_foo, content_bar"
:Example: "content_foo, content_bar, x-foo-bar"


``rgw exit timeout secs``
Expand Down
43 changes: 21 additions & 22 deletions src/rgw/rgw_rest.cc
Expand Up @@ -32,15 +32,13 @@ struct rgw_http_attr {
/*
* mapping between rgw object attrs and output http fields
*/
static struct rgw_http_attr rgw_to_http_attr_list[] = {
{ RGW_ATTR_CONTENT_TYPE, "Content-Type"},
{ RGW_ATTR_CONTENT_LANG, "Content-Language"},
{ RGW_ATTR_EXPIRES, "Expires"},
{ RGW_ATTR_CACHE_CONTROL, "Cache-Control"},
{ RGW_ATTR_CONTENT_DISP, "Content-Disposition"},
{ RGW_ATTR_CONTENT_ENC, "Content-Encoding"},
{ RGW_ATTR_USER_MANIFEST, "X-Object-Manifest"},
{ NULL, NULL},
static const struct rgw_http_attr base_rgw_to_http_attrs[] = {
{ RGW_ATTR_CONTENT_LANG, "Content-Language" },
{ RGW_ATTR_EXPIRES, "Expires" },
{ RGW_ATTR_CACHE_CONTROL, "Cache-Control" },
{ RGW_ATTR_CONTENT_DISP, "Content-Disposition" },
{ RGW_ATTR_CONTENT_ENC, "Content-Encoding" },
{ RGW_ATTR_USER_MANIFEST, "X-Object-Manifest" },
};


Expand All @@ -52,14 +50,13 @@ struct generic_attr {
/*
* mapping between http env fields and rgw object attrs
*/
struct generic_attr generic_attrs[] = {
{ "CONTENT_TYPE", RGW_ATTR_CONTENT_TYPE },
{ "HTTP_CONTENT_LANGUAGE", RGW_ATTR_CONTENT_LANG },
{ "HTTP_EXPIRES", RGW_ATTR_EXPIRES },
{ "HTTP_CACHE_CONTROL", RGW_ATTR_CACHE_CONTROL },
static const struct generic_attr generic_attrs[] = {
{ "CONTENT_TYPE", RGW_ATTR_CONTENT_TYPE },
{ "HTTP_CONTENT_LANGUAGE", RGW_ATTR_CONTENT_LANG },
{ "HTTP_EXPIRES", RGW_ATTR_EXPIRES },
{ "HTTP_CACHE_CONTROL", RGW_ATTR_CACHE_CONTROL },
{ "HTTP_CONTENT_DISPOSITION", RGW_ATTR_CONTENT_DISP },
{ "HTTP_CONTENT_ENCODING", RGW_ATTR_CONTENT_ENC },
{ NULL, NULL },
{ "HTTP_CONTENT_ENCODING", RGW_ATTR_CONTENT_ENC },
};

map<string, string> rgw_to_http_attrs;
Expand Down Expand Up @@ -147,14 +144,16 @@ string camelcase_dash_http_attr(const string& orig)
for (size_t i = 0; i < orig.size(); ++i, ++s) {
switch (*s) {
case '_':
case '-':
buf[i] = '-';
last_sep = true;
break;
default:
if (last_sep)
if (last_sep) {
buf[i] = toupper(*s);
else
} else {
buf[i] = tolower(*s);
}
last_sep = false;
}
}
Expand All @@ -166,12 +165,12 @@ static set<string> hostnames_set;

void rgw_rest_init(CephContext *cct, RGWRegion& region)
{
for (struct rgw_http_attr *attr = rgw_to_http_attr_list; attr->rgw_attr; attr++) {
rgw_to_http_attrs[attr->rgw_attr] = attr->http_attr;
for (const auto& rgw2http : base_rgw_to_http_attrs) {
rgw_to_http_attrs[rgw2http.rgw_attr] = rgw2http.http_attr;
}

for (struct generic_attr *gen_attr = generic_attrs; gen_attr->http_header; gen_attr++) {
generic_attrs_map[gen_attr->http_header] = gen_attr->rgw_attr;
for (const auto& http2rgw : generic_attrs) {
generic_attrs_map[http2rgw.http_header] = http2rgw.rgw_attr;
}

list<string> extended_http_attrs;
Expand Down
24 changes: 12 additions & 12 deletions src/rgw/rgw_rest_s3.cc
Expand Up @@ -138,22 +138,22 @@ int RGWGetObj_ObjStore_S3::send_response_data(bufferlist& bl, off_t bl_ofs, off_

for (iter = attrs.begin(); iter != attrs.end(); ++iter) {
const char *name = iter->first.c_str();

map<string, string>::iterator aiter = rgw_to_http_attrs.find(name);
if (aiter != rgw_to_http_attrs.end()) {
if (response_attrs.count(aiter->second) > 0) // was already overridden by a response param
continue;

if (aiter->first.compare(RGW_ATTR_CONTENT_TYPE) == 0) { // special handling for content_type
if (!content_type)
content_type = iter->second.c_str();
continue;
if (response_attrs.count(aiter->second) == 0) {
/* Was not already overridden by a response param. */
response_attrs[aiter->second] = iter->second.c_str();
}
response_attrs[aiter->second] = iter->second.c_str();
} else {
if (strncmp(name, RGW_ATTR_META_PREFIX, sizeof(RGW_ATTR_META_PREFIX)-1) == 0) {
name += sizeof(RGW_ATTR_PREFIX) - 1;
s->cio->print("%s: %s\r\n", name, iter->second.c_str());
} else if (iter->first.compare(RGW_ATTR_CONTENT_TYPE) == 0) {
/* Special handling for content_type. */
if (!content_type) {
content_type = iter->second.c_str();
}
} else if (strncmp(name, RGW_ATTR_META_PREFIX, sizeof(RGW_ATTR_META_PREFIX)-1) == 0) {
/* User custom metadata. */
name += sizeof(RGW_ATTR_PREFIX) - 1;
s->cio->print("%s: %s\r\n", name, iter->second.c_str());
}
}
}
Expand Down
31 changes: 18 additions & 13 deletions src/rgw/rgw_rest_swift.cc
Expand Up @@ -84,15 +84,17 @@ static void dump_account_metadata(struct req_state * const s,
}
}

/* Dump user-defined metadata items */
/* Dump user-defined metadata items and generic attrs. */
const size_t PREFIX_LEN = sizeof(RGW_ATTR_META_PREFIX) - 1;
map<string, bufferlist>::iterator iter;
for (iter = attrs.lower_bound(RGW_ATTR_META_PREFIX); iter != attrs.end(); ++iter) {
for (iter = attrs.lower_bound(RGW_ATTR_PREFIX); iter != attrs.end(); ++iter) {
const char *name = iter->first.c_str();
if (strncmp(name, RGW_ATTR_META_PREFIX, PREFIX_LEN) == 0) {
map<string, string>::const_iterator geniter = rgw_to_http_attrs.find(name);

if (geniter != rgw_to_http_attrs.end()) {
s->cio->print("%s: %s\r\n", geniter->second.c_str(), iter->second.c_str());
} else if (strncmp(name, RGW_ATTR_META_PREFIX, PREFIX_LEN) == 0) {
s->cio->print("X-Account-Meta-%s: %s\r\n", name + PREFIX_LEN, iter->second.c_str());
} else {
break;
}
}
}
Expand Down Expand Up @@ -338,15 +340,20 @@ static void dump_container_metadata(struct req_state *s, RGWBucketEnt& bucket)
if (!s->bucket_info.placement_rule.empty()) {
s->cio->print("X-Storage-Policy: %s\r\n", s->bucket_info.placement_rule.c_str());
}
// Dump user-defined metadata items

/* Dump user-defined metadata items and generic attrs. */
const size_t PREFIX_LEN = sizeof(RGW_ATTR_META_PREFIX) - 1;
map<string, bufferlist>::iterator iter;
for (iter = s->bucket_attrs.lower_bound(RGW_ATTR_META_PREFIX); iter != s->bucket_attrs.end(); ++iter) {
for (iter = s->bucket_attrs.lower_bound(RGW_ATTR_PREFIX);
iter != s->bucket_attrs.end();
++iter) {
const char *name = iter->first.c_str();
if (strncmp(name, RGW_ATTR_META_PREFIX, PREFIX_LEN) == 0) {
map<string, string>::const_iterator geniter = rgw_to_http_attrs.find(name);

if (geniter != rgw_to_http_attrs.end()) {
s->cio->print("%s: %s\r\n", geniter->second.c_str(), iter->second.c_str());
} else if (strncmp(name, RGW_ATTR_META_PREFIX, PREFIX_LEN) == 0) {
s->cio->print("X-Container-Meta-%s: %s\r\n", name + PREFIX_LEN, iter->second.c_str());
} else {
break;
}
}
}
Expand Down Expand Up @@ -723,9 +730,7 @@ static void dump_object_metadata(struct req_state * const s,
const char *name = iter->first.c_str();
map<string, string>::const_iterator aiter = rgw_to_http_attrs.find(name);

if (aiter != rgw_to_http_attrs.end() &&
aiter->first.compare(RGW_ATTR_CONTENT_TYPE) != 0) {
/* Filter out Content-Type. It must be treated separately. */
if (aiter != rgw_to_http_attrs.end()) {
response_attrs[aiter->second] = iter->second.c_str();
} else if (strncmp(name, RGW_ATTR_META_PREFIX, sizeof(RGW_ATTR_META_PREFIX)-1) == 0) {
name += sizeof(RGW_ATTR_META_PREFIX) - 1;
Expand Down

0 comments on commit 7f31d67

Please sign in to comment.