rgw: implement POST key can use ${filename}

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
This commit is contained in:
Yehuda Sadeh 2012-10-11 14:27:16 -07:00
parent d7b59429f2
commit ca1e1776fc
2 changed files with 31 additions and 8 deletions

View File

@ -631,7 +631,7 @@ int RGWPostObj_ObjStore_S3::read_form_part_header(struct post_form_part *part,
part->fields[field_name] = field;
if (field_name.compare("Content-Disposition") == 0) {
if (stringcasecmp(field_name, "Content-Disposition") == 0) {
part->name = field.params["name"];
}
@ -666,6 +666,20 @@ bool RGWPostObj_ObjStore_S3::part_bl(const string& name, bufferlist *pbl)
return true;
}
void RGWPostObj_ObjStore_S3::rebuild_key(string& key)
{
static string var = "${filename}";
int pos = key.find(var);
if (pos < 0)
return;
string new_key = key.substr(0, pos);
new_key.append(filename);
new_key.append(key.substr(pos + var.size()));
key = new_key;
}
int RGWPostObj_ObjStore_S3::get_params()
{
string temp_line;
@ -721,12 +735,12 @@ int RGWPostObj_ObjStore_S3::get_params()
if (r < 0)
return r;
map<string, struct post_part_field>::iterator piter;
for (piter = part.fields.begin(); piter != part.fields.end(); ++piter) {
ldout(s->cct, 20) << "read part header: name=" << part.name << " content_type=" << part.content_type << dendl;
ldout(s->cct, 20) << "name=" << piter->first << dendl;
ldout(s->cct, 20) << "val=" << piter->second.val << dendl;
if (s->cct->_conf->subsys.should_gather(ceph_subsys_rgw, 20)) {
if (s->cct->_conf->subsys.should_gather(ceph_subsys_rgw, 20)) {
map<string, struct post_part_field, ltstr_nocase>::iterator piter;
for (piter = part.fields.begin(); piter != part.fields.end(); ++piter) {
ldout(s->cct, 20) << "read part header: name=" << part.name << " content_type=" << part.content_type << dendl;
ldout(s->cct, 20) << "name=" << piter->first << dendl;
ldout(s->cct, 20) << "val=" << piter->second.val << dendl;
ldout(s->cct, 20) << "params:" << dendl;
map<string, string>& params = piter->second.params;
for (iter = params.begin(); iter != params.end(); ++iter) {
@ -739,6 +753,11 @@ int RGWPostObj_ObjStore_S3::get_params()
return -EINVAL;
if (stringcasecmp(part.name, "file") == 0) { /* beginning of data transfer */
struct post_part_field& field = part.fields["Content-Disposition"];
map<string, string>::iterator iter = field.params.find("filename");
if (iter != field.params.end()) {
filename = iter->second;
}
parts[part.name] = part;
data_pending = true;
break;
@ -757,6 +776,8 @@ int RGWPostObj_ObjStore_S3::get_params()
if (!part_str("key", &s->object_str))
return -EINVAL;
rebuild_key(s->object_str);
part_str("Content-Type", &content_type);
env.add_var("Content-Type", content_type);

View File

@ -90,12 +90,13 @@ struct post_part_field {
struct post_form_part {
string name;
string content_type;
map<string, struct post_part_field> fields;
map<string, struct post_part_field, ltstr_nocase> fields;
bufferlist data;
};
class RGWPostObj_ObjStore_S3 : public RGWPostObj_ObjStore {
string boundary;
string filename;
bufferlist in_data;
map<string, post_form_part, const ltstr_nocase> parts;
RGWPolicyEnv env;
@ -115,6 +116,7 @@ class RGWPostObj_ObjStore_S3 : public RGWPostObj_ObjStore {
bool part_bl(const string& name, bufferlist *pbl);
int get_policy();
void rebuild_key(string& key);
public:
RGWPostObj_ObjStore_S3() {}
~RGWPostObj_ObjStore_S3() {}