Merge pull request #19902 from linuxbox2/wip-rgw-mploc

rgw: return valid Location element, CompleteMultipartUpload
This commit is contained in:
Matt Benjamin 2018-02-02 11:37:01 -05:00 committed by GitHub
commit dcdb7aba28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 13 deletions

View File

@ -713,6 +713,22 @@ static inline void dump_header_if_nonempty(struct req_state* s,
}
}
static inline std::string compute_domain_uri(const struct req_state *s) {
std::string uri = (!s->info.domain.empty()) ? s->info.domain :
[&s]() -> std::string {
auto env = *(s->info.env);
std::string uri =
env.get("SERVER_PORT_SECURE") ? "https://" : "http://";
if (env.exists("SERVER_NAME")) {
uri.append(env.get("SERVER_NAME", "<SERVER_NAME>"));
} else {
uri.append(env.get("HTTP_HOST", "<HTTP_HOST>"));
}
return uri;
}();
return uri;
}
extern void dump_content_length(struct req_state *s, uint64_t len);
extern int64_t parse_content_length(const char *content_length);
extern void dump_etag(struct req_state *s,
@ -744,7 +760,6 @@ extern void dump_access_control(req_state *s, RGWOp *op);
extern int dump_body(struct req_state* s, const char* buf, size_t len);
extern int dump_body(struct req_state* s, /* const */ ceph::buffer::list& bl);
extern int dump_body(struct req_state* s, const std::string& str);
extern int recv_body(struct req_state* s, char* buf, size_t max);
#endif /* CEPH_RGW_REST_H */

View File

@ -2542,23 +2542,24 @@ void RGWCompleteMultipart_ObjStore_S3::send_response()
dump_errno(s);
dump_header_if_nonempty(s, "x-amz-version-id", version_id);
end_header(s, this, "application/xml");
if (op_ret == 0) {
if (op_ret == 0) {
dump_start(s);
s->formatter->open_object_section_in_ns("CompleteMultipartUploadResult", XMLNS_AWS_S3);
std::string base_uri = compute_domain_uri(s);
if (!s->bucket_tenant.empty()) {
if (s->info.domain.length()) {
s->formatter->dump_format("Location", "%s.%s.%s",
s->bucket_name.c_str(),
s->bucket_tenant.c_str(),
s->info.domain.c_str());
}
s->formatter->dump_format("Location", "%s/%s:%s/%s",
base_uri.c_str(),
s->bucket_tenant.c_str(),
s->bucket_name.c_str(),
s->object.name.c_str()
);
s->formatter->dump_string("Tenant", s->bucket_tenant);
} else {
if (s->info.domain.length()) {
s->formatter->dump_format("Location", "%s.%s",
s->bucket_name.c_str(),
s->info.domain.c_str());
}
s->formatter->dump_format("Location", "%s/%s/%s",
base_uri.c_str(),
s->bucket_name.c_str(),
s->object.name.c_str()
);
}
s->formatter->dump_string("Bucket", s->bucket_name);
s->formatter->dump_string("Key", s->object.name);