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

Move http data structs to a separate header.

Kishore Nallane066beb87077
diff --git a/TODO.md b/TODO.md
index 68428d37..e96edd40 100644
--- a/TODO.md
+++ b/TODO.md
@@ -47,7 +47,7 @@
- ~~List all collections~~
- ~~Fetch an individual document~~
- ~~ID field should be a string: must validate~~
-- Number of records in collection
+- ~~Number of records in collection~~
- Use rocksdb batch put for atomic insertion
- When prefix=true, use token_ranking_field for token ordering only for last word
- Query token ids should match query token ordering
diff --git a/include/http_data.h b/include/http_data.h
new file mode 100644
index 00000000..ba0ace4c
--- /dev/null
+++ b/include/http_data.h
@@ -0,0 +1,76 @@
+#pragma once
+#include <stdint.h>
+#include <string>
+#include <map>
+#include <vector>
+
+struct http_res {
+ uint32_t status_code;
+ std::string body;
+
+ void send_200(const std::string & res_body) {
+ status_code = 200;
+ body = res_body;
+ }
+
+ void send_201(const std::string & res_body) {
+ status_code = 201;
+ body = res_body;
+ }
+
+ void send_400(const std::string & message) {
+ status_code = 400;
+ body = "{\"message\": \"" + message + "\"}";
+ }
+
+ void send_401(const std::string & message) {
+ status_code = 400;
+ body = "{\"message\": \"" + message + "\"}";
+ }
+
+ void send_403() {
+ status_code = 403;
+ body = "{\"message\": \"Forbidden\"}";
+ }
+
+ void send_404() {
+ status_code = 404;
+ body = "{\"message\": \"Not Found\"}";
+ }
+
+ void send_409(const std::string & message) {
+ status_code = 409;
+ body = "{\"message\": \"" + message + "\"}";
+ }
+
+ void send_422(const std::string & message) {
+ status_code = 422;
+ body = "{\"message\": \"" + message + "\"}";
+ }
+
+ void send_500(const std::string & res_body) {
+ status_code = 500;
+ body = res_body;
+ }
+
+ void send(uint32_t code, const std::string & message) {
+ status_code = code;
+ body = "{\"message\": \"" + message + "\"}";
+ }
+};
+
+struct http_req {
+ std::map<std::string, std::string> params;
+ std::string body;
+};
+
+struct route_path {
+ std::string http_method;
+ std::vector<std::string> path_parts;
+ void (*handler)(http_req & req, http_res &);
+ bool authenticated;
+
+ inline bool operator< (const route_path& rhs) const {
+ return true;
+ }
+};
\ No newline at end of file
diff --git a/include/http_server.h b/include/http_server.h
index 0b0386a7..a916a982 100644
--- a/include/http_server.h
+++ b/include/http_server.h
@@ -11,80 +11,10 @@ extern "C" {
#include <map>
#include <string>
#include <stdio.h>
+#include "http_data.h"
#include "collection.h"
#include "collection_manager.h"
-struct http_res {
- uint32_t status_code;
- std::string body;
-
- void send_200(const std::string & res_body) {
- status_code = 200;
- body = res_body;
- }
-
- void send_201(const std::string & res_body) {
- status_code = 201;
- body = res_body;
- }
-
- void send_400(const std::string & message) {
- status_code = 400;
- body = "{\"message\": \"" + message + "\"}";
- }
-
- void send_401(const std::string & message) {
- status_code = 400;
- body = "{\"message\": \"" + message + "\"}";
- }
-
- void send_403() {
- status_code = 403;
- body = "{\"message\": \"Forbidden\"}";
- }
-
- void send_404() {
- status_code = 404;
- body = "{\"message\": \"Not Found\"}";
- }
-
- void send_409(const std::string & message) {
- status_code = 409;
- body = "{\"message\": \"" + message + "\"}";
- }
-
- void send_422(const std::string & message) {
- status_code = 422;
- body = "{\"message\": \"" + message + "\"}";
- }
-
- void send_500(const std::string & res_body) {
- status_code = 500;
- body = res_body;
- }
-
- void send(uint32_t code, const std::string & message) {
- status_code = code;
- body = "{\"message\": \"" + message + "\"}";
- }
-};
-
-struct http_req {
- std::map<std::string, std::string> params;
- std::string body;
-};
-
-struct route_path {
- std::string http_method;
- std::vector<std::string> path_parts;
- void (*handler)(http_req & req, http_res &);
- bool authenticated;
-
- inline bool operator< (const route_path& rhs) const {
- return true;
- }
-};
-
class HttpServer {
private:
static h2o_globalconf_t config;
diff --git a/src/http_server.cpp b/src/http_server.cpp
index 0487b118..d5af1a27 100644
--- a/src/http_server.cpp
+++ b/src/http_server.cpp
@@ -1,3 +1,4 @@
+#include "http_data.h"
#include "http_server.h"
#include "string_utils.h"
#include <regex>