Skip to content

Commit

Permalink
fixing hurl with accept-encoding header. (#51)
Browse files Browse the repository at this point in the history
* fixing hurl with accept-encoding header.

* fixing hurl with accept-encoding header.

* fixing hurl with accept-encoding header.
  • Loading branch information
tinselcity committed Dec 7, 2022
1 parent 473f13a commit ca23bcc
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 91 deletions.
31 changes: 15 additions & 16 deletions src/hurl/hurl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
return STATUS_ERROR;\
}\
} while(0)
#define _STRN_CASE_CMP(_a,_b) ((strncasecmp(_a, _b, strlen(_a)) == 0) && (strlen(_a) == strlen(_b)))
//! ----------------------------------------------------------------------------
//! types
//! ----------------------------------------------------------------------------
Expand Down Expand Up @@ -510,10 +511,10 @@ class request {
bool l_replace = false;
bool l_remove = false;
if (!strcasecmp(a_key.c_str(), "User-Agent") ||
!strcasecmp(a_key.c_str(), "Referer") ||
!strcasecmp(a_key.c_str(), "Accept") ||
!strcasecmp(a_key.c_str(), "X-Forwarded-For") ||
!strcasecmp(a_key.c_str(), "Host"))
!strcasecmp(a_key.c_str(), "Referer") ||
!strcasecmp(a_key.c_str(), "Accept") ||
!strcasecmp(a_key.c_str(), "X-Forwarded-For") ||
!strcasecmp(a_key.c_str(), "Host"))
{
l_replace = true;
if (a_val.empty())
Expand All @@ -528,7 +529,7 @@ class request {
ns_hurl::kv_map_list_t::iterator i_obj = m_headers.find(a_key);
if (i_obj != m_headers.end())
{
// Special handling for Host/User-agent/referer
// Special handling for Host/User-agent/Referer
if (l_replace)
{
i_obj->second.clear();
Expand Down Expand Up @@ -1170,7 +1171,6 @@ int32_t http_session::srequest(void)
}
ns_hurl::kv_map_list_t::const_iterator i_hdr;
bool l_specd_host = false;
#define STRN_CASE_CMP(_a,_b) (strncasecmp(_a, _b, strlen(_a)) == 0)
#define SET_IF_V1(_key) do { \
i_hdr = m_request->m_headers.find(_key);\
if (i_hdr != m_request->m_headers.end()) { \
Expand All @@ -1193,9 +1193,9 @@ if (i_hdr != m_request->m_headers.end()) { \
i_hl != m_request->m_headers.end();
++i_hl)
{
if (STRN_CASE_CMP("host", i_hl->first.c_str()) ||
STRN_CASE_CMP("accept", i_hl->first.c_str()) ||
STRN_CASE_CMP("user-agent", i_hl->first.c_str()))
if (_STRN_CASE_CMP("host", i_hl->first.c_str()) ||
_STRN_CASE_CMP("accept", i_hl->first.c_str()) ||
_STRN_CASE_CMP("user-agent", i_hl->first.c_str()))
{
continue;
}
Expand Down Expand Up @@ -1847,30 +1847,29 @@ int32_t h2_session::srequest(void)
// -----------------------------------------
// std headers
// -----------------------------------------
#define SET_IF(_key) do { \
#define _SET_IF(_key) do { \
i_hdr = m_request->m_headers.find(_key);\
if (i_hdr != m_request->m_headers.end()) { \
SET_HEADER(l_hdr_idx, i_hdr->first, i_hdr->second.front()); \
++l_hdr_idx;\
}\
} while(0)
SET_IF("user-agent");
SET_IF("accept");
_SET_IF("user-agent");
_SET_IF("accept");
// -----------------------------------------
// the rest...
// -----------------------------------------
for(i_hdr = m_request->m_headers.begin();
i_hdr != m_request->m_headers.end();
++i_hdr)
{
#define STRN_CASE_CMP(_a,_b) (strncasecmp(_a, _b, strlen(_a)) == 0)
if (STRN_CASE_CMP("accept", i_hdr->first.c_str()) ||
STRN_CASE_CMP("user-agent", i_hdr->first.c_str()))
if (_STRN_CASE_CMP("accept", i_hdr->first.c_str()) ||
_STRN_CASE_CMP("user-agent", i_hdr->first.c_str()))
{
continue;
}
if (!m_request->m_no_host &&
STRN_CASE_CMP("host", i_hdr->first.c_str()))
_STRN_CASE_CMP("host", i_hdr->first.c_str()))
{
continue;
}
Expand Down
23 changes: 21 additions & 2 deletions tests/whitebox/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
# ------------------------------------------------------------------------------
# includes
# ------------------------------------------------------------------------------
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/core
${CMAKE_SOURCE_DIR}/ext
)
# ------------------------------------------------------------------------------
# build catch
# ------------------------------------------------------------------------------
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ../../ext/)
add_library(compiled_catch STATIC ${CMAKE_CURRENT_SOURCE_DIR}/../../ext/catch/catch.hpp _catch.cc)
add_library(compiled_catch STATIC ${CMAKE_SOURCE_DIR}/ext/catch/catch.hpp _catch.cc)
# ------------------------------------------------------------------------------
# macros
# ------------------------------------------------------------------------------
macro (add_hurl_wb_test test_name)
add_executable("wb_${test_name}" "wb_${test_name}.cc")
target_link_libraries("wb_${test_name}"
${DEBUG_LIBRARIES}
compiled_catch
${CMAKE_BINARY_DIR}/src/core/libhurlcore.a
${LIBRARIES})
add_test(${test_name} "wb_${test_name}")
endmacro()
# ------------------------------------------------------------------------------
# fix for error
# ...
Expand Down
30 changes: 2 additions & 28 deletions tests/whitebox/dns/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,2 @@
# ------------------------------------------------------------------------------
# wb_ai_cache
# ------------------------------------------------------------------------------
SET(SRCS wb_ai_cache.cc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/core)
add_executable(wb_ai_cache ${HDRS} ${SRCS})
target_link_libraries(wb_ai_cache
compiled_catch
${DEBUG_LIBRARIES}
${CMAKE_BINARY_DIR}/src/core/libhurlcore.a
${LIBRARIES}
)
SET_TARGET_PROPERTIES(wb_ai_cache PROPERTIES OUTPUT_NAME "wb_ai_cache")
add_test(ai_cache wb_ai_cache)
# ------------------------------------------------------------------------------
# wb_nresolver
# ------------------------------------------------------------------------------
SET(SRCS wb_nresolver.cc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/core)
add_executable(wb_nresolver ${HDRS} ${SRCS})
target_link_libraries(wb_nresolver
compiled_catch
${DEBUG_LIBRARIES}
${CMAKE_BINARY_DIR}/src/core/libhurlcore.a
${LIBRARIES}
)
SET_TARGET_PROPERTIES(wb_nresolver PROPERTIES OUTPUT_NAME "wb_nresolver")
add_test(nresolver wb_nresolver)
add_hurl_wb_test(ai_cache)
add_hurl_wb_test(nresolver)
20 changes: 2 additions & 18 deletions tests/whitebox/nconn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,2 @@
# ------------------------------------------------------------------------------
# wb_nconn_tcp
# ------------------------------------------------------------------------------
SET(SRCS wb_nconn_tcp.cc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/core)
add_executable(wb_nconn_tcp ${HDRS} ${SRCS})
target_link_libraries(wb_nconn_tcp compiled_catch ${DEBUG_LIBRARIES} ${CMAKE_BINARY_DIR}/src/core/libhurlcore.a ${LIBRARIES})
SET_TARGET_PROPERTIES(wb_nconn_tcp PROPERTIES OUTPUT_NAME "wb_nconn_tcp")
add_test(nconn_tcp wb_nconn_tcp)
# ------------------------------------------------------------------------------
# wb_nconn_tls
# ------------------------------------------------------------------------------
SET(SRCS wb_nconn_tls.cc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/core)
add_executable(wb_nconn_tls ${HDRS} ${SRCS})
target_link_libraries(wb_nconn_tls compiled_catch ${DEBUG_LIBRARIES} ${CMAKE_BINARY_DIR}/src/core/libhurlcore.a ${LIBRARIES})
SET_TARGET_PROPERTIES(wb_nconn_tls PROPERTIES OUTPUT_NAME "wb_nconn_tls")
add_test(nconn_tls wb_nconn_tls)
add_hurl_wb_test(nconn_tcp)
add_hurl_wb_test(nconn_tls)
31 changes: 4 additions & 27 deletions tests/whitebox/support/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
# ------------------------------------------------------------------------------
# wb_nbq
# ------------------------------------------------------------------------------
SET(SRCS wb_nbq.cc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/core)
add_executable(wb_nbq ${HDRS} ${SRCS})
target_link_libraries(wb_nbq compiled_catch ${DEBUG_LIBRARIES} ${CMAKE_BINARY_DIR}/src/core/libhurlcore.a ${LIBRARIES})
SET_TARGET_PROPERTIES(wb_nbq PROPERTIES OUTPUT_NAME "wb_nbq")
add_test(nbq wb_nbq)
# ------------------------------------------------------------------------------
# wb_obj_pool
# ------------------------------------------------------------------------------
SET(SRCS wb_obj_pool.cc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/core)
add_executable(wb_obj_pool ${HDRS} ${SRCS})
target_link_libraries(wb_obj_pool compiled_catch ${DEBUG_LIBRARIES} ${CMAKE_BINARY_DIR}/src/core/libhurlcore.a ${LIBRARIES})
SET_TARGET_PROPERTIES(wb_obj_pool PROPERTIES OUTPUT_NAME "wb_obj_pool")
add_test(obj_pool wb_obj_pool)
# ------------------------------------------------------------------------------
# wb_nlru
# ------------------------------------------------------------------------------
SET(SRCS wb_nlru.cc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/core)
add_executable(wb_nlru ${HDRS} ${SRCS})
target_link_libraries(wb_nlru compiled_catch ${DEBUG_LIBRARIES} ${CMAKE_BINARY_DIR}/src/core/libhurlcore.a ${LIBRARIES})
SET_TARGET_PROPERTIES(wb_nlru PROPERTIES OUTPUT_NAME "wb_nlru")
add_test(nlru wb_nlru)
add_hurl_wb_test(nbq)
add_hurl_wb_test(obj_pool)
add_hurl_wb_test(nlru)
add_hurl_wb_test(kv_map)
62 changes: 62 additions & 0 deletions tests/whitebox/support/wb_kv_map.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//! ----------------------------------------------------------------------------
//! Copyright Edgio Inc.
//!
//! \file: TODO
//! \details: TODO
//!
//! Licensed under the terms of the Apache 2.0 open source license.
//! Please refer to the LICENSE file in the project root for the terms.
//! ----------------------------------------------------------------------------
//! ----------------------------------------------------------------------------
//! includes
//! ----------------------------------------------------------------------------
#include "status.h"
#include "support/ndebug.h"
#include "support/kv_map_list.h"
#include "catch/catch.hpp"
//! ----------------------------------------------------------------------------
//! append
//! ----------------------------------------------------------------------------
static inline void _append(ns_hurl::kv_map_list_t& a_map,
const std::string& a_key,
const std::string& a_val)
{
ns_hurl::kv_map_list_t::iterator i_obj = a_map.find(a_key);
if (i_obj != a_map.end())
{
i_obj->second.push_back(a_val);
return;
}
ns_hurl::str_list_t l_list;
l_list.push_back(a_val);
a_map[a_key] = l_list;
return;
}
//! ----------------------------------------------------------------------------
//! append
//! ----------------------------------------------------------------------------
static inline void _show(ns_hurl::kv_map_list_t& a_map)
{
for(auto && i_k : a_map)
{
NDBG_OUTPUT("%s: ", i_k.first.c_str());
for(auto && i_v : i_k.second)
{
NDBG_OUTPUT("%s ", i_v.c_str());
}
NDBG_OUTPUT("\n");
}
}
//! ----------------------------------------------------------------------------
//! Tests
//! ----------------------------------------------------------------------------
TEST_CASE( "kv_map test", "[kv_map]" ) {
SECTION("basic test") {
ns_hurl::kv_map_list_t l_kvml;
NDBG_PRINT("APPEND\n");
_append(l_kvml, "TEST", "TEST");
NDBG_PRINT("APPEND\n");
_append(l_kvml, "TEST-TEST", "TEST");
REQUIRE((l_kvml.size() == 2));
}
}

0 comments on commit ca23bcc

Please sign in to comment.