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.7 to main #485

Closed
wants to merge 3 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
4 changes: 3 additions & 1 deletion common/iovector.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ limitations under the License.
#include <photon/common/io-alloc.h>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
#if __GNUC__ >= 13
// #pragma GCC diagnostic ignored "-Wunknown-warning-option"
#pragma GCC diagnostic ignored "-Wzero-length-bounds"
#endif

inline bool operator == (const iovec& a, const iovec& b)
{
Expand Down
5 changes: 5 additions & 0 deletions common/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,12 @@ TEST(Callback, virtual_function)
Callback<int> dd(lambda);
// Callback<int> ee([&](int x){ return RET + x/2; });

#pragma GCC diagnostic push
#if __GNUC__ >= 13
#pragma GCC diagnostic ignored "-Wdangling-pointer"
#endif
THIS = (BB*)&c;
#pragma GCC diagnostic pop
LOG_DEBUG(VALUE(THIS), VALUE(&c));

for (int i=0; i<100; ++i)
Expand Down
5 changes: 3 additions & 2 deletions net/http/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,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 @@ -116,6 +116,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 @@ -136,6 +139,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
38 changes: 38 additions & 0 deletions net/http/test/client_function_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,44 @@ TEST(http_client, unix_socket) {
ASSERT_EQ(200, op2.resp.status_code());
}

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
4 changes: 3 additions & 1 deletion rpc/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,10 @@ namespace rpc {
return -1;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
#if __GNUC__ >= 13
// #pragma GCC diagnostic ignored "-Wunknown-warning-option"
#pragma GCC diagnostic ignored "-Wdangling-pointer"
#endif
ThreadLink node;
m_list.push_back(&node);
#pragma GCC diagnostic pop
Expand Down
2 changes: 1 addition & 1 deletion thread/thread11.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ namespace photon {

void asdf()
{
int a; char b;
int a = 0; char b = 0;
auto func = &__Example_of_Thread11__::member_function;
auto cfunc = &__Example_of_Thread11__::const_member_function;

Expand Down
Loading