Skip to content

added http code param to WebServer.streamFile (#6899) #6995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libraries/WebServer/src/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ void WebServer::sendContent_P(PGM_P content, size_t size) {
}


void WebServer::_streamFileCore(const size_t fileSize, const String & fileName, const String & contentType)
void WebServer::_streamFileCore(const size_t fileSize, const String & fileName, const String & contentType, const int code)
{
using namespace mime;
setContentLength(fileSize);
Expand All @@ -536,7 +536,7 @@ void WebServer::_streamFileCore(const size_t fileSize, const String & fileName,
contentType != String(FPSTR(mimeTable[none].mimeType))) {
sendHeader(F("Content-Encoding"), F("gzip"));
}
send(200, contentType, "");
send(code, contentType, "");
}

String WebServer::pathArg(unsigned int i) {
Expand Down
6 changes: 3 additions & 3 deletions libraries/WebServer/src/WebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ class WebServer
static String urlDecode(const String& text);

template<typename T>
size_t streamFile(T &file, const String& contentType) {
_streamFileCore(file.size(), file.name(), contentType);
size_t streamFile(T &file, const String& contentType, const int code = 200) {
_streamFileCore(file.size(), file.name(), contentType, code);
return _currentClient.write(file);
}

Expand All @@ -160,7 +160,7 @@ class WebServer
void _prepareHeader(String& response, int code, const char* content_type, size_t contentLength);
bool _collectHeader(const char* headerName, const char* headerValue);

void _streamFileCore(const size_t fileSize, const String & fileName, const String & contentType);
void _streamFileCore(const size_t fileSize, const String & fileName, const String & contentType, const int code = 200);

String _getRandomHexString();
// for extracting Auth parameters
Expand Down