Rework book example to support upload book photo.

This commit is contained in:
Chunting Gu
2019-09-05 10:53:39 +08:00
parent 4c413e245d
commit f1ad97b227
5 changed files with 271 additions and 163 deletions
+12
View File
@@ -43,6 +43,18 @@ ResponsePtr ResponseBuilder::operator()() {
return response;
}
ResponseBuilder& ResponseBuilder::File(const webcc::Path& path,
bool infer_media_type,
std::size_t chunk_size) {
body_.reset(new FileBody{ path, chunk_size });
if (infer_media_type) {
media_type_ = media_types::FromExtension(path.extension().string());
}
return *this;
}
ResponseBuilder& ResponseBuilder::Date() {
headers_.push_back(headers::kDate);
headers_.push_back(utility::GetTimestamp());
+5
View File
@@ -92,6 +92,11 @@ public:
return *this;
}
// Use the file content as body.
// NOTE: Error::kFileError might be thrown.
ResponseBuilder& File(const webcc::Path& path, bool infer_media_type = true,
std::size_t chunk_size = 1024);
ResponseBuilder& Header(const std::string& key, const std::string& value) {
headers_.push_back(key);
headers_.push_back(value);