Skip to content

Commit

Permalink
Add filename header to response
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Dec 15, 2024
1 parent 80f0e55 commit 47a6824
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion wpinet/src/main/native/cpp/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
#include <fmt/format.h>
#include <wpi/DenseMap.h>
#include <wpi/MemoryBuffer.h>
#include <wpi/SmallString.h>
#include <wpi/Signal.h>
#include <wpi/StringMap.h>
#include <wpi/fs.h>
#include <wpi/json.h>
#include <wpi/print.h>
#include <wpi/raw_ostream.h>

#include "wpinet/EventLoopRunner.h"
#include "wpinet/HttpServerConnection.h"
Expand Down Expand Up @@ -322,8 +324,13 @@ void MyHttpConnection::ProcessRequest() {
SendResponse(200, "OK", "text/html", html);
}
} else {
wpi::SmallString<128> extraHeadersBuf;
wpi::raw_svector_ostream os{extraHeadersBuf};
os << "Content-Disposition: filename=\"";
os.write_escaped(fullpath.filename().string());
os << "\"\r\n";
SendFileResponse(200, "OK", GetMimeType(wpi::rsplit(path, '.').second),
fullpath);
fullpath, os.str());
}
} else {
SendError(404, "Resource not found");
Expand Down

0 comments on commit 47a6824

Please sign in to comment.