Common: Rename Download to Request, and the old Request to ServerRequest.

This commit is contained in:
Henrik Rydgård committed 2023-07-21 22:12:00 +02:00
1 parent d4c0d1da64
commit 93bb113009
20 files changed
+97 -99

No files matched your search

+11 -11
View File
@@ -60,7 +60,7 @@ namespace http {
// Note: charset here helps prevent XSS.
const char *const DEFAULT_MIME_TYPE = "text/html; charset=utf-8";
Request::Request(int fd)
ServerRequest::ServerRequest(int fd)
: fd_(fd) {
in_ = new net::InputSink(fd);
out_ = new net::OutputSink(fd);
@@ -73,7 +73,7 @@ Request::Request(int fd)
}
}
Request::~Request() {
ServerRequest::~ServerRequest() {
Close();
if (!in_->Empty()) {
@@ -86,7 +86,7 @@ Request::~Request() {
delete out_;
}
void Request::WriteHttpResponseHeader(const char *ver, int status, int64_t size, const char *mimeType, const char *otherHeaders) const {
void ServerRequest::WriteHttpResponseHeader(const char *ver, int status, int64_t size, const char *mimeType, const char *otherHeaders) const {
const char *statusStr;
switch (status) {
case 200: statusStr = "OK"; break;
@@ -123,18 +123,18 @@ void Request::WriteHttpResponseHeader(const char *ver, int status, int64_t size,
buffer->Push("\r\n");
}
void Request::WritePartial() const {
void ServerRequest::WritePartial() const {
_assert_(fd_);
out_->Flush();
}
void Request::Write() {
void ServerRequest::Write() {
_assert_(fd_);
WritePartial();
Close();
}
void Request::Close() {
void ServerRequest::Close() {
if (fd_) {
closesocket(fd_);
fd_ = 0;
@@ -317,7 +317,7 @@ void Server::Stop() {
}
void Server::HandleConnection(int conn_fd) {
Request request(conn_fd);
ServerRequest request(conn_fd);
if (!request.IsOK()) {
WARN_LOG(IO, "Bad request, ignoring.");
return;
@@ -331,11 +331,11 @@ void Server::HandleConnection(int conn_fd) {
request.Write();
}
void Server::HandleRequest(const Request &request) {
void Server::HandleRequest(const ServerRequest &request) {
HandleRequestDefault(request);
}
void Server::HandleRequestDefault(const Request &request) {
void Server::HandleRequestDefault(const ServerRequest &request) {
if (request.resource() == nullptr) {
fallback_(request);
return;
@@ -350,14 +350,14 @@ void Server::HandleRequestDefault(const Request &request) {
}
}
void Server::Handle404(const Request &request) {
void Server::Handle404(const ServerRequest &request) {
INFO_LOG(IO, "No handler for '%s', falling back to 404.", request.resource());
const char *payload = "<html><body>404 not found</body></html>\r\n";
request.WriteHttpResponseHeader("1.0", 404, (int)strlen(payload));
request.Out()->Push(payload);
}
void Server::HandleListing(const Request &request) {
void Server::HandleListing(const ServerRequest &request) {
request.WriteHttpResponseHeader("1.0", 200, -1, "text/plain");
for (auto iter = handlers_.begin(); iter != handlers_.end(); ++iter) {
request.Out()->Printf("%s\n", iter->first.c_str());