Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Merge branch '0.18.0-patches' into 0.20.0-rc

kishorenc5dc7df793c87
diff --cc include/auth_manager.h
index d1e5c571,db199395..83b1a375
--- a/include/auth_manager.h
+++ b/include/auth_manager.h
@@@ -99,9 -95,10 +99,10 @@@ private
static std::string fmt_error(std::string&& error, const std::string& key);
Option<bool> authenticate_parse_params(const std::string& scoped_api_key, const std::string& action,
- const std::string& collection, nlohmann::json& embedded_params) const;
+ const std::vector<std::string>& collections,
- nlohmann::json& embedded_params) const;
++ nlohmann::json& embedded_params) const ;
- bool auth_against_key(const std::string &collection, const std::string& action,
+ bool auth_against_key(const std::vector<std::string>& collections, const std::string& action,
const api_key_t &api_key, const bool search_only) const;
public:
@@@ -121,8 -115,14 +122,8 @@@
Option<api_key_t> remove_key(uint32_t id);
- bool authenticate(const std::string& req_api_key, const std::string& action, const std::string& collection,
- std::map<std::string, std::string>& params) const;
- static const size_t KEY_LEN = 32;
- static const size_t HMAC_BASE64_LEN = 44;
-
- bool auth_against_key(const std::string &collection, const std::string& action,
- const api_key_t &api_key, const bool search_only) const;
-
+ bool authenticate(const std::string& req_api_key, const std::string& action,
+ const std::vector<std::string>& collections, std::map<std::string, std::string>& params) const;
static bool populate_req_params(std::map<std::string, std::string> &req_params,
nlohmann::detail::iteration_proxy_value<nlohmann::json::iterator>& item);
diff --cc include/collection_manager.h
index bae8906a,560af3b2..c2ff07e1
--- a/include/collection_manager.h
+++ b/include/collection_manager.h
@@@ -129,8 -68,12 +129,8 @@@ public
// frees in-memory data structures when server is shutdown - helps us run a memory leak detector properly
void dispose();
- Collection* init_collection(const nlohmann::json & collection_meta, const uint32_t collection_next_seq_id);
-
- void add_to_collections(Collection* collection);
-
bool auth_key_matches(const std::string& auth_key_sent, const std::string& action,
- const std::string& collection, std::map<std::string, std::string>& params) const;
+ const std::vector<std::string>& collections, std::map<std::string, std::string>& params) const;
Option<Collection*> create_collection(const std::string& name, const size_t num_memory_shards,
const std::vector<field> & fields,
diff --cc include/http_server.h
index 01ce190e,6534f80c..0f9d25ed
--- a/include/http_server.h
+++ b/include/http_server.h
@@@ -76,9 -75,7 +76,9 @@@ private
bool cors_enabled;
+ ThreadPool* thread_pool;
+
- bool (*auth_handler)(std::map<std::string, std::string>& params, const route_path& rpath,
+ bool (*auth_handler)(std::map<std::string, std::string>& params, const std::string& body, const route_path& rpath,
const std::string& auth_key);
static void on_accept(h2o_socket_t *listener, const char *err);
diff --cc src/auth_manager.cpp
index de338956,50b4b943..711341c8
--- a/src/auth_manager.cpp
+++ b/src/auth_manager.cpp
@@@ -139,10 -131,9 +139,10 @@@ uint32_t AuthManager::get_next_api_key_
}
bool AuthManager::authenticate(const std::string& req_api_key, const std::string& action,
- const std::string& collection, std::map<std::string, std::string>& params) const {
+ const std::vector<std::string>& collections,
+ std::map<std::string, std::string>& params) const {
+ std::shared_lock lock(mutex);
-
//LOG(INFO) << "AuthManager::authenticate()";
if(req_api_key.size() > KEY_LEN) {
diff --cc src/collection_manager.cpp
index 9a952f00,858f99db..c1c5f8cc
--- a/src/collection_manager.cpp
+++ b/src/collection_manager.cpp
@@@ -275,10 -263,8 +275,10 @@@ void CollectionManager::dispose()
bool CollectionManager::auth_key_matches(const std::string& auth_key_sent,
const std::string& action,
- const std::string& collection,
+ const std::vector<std::string>& collections,
std::map<std::string, std::string>& params) const {
+ std::shared_lock lock(mutex);
+
if(auth_key_sent.empty()) {
return false;
}
diff --cc src/core_api.cpp
index 56adb91a,30fb7703..93d140fa
--- a/src/core_api.cpp
+++ b/src/core_api.cpp
@@@ -444,10 -481,9 +466,9 @@@ bool post_import_documents(http_req& re
}
CollectionManager & collectionManager = CollectionManager::get_instance();
- Collection* collection = collectionManager.get_collection(req.params["collection"]);
+ auto collection = collectionManager.get_collection(req.params["collection"]);
if(collection == nullptr) {
- req.last_chunk_aggregate = true;
res.final = true;
res.set_404();
HttpServer::stream_response(req, res);
diff --cc src/http_server.cpp
index 4db5e12d,83a29d62..345df6e2
--- a/src/http_server.cpp
+++ b/src/http_server.cpp
@@@ -13,10 -13,9 +13,10 @@@
HttpServer::HttpServer(const std::string & version, const std::string & listen_address,
uint32_t listen_port, const std::string & ssl_cert_path,
- const std::string & ssl_cert_key_path, bool cors_enabled):
+ const std::string & ssl_cert_key_path, bool cors_enabled, ThreadPool* thread_pool):
- version(version), listen_address(listen_address), listen_port(listen_port),
+ exit_loop(false), version(version), listen_address(listen_address), listen_port(listen_port),
- ssl_cert_path(ssl_cert_path), ssl_cert_key_path(ssl_cert_key_path), cors_enabled(cors_enabled) {
+ ssl_cert_path(ssl_cert_path), ssl_cert_key_path(ssl_cert_key_path),
+ cors_enabled(cors_enabled), thread_pool(thread_pool) {
accept_ctx = new h2o_accept_ctx_t();
h2o_config_init(&config);
hostconf = h2o_config_register_host(&config, h2o_iovec_init(H2O_STRLIT("default")), 65535);