Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto PR from release/0.6 to release/0.7 #506

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions .github/workflows/ci.linux.arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: [self-hosted, Linux, ARM64]

container:
image: dokken/centos-stream-8:sha-40294ce
image: ghcr.io/coldwings/photon-ut-base:latest
options: --cpus 4

steps:
Expand All @@ -23,14 +23,14 @@ jobs:

- uses: actions/checkout@v3

- name: Install Dependencies
run: |
dnf install -y git gcc-c++ cmake 'dnf-command(config-manager)'
dnf install -y gcc-toolset-9-gcc-c++
dnf install -y openssl-devel libcurl-devel libaio-devel
dnf install -y epel-release
dnf config-manager --set-enabled powertools
dnf install -y gtest-devel gmock-devel gflags-devel fuse-devel libgsasl-devel e2fsprogs-devel
# - name: Install Dependencies
# run: |
# dnf install -y git gcc-c++ cmake 'dnf-command(config-manager)'
# dnf install -y gcc-toolset-9-gcc-c++
# dnf install -y openssl-devel libcurl-devel libaio-devel
# dnf install -y epel-release
# dnf config-manager --set-enabled powertools
# dnf install -y gtest-devel gmock-devel gflags-devel fuse-devel libgsasl-devel e2fsprogs-devel

- name: Build
run: |
Expand All @@ -51,7 +51,7 @@ jobs:
runs-on: [self-hosted, Linux, ARM64]

container:
image: dokken/centos-stream-8:sha-40294ce
image: ghcr.io/coldwings/photon-ut-base:latest
options: --cpus 4

steps:
Expand All @@ -63,14 +63,14 @@ jobs:

- uses: actions/checkout@v3

- name: Install Dependencies
run: |
dnf install -y git gcc-c++ cmake 'dnf-command(config-manager)'
dnf install -y gcc-toolset-9-gcc-c++
dnf install -y openssl-devel libcurl-devel libaio-devel
dnf install -y epel-release
dnf config-manager --set-enabled powertools
dnf install -y gtest-devel gmock-devel gflags-devel fuse-devel libgsasl-devel e2fsprogs-devel
# - name: Install Dependencies
# run: |
# dnf install -y git gcc-c++ cmake 'dnf-command(config-manager)'
# dnf install -y gcc-toolset-9-gcc-c++
# dnf install -y openssl-devel libcurl-devel libaio-devel
# dnf install -y epel-release
# dnf config-manager --set-enabled powertools
# dnf install -y gtest-devel gmock-devel gflags-devel fuse-devel libgsasl-devel e2fsprogs-devel

- name: Build
run: |
Expand Down
52 changes: 26 additions & 26 deletions .github/workflows/ci.linux.x86.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: [self-hosted, Linux, X64]

container:
image: dokken/centos-stream-8:sha-40294ce
image: ghcr.io/coldwings/photon-ut-base:latest
options: --cpus 4

steps:
Expand All @@ -23,14 +23,14 @@ jobs:

- uses: actions/checkout@v3

- name: Install Dependencies
run: |
dnf install -y git gcc-c++ cmake 'dnf-command(config-manager)'
dnf install -y gcc-toolset-9-gcc-c++
dnf install -y openssl-devel libcurl-devel libaio-devel
dnf install -y epel-release
dnf config-manager --set-enabled powertools
dnf install -y gtest-devel gmock-devel gflags-devel fuse-devel libgsasl-devel e2fsprogs-devel
# - name: Install Dependencies
# run: |
# dnf install -y git gcc-c++ cmake 'dnf-command(config-manager)'
# dnf install -y gcc-toolset-9-gcc-c++
# dnf install -y openssl-devel libcurl-devel libaio-devel
# dnf install -y epel-release
# dnf config-manager --set-enabled powertools
# dnf install -y gtest-devel gmock-devel gflags-devel fuse-devel libgsasl-devel e2fsprogs-devel

- name: Build
run: |
Expand All @@ -51,7 +51,7 @@ jobs:
runs-on: [self-hosted, Linux, X64]

container:
image: dokken/centos-stream-8:sha-40294ce
image: ghcr.io/coldwings/photon-ut-base:latest
options: --cpus 4

steps:
Expand All @@ -63,14 +63,14 @@ jobs:

- uses: actions/checkout@v3

- name: Install Dependencies
run: |
dnf install -y git gcc-c++ cmake 'dnf-command(config-manager)'
dnf install -y gcc-toolset-9-gcc-c++
dnf install -y openssl-devel libcurl-devel libaio-devel
dnf install -y epel-release
dnf config-manager --set-enabled powertools
dnf install -y gtest-devel gmock-devel gflags-devel fuse-devel libgsasl-devel e2fsprogs-devel
# - name: Install Dependencies
# run: |
# dnf install -y git gcc-c++ cmake 'dnf-command(config-manager)'
# dnf install -y gcc-toolset-9-gcc-c++
# dnf install -y openssl-devel libcurl-devel libaio-devel
# dnf install -y epel-release
# dnf config-manager --set-enabled powertools
# dnf install -y gtest-devel gmock-devel gflags-devel fuse-devel libgsasl-devel e2fsprogs-devel

- name: Build
run: |
Expand All @@ -91,7 +91,7 @@ jobs:
runs-on: [self-hosted, Linux, X64]

container:
image: dokken/centos-stream-8:sha-40294ce
image: ghcr.io/coldwings/photon-ut-base:latest
# In order to run io_uring, the docker daemon should add --default-ulimit memlock=-1:-1
options: --cpus 4

Expand All @@ -104,13 +104,13 @@ jobs:

- uses: actions/checkout@v3

- name: Install Dependencies
run: |
dnf install -y git gcc-c++ cmake
dnf install -y gcc-toolset-9-gcc-c++
dnf install -y openssl-devel libcurl-devel
dnf install -y epel-release
dnf install -y fuse-devel libgsasl-devel e2fsprogs-devel
# - name: Install Dependencies
# run: |
# dnf install -y git gcc-c++ cmake
# dnf install -y gcc-toolset-9-gcc-c++
# dnf install -y openssl-devel libcurl-devel
# dnf install -y epel-release
# dnf install -y fuse-devel libgsasl-devel e2fsprogs-devel

- name: Build
run: |
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/ci.macos.arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ on:

jobs:
macOS-clang-debug:
runs-on: [self-hosted, macOS, ARM64]
runs-on: macos-14

steps:
# - uses: szenius/[email protected]
# with:
# timezoneLinux: "Asia/Shanghai"
# timezoneMacos: "Asia/Shanghai"
# timezoneWindows: "China Standard Time"
- uses: szenius/[email protected]
with:
timezoneLinux: "Asia/Shanghai"
timezoneMacos: "Asia/Shanghai"
timezoneWindows: "China Standard Time"

- uses: actions/checkout@v3

Expand Down
28 changes: 8 additions & 20 deletions common/lockfree_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class LockfreeMPMCRingQueue : public LockfreeRingQueueBase<T, N> {
using Base::empty;
using Base::full;

bool push_weak(const T& x) {
bool push(const T& x) {
auto t = tail.load(std::memory_order_acquire);
for (;;) {
auto& slot = slots[idx(t)];
Expand All @@ -192,15 +192,16 @@ class LockfreeMPMCRingQueue : public LockfreeRingQueueBase<T, N> {
}
} else {
auto const prevTail = t;
auto h = head.load(std::memory_order_acquire);
t = tail.load(std::memory_order_acquire);
if (t == prevTail) {
if (t == prevTail && Base::check_full(h, t)) {
return false;
}
}
}
}

bool pop_weak(T& x) {
bool pop(T& x) {
auto h = head.load(std::memory_order_acquire);
for (;;) {
auto& slot = slots[idx(h)];
Expand All @@ -213,28 +214,15 @@ class LockfreeMPMCRingQueue : public LockfreeRingQueueBase<T, N> {
}
} else {
auto const prevHead = h;
auto t = tail.load(std::memory_order_acquire);
h = head.load(std::memory_order_acquire);
if (h == prevHead) {
if (h == prevHead && Base::check_empty(h, t)) {
return false;
}
}
}
}

bool push(const T& x) {
do {
if (push_weak(x)) return true;
} while (!full());
return false;
}

bool pop(T& x) {
do {
if (pop_weak(x)) return true;
} while (!empty());
return false;
}

template <typename Pause = ThreadPause>
void send(const T& x) {
static_assert(std::is_base_of<PauseBase, Pause>::value,
Expand Down Expand Up @@ -536,8 +524,8 @@ namespace common {
* and load balancing.
* Watch out that `recv` should run in photon environment (because it has to)
* use photon semaphore to be notified that new item has sended. `send` could
* running in photon or std::thread environment (needs to set template `Pause` as
* `ThreadPause`).
* running in photon or std::thread environment (needs to set template `Pause`
* as `ThreadPause`).
*
* @tparam QueueType shoulde be one of LockfreeMPMCRingQueue,
* LockfreeBatchMPMCRingQueue, or LockfreeSPSCRingQueue, with their own template
Expand Down
5 changes: 3 additions & 2 deletions net/http/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,10 @@ class ClientImpl : public Client {
LOG_ERROR_RETURN(EINVAL, ROUNDTRIP_FAILED,
"Content-Length and Transfer-Encoding conflicted");
}
op->req.headers.insert("User-Agent", USERAGENT);
op->req.headers.insert("Connection", "keep-alive");
op->req.headers.merge(m_common_headers);
op->req.headers.insert("User-Agent", m_user_agent.empty() ? std::string_view(USERAGENT)
: std::string_view(m_user_agent));
op->req.headers.insert("Connection", "keep-alive");
if (m_cookie_jar && m_cookie_jar->set_cookies_to_headers(&op->req) != 0)
LOG_ERROR_RETURN(0, -1, "set_cookies_to_headers failed");
Timeout tmo(std::min(op->timeout.timeout(), m_timeout));
Expand Down
4 changes: 4 additions & 0 deletions net/http/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class Client : public Object {
m_proxy_url.from_string(proxy);
m_proxy = true;
}
void set_user_agent(std::string_view user_agent) {
m_user_agent = std::string(user_agent);
}
StoredURL* get_proxy() {
return &m_proxy_url;
}
Expand All @@ -129,6 +132,7 @@ class Client : public Object {
bool secure = false, uint64_t timeout = -1UL) = 0;
protected:
StoredURL m_proxy_url;
std::string m_user_agent;
uint64_t m_timeout = -1UL;
bool m_proxy = false;
};
Expand Down
40 changes: 40 additions & 0 deletions net/http/test/client_function_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,46 @@ TEST(http_client, partial_body) {
EXPECT_EQ(true, buf == "http_clien");
}

int ua_check_handler(void*, Request &req, Response &resp, std::string_view) {
auto ua = req.headers["User-Agent"];
LOG_DEBUG(VALUE(ua));
EXPECT_EQ(ua, "TEST_UA");
resp.set_result(200);
std::string str = "success";
resp.headers.content_length(7);
resp.write((void*)str.data(), str.size());
return 0;
}


TEST(http_client, user_agent) {
auto tcpserver = new_tcp_socket_server();
DEFER(delete tcpserver);
tcpserver->bind(18731);
tcpserver->listen();
auto server = new_http_server();
DEFER(delete server);
server->add_handler({nullptr, &ua_check_handler});
tcpserver->set_handler(server->get_connection_handler());
tcpserver->start_loop();

std::string target_get = "http://localhost:18731/file";
auto client = new_http_client();
client->set_user_agent("TEST_UA");
DEFER(delete client);
auto op = client->new_operation(Verb::GET, target_get);
DEFER(delete op);
op->req.headers.content_length(0);
client->call(op);
EXPECT_EQ(op->status_code, 200);
std::string buf;
buf.resize(op->resp.headers.content_length());
op->resp.read((void*)buf.data(), op->resp.headers.content_length());
LOG_DEBUG(VALUE(buf));
EXPECT_EQ(true, buf == "success");
}


TEST(url, url_escape_unescape) {
EXPECT_EQ(
url_escape("?a=x:b&b=cd&c= feg&d=2/1[+]@alibaba.com&e='!bad';"),
Expand Down
Loading