bool FilesystemHttpHandler::Handle( HttpOutput& output, RequestOrigin /*origin*/, const char* /*remoteIp*/, const char* /*username*/, HttpMethod method, const UriComponents& uri, const Arguments& headers, const GetArguments& arguments, const char* /*bodyData*/, size_t /*bodySize*/) { if (!Toolbox::IsChildUri(pimpl_->baseUri_, uri)) { // This URI is not served by this handler return false; } if (method != HttpMethod_Get) { output.SendMethodNotAllowed("GET"); return true; } namespace fs = boost::filesystem; fs::path p = pimpl_->root_; for (size_t i = pimpl_->baseUri_.size(); i < uri.size(); i++) { p /= uri[i]; } if (fs::exists(p) && fs::is_regular_file(p)) { FilesystemHttpSender sender(p); output.Answer(sender); // TODO COMPRESSION } else if (listDirectoryContent_ && fs::exists(p) && fs::is_directory(p)) { OutputDirectoryContent(output, headers, uri, p); } else { output.SendStatus(HttpStatus_404_NotFound); } return true; }
bool FilesystemHttpHandler::Handle( HttpOutput& output, HttpMethod method, const UriComponents& uri, const Arguments& headers, const GetArguments& arguments, const std::string&) { if (!Toolbox::IsChildUri(pimpl_->baseUri_, uri)) { // This URI is not served by this handler return false; } if (method != HttpMethod_Get) { output.SendMethodNotAllowed("GET"); return true; } namespace fs = boost::filesystem; fs::path p = pimpl_->root_; for (size_t i = pimpl_->baseUri_.size(); i < uri.size(); i++) { p /= uri[i]; } if (fs::exists(p) && fs::is_regular_file(p)) { FilesystemHttpSender(p).Send(output); //output.AnswerFileAutodetectContentType(p.string()); } else if (listDirectoryContent_ && fs::exists(p) && fs::is_directory(p)) { OutputDirectoryContent(output, uri, p); } else { output.SendStatus(HttpStatus_404_NotFound); } return true; }