/*
* 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" },
};
/*
* 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;
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;
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());
}
}
}
const char *name = iter->first.c_str();
map<string, string>::const_iterator geniter = rgw_to_http_attrs.find(name);
- if (geniter != rgw_to_http_attrs.end() &&
- geniter->first.compare(RGW_ATTR_CONTENT_TYPE) != 0) {
+ 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());
const char *name = iter->first.c_str();
map<string, string>::const_iterator geniter = rgw_to_http_attrs.find(name);
- if (geniter != rgw_to_http_attrs.end() &&
- geniter->first.compare(RGW_ATTR_CONTENT_TYPE) != 0) {
+ 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());
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;