Skip to content

Commit

Permalink
Merge pull request #95 from coding-cpp/fix/63
Browse files Browse the repository at this point in the history
etag in res.sendFile
  • Loading branch information
Jadit19 authored Sep 12, 2024
2 parents 3997cac + 67515ab commit 27d3c45
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/expresso/helpers/response.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <brewtils/os.h>
#include <brewtils/sys.h>
#include <zippuccino/crc.h>

namespace expresso {

Expand All @@ -14,6 +15,8 @@ static const short CHUNK_SIZE = 1024;

std::string getAvailableFile(const std::string &path);

const std::string generateETag(const std::string &data);

bool sendChunkedData(const int &socket, const std::string &data);

bool sendFileInChunks(const int &socket, const std::string &path);
Expand Down
1 change: 1 addition & 0 deletions src/core/response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void expresso::core::Response::sendFile(const std::string &path, int64_t start,
this->set("content-type", brewtils::os::file::getMimeType(fileName));
this->set("content-disposition", "inline; filename=\"" + fileName + "\"");
this->set("accept-ranges", "bytes");
this->set("etag", expresso::helpers::generateETag(availableFile));

if (!isPartial) {
start = 0;
Expand Down
8 changes: 8 additions & 0 deletions src/helpers/response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ std::string expresso::helpers::getAvailableFile(const std::string &path) {
return "";
}

const std::string expresso::helpers::generateETag(const std::string &data) {
const std::string availableFile = expresso::helpers::getAvailableFile(data);
uint32_t crc = zippuccino::crc::compute(availableFile);
std::ostringstream etag;
etag << "\"" << std::hex << std::setw(8) << std::setfill('0') << crc << "\"";
return etag.str();
}

bool expresso::helpers::sendChunkedData(const int &socket,
const std::string &data) {
std::ostringstream dataSizeHex;
Expand Down

0 comments on commit 27d3c45

Please sign in to comment.