Commit dc31d3c1 authored by Sophie Wenzel-Teuber's avatar Sophie Wenzel-Teuber
Browse files

Update the server to work with Estuary copytool

Changelog:
* Add content_length to phobos metadata
* Send the content_length from phobos metadata as header Content-Length
* Add all Phobos Metadata (formerly retrieved only by a HEAD request) as headers to the response to a GET request
parent e9afd4a8
Pipeline #1726 passed with stages
in 7 minutes and 28 seconds
......@@ -48,6 +48,9 @@ void GetRequestHandler::onRequest(
}
#endif
std::map<std::string, std::string> meta_data;
std::string content_length;
try {
/* Send meta data to backend through the stream */
......@@ -55,8 +58,8 @@ void GetRequestHandler::onRequest(
// m_s3_header.get_meta_data(), m_s3_header.get_bucket());
// Check if metadata for file exists
std::map<std::string, std::string> meta_data =
m_stream->get_meta_data(m_s3_header.get_key());
meta_data = m_stream->get_meta_data(m_s3_header.get_key());
content_length = meta_data["content_length"];
/* Tell stream to coordinate with backend to prepare for GET operation
*/
......@@ -86,7 +89,18 @@ void GetRequestHandler::onRequest(
return;
}
proxygen::ResponseBuilder(downstream_).status(200, "Ok").send();
proxygen::ResponseBuilder response(downstream_);
response.status(200, "OK");
response.header("Content-Length", content_length);
std::for_each(
meta_data.begin(), meta_data.end(),
[&](std::pair<std::string, std::string> pair) {
if (pair.first != "creation_time" && pair.first != "bucket"
&& pair.first != "content_length") {
response.header("x-amz-meta-" + pair.first, pair.second);
}
});
response.send();
/* Initiating a read from the stream and creating a body to send */
m_read_file_scheduled = true;
......
......@@ -56,10 +56,13 @@ void PutRequestHandler::onRequest(
}
try {
/*
* Add timestamp to meta data and send it to backend through the stream
* Add timestamp and content length to meta data and send it to backend
* through the stream
*/
auto metadata = m_s3_header.get_meta_data();
metadata["creation_time"] = std::to_string(std::time(nullptr));
metadata["content_length"] =
std::to_string(m_s3_header.get_body_length());
m_stream->set_storage_meta_data(metadata, m_s3_header.get_bucket());
/*
......
......@@ -66,6 +66,7 @@ class Server_test_case(unittest.TestCase):
key,
meta_data=put_meta_data)
put_meta_data['content_length'] = '20662'
get_meta_data = self.client.get_md(self.bucket_name, key)
self.assertTrue(put_meta_data == get_meta_data)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment