mirror of https://github.com/kiwix/libkiwix.git
added code for status code 204 for empty return of search.
This commit is contained in:
parent
1884081ebe
commit
599aaa4c1b
|
@ -740,6 +740,13 @@ Response InternalServer::handle_search(const RequestContext& request)
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << e.what() << std::endl;
|
std::cerr << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//changing status code if no result obtained
|
||||||
|
if(searcher.getEstimatedResultCount() == 0)
|
||||||
|
{
|
||||||
|
response.set_code(MHD_HTTP_NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -155,7 +155,7 @@ const ResourceCollection resources200Compressible{
|
||||||
{ NO_ETAG, "/catalog/searchdescription.xml" },
|
{ NO_ETAG, "/catalog/searchdescription.xml" },
|
||||||
{ NO_ETAG, "/catalog/search" },
|
{ NO_ETAG, "/catalog/search" },
|
||||||
|
|
||||||
{ NO_ETAG, "/search?content=zimfile&pattern=abcd" },
|
{ NO_ETAG, "/search?content=zimfile&pattern=a" },
|
||||||
|
|
||||||
{ NO_ETAG, "/suggest?content=zimfile&term=ray" },
|
{ NO_ETAG, "/suggest?content=zimfile&term=ray" },
|
||||||
|
|
||||||
|
@ -197,6 +197,15 @@ TEST_F(ServerTest, 200)
|
||||||
EXPECT_EQ(200, zfs1_->GET(res.url)->status) << "res.url: " << res.url;
|
EXPECT_EQ(200, zfs1_->GET(res.url)->status) << "res.url: " << res.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// seperate test for 204 code
|
||||||
|
|
||||||
|
TEST_F(ServerTest, EmptySearchReturnsA204StatusCode)
|
||||||
|
{
|
||||||
|
const char* url="/search?content=zimfile&pattern=abcd";
|
||||||
|
auto res=zfs1_->GET(url);
|
||||||
|
EXPECT_EQ(204, res->status) << "res.url: " << url;
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ServerTest, CompressibleContentIsCompressedIfAcceptable)
|
TEST_F(ServerTest, CompressibleContentIsCompressedIfAcceptable)
|
||||||
{
|
{
|
||||||
for ( const Resource& res : resources200Compressible ) {
|
for ( const Resource& res : resources200Compressible ) {
|
||||||
|
|
Loading…
Reference in New Issue