mirror of https://github.com/kiwix/libkiwix.git
Remove the `RedirectResponse` and use a basic `Response` with header.
This commit is contained in:
parent
77123ac74c
commit
3352c95314
|
@ -511,7 +511,7 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
|
|||
/* If article found then redirect directly to it */
|
||||
if (!patternCorrespondingUrl.empty()) {
|
||||
auto redirectUrl = m_root + "/" + bookName + "/" + patternCorrespondingUrl;
|
||||
return RedirectionResponse::build(*this, redirectUrl);
|
||||
return Response::build_redirect(*this, redirectUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -743,7 +743,7 @@ std::unique_ptr<Response>
|
|||
InternalServer::build_redirect(const std::string& bookName, const kiwix::Entry& entry) const
|
||||
{
|
||||
auto redirectUrl = m_root + "/" + bookName + "/" + kiwix::urlEncode(entry.getPath());
|
||||
return RedirectionResponse::build(*this, redirectUrl);
|
||||
return Response::build_redirect(*this, redirectUrl);
|
||||
}
|
||||
|
||||
std::unique_ptr<Response> InternalServer::handle_content(const RequestContext& request)
|
||||
|
|
|
@ -103,7 +103,6 @@ class InternalServer {
|
|||
std::string m_server_id;
|
||||
|
||||
friend std::unique_ptr<Response> Response::build(const InternalServer& server);
|
||||
friend std::unique_ptr<Response> RedirectionResponse::build(const InternalServer& server, const std::string& redirectionUrl);
|
||||
friend std::unique_ptr<ContentResponse> ContentResponse::build(const InternalServer& server, const std::string& content, const std::string& mimetype);
|
||||
friend std::unique_ptr<Response> EntryResponse::build(const InternalServer& server, const RequestContext& request, const Entry& entry);
|
||||
friend std::unique_ptr<Response> Response::build_500(const InternalServer& server, const std::string& msg);
|
||||
|
|
|
@ -111,6 +111,15 @@ std::unique_ptr<Response> Response::build_500(const InternalServer& server, cons
|
|||
}
|
||||
|
||||
|
||||
std::unique_ptr<Response> Response::build_redirect(const InternalServer& server, const std::string& redirectUrl)
|
||||
{
|
||||
auto response = Response::build(server);
|
||||
response->m_returnCode = MHD_HTTP_FOUND;
|
||||
response->add_header(MHD_HTTP_HEADER_LOCATION, redirectUrl);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static MHD_Result print_key_value (void *cls, enum MHD_ValueKind kind,
|
||||
const char *key, const char *value)
|
||||
|
@ -221,7 +230,7 @@ ContentResponse::contentDecorationAllowed() const
|
|||
MHD_Response*
|
||||
Response::create_mhd_response(const RequestContext& request)
|
||||
{
|
||||
MHD_Response* response = MHD_create_response_from_buffer(0, NULL, MHD_RESPMEM_PERSISTENT);
|
||||
MHD_Response* response = MHD_create_response_from_buffer(0, nullptr, MHD_RESPMEM_PERSISTENT);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -303,27 +312,6 @@ void ContentResponse::set_taskbar(const std::string& bookName, const std::string
|
|||
}
|
||||
|
||||
|
||||
RedirectionResponse::RedirectionResponse(bool verbose, const std::string& redirectionUrl):
|
||||
Response(verbose),
|
||||
m_redirectionUrl(redirectionUrl)
|
||||
{
|
||||
m_returnCode = MHD_HTTP_FOUND;
|
||||
}
|
||||
|
||||
std::unique_ptr<Response> RedirectionResponse::build(const InternalServer& server, const std::string& redirectionUrl)
|
||||
{
|
||||
return std::unique_ptr<Response>(new RedirectionResponse(
|
||||
server.m_verbose.load(),
|
||||
redirectionUrl));
|
||||
}
|
||||
|
||||
MHD_Response* RedirectionResponse::create_mhd_response(const RequestContext& request)
|
||||
{
|
||||
MHD_Response* response = MHD_create_response_from_buffer(0, nullptr, MHD_RESPMEM_MUST_COPY);
|
||||
MHD_add_response_header(response, MHD_HTTP_HEADER_LOCATION, m_redirectionUrl.c_str());
|
||||
return response;
|
||||
}
|
||||
|
||||
ContentResponse::ContentResponse(const std::string& root, bool verbose, bool withTaskbar, bool withLibraryButton, bool blockExternalLinks, const std::string& content, const std::string& mimetype) :
|
||||
Response(verbose),
|
||||
m_root(root),
|
||||
|
|
|
@ -50,6 +50,7 @@ class Response {
|
|||
static std::unique_ptr<Response> build_404(const InternalServer& server, const RequestContext& request, const std::string& bookName);
|
||||
static std::unique_ptr<Response> build_416(const InternalServer& server, size_t resourceLength);
|
||||
static std::unique_ptr<Response> build_500(const InternalServer& server, const std::string& msg);
|
||||
static std::unique_ptr<Response> build_redirect(const InternalServer& server, const std::string& redirectUrl);
|
||||
|
||||
MHD_Result send(const RequestContext& request, MHD_Connection* connection);
|
||||
|
||||
|
@ -75,18 +76,6 @@ class Response {
|
|||
};
|
||||
|
||||
|
||||
class RedirectionResponse : public Response {
|
||||
public:
|
||||
RedirectionResponse(bool verbose, const std::string& redirectionUrl);
|
||||
static std::unique_ptr<Response> build(const InternalServer& server, const std::string& redirectionUrl);
|
||||
|
||||
|
||||
private:
|
||||
MHD_Response* create_mhd_response(const RequestContext& request);
|
||||
|
||||
std::string m_redirectionUrl;
|
||||
};
|
||||
|
||||
class ContentResponse : public Response {
|
||||
public:
|
||||
ContentResponse(const std::string& root, bool verbose, bool withTaskbar, bool withLibraryButton, bool blockExternalLinks, const std::string& content, const std::string& mimetype);
|
||||
|
|
Loading…
Reference in New Issue