diff --git a/http_server/dap_http_simple.c b/http_server/dap_http_simple.c index edae106756b40931a8d64e8741380f2710589fe7..695f6c412b340cd6b107bf59a5dc7e89d64f84e6 100644 --- a/http_server/dap_http_simple.c +++ b/http_server/dap_http_simple.c @@ -72,7 +72,8 @@ typedef struct user_agents_item { struct user_agents_item* next; } user_agents_item_t; -user_agents_item_t *user_agents_list = NULL; +static user_agents_item_t *user_agents_list = NULL; +static bool is_unknown_user_agents_pass = false; #define DAP_HTTP_SIMPLE_URL_PROC(a) ((dap_http_simple_url_proc_t*) (a)->_inheritor) @@ -161,12 +162,12 @@ static void _free_user_agents_list() static bool _is_user_agent_supported(const char* user_agent) { - bool result = false; + bool result = is_unknown_user_agents_pass; dap_http_user_agent_ptr_t find_agent = dap_http_user_agent_new_from_str(user_agent); if(find_agent == NULL) { - return false; + return result; } const char* find_agent_name = dap_http_user_agent_get_name(find_agent); @@ -216,6 +217,13 @@ bool dap_http_simple_set_supported_user_agents(const char *user_agents, ...) return true; } +// if this function was called. We checking version only supported user-agents +// other will pass automatically ( and request with without user-agents field too ) +void dap_http_simple_set_pass_unknown_user_agents(bool pass) +{ + is_unknown_user_agents_pass = pass; +} + inline static bool _is_supported_user_agents_list_setted() { user_agents_item_t * tmp; @@ -277,7 +285,7 @@ void* dap_http_simple_proc(dap_http_simple_t * cl_sh) if(_is_supported_user_agents_list_setted() == true) { dap_http_header_t *header = dap_http_header_find(cl_sh->http->in_headers, "User-Agent"); - if(header == NULL) { + if(header == NULL && is_unknown_user_agents_pass == false) { const char* error_msg = "Not found User-Agent HTTP header"; _write_response_bad_request(cl_sh, error_msg); return NULL; diff --git a/http_server/dap_http_simple.h b/http_server/dap_http_simple.h index b73ac760be6fda64b938b1f0b91a3b7e1246958e..1082534588985ecf3bac3390a7e64b51f1162086 100644 --- a/http_server/dap_http_simple.h +++ b/http_server/dap_http_simple.h @@ -64,6 +64,12 @@ void dap_http_simple_module_deinit(void); // returns false if operation not successful bool dap_http_simple_set_supported_user_agents(const char *str_agents, ...); +// if this function was called. We checking version only supported user-agents +// other will pass automatically ( and request with without user-agents field too ) +// Affects the behavior of the internal function _is_user_agent_supported +void dap_http_simple_set_pass_unknown_user_agents(bool pass); + + size_t dap_http_simple_reply(dap_http_simple_t * shs, void * data, size_t data_size); size_t dap_http_simple_reply_f(dap_http_simple_t * shs, const char * data, ...);