Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3715b90

Browse files
Luca Niccolinimeta-codesync[bot]
Luca Niccolini
authored andcommitted
Add custom header support to H3DatagramClient
Summary: The H3DatagramClient sample binary hardcodes its HTTP request with no way to pass custom headers. This is needed for use with Meta's forward proxy, which requires X-FB-Proxy, X-FB-ProxyScheme, and X-FB-ProxyType headers. This change adds a --headers gflag that accepts comma-separated Name=Value pairs, reusing the existing CurlClient::parseHeaders() utility already used by the curl and hq samples.Reviewed By: jalopezsilvaDifferential Revision: D93680181fbshipit-source-id: 7f1600646e3d2bae638bddea049919f69964099e
1 parentbd79c0b commit3715b90

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

‎proxygen/httpclient/samples/H3Datagram/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ target_link_libraries(
1313
proxygen_h3datagram_client
1414
PUBLIC
1515
proxygen
16+
proxygencurl
1617
)
1718
install(
1819
TARGETS proxygen_h3datagram_client

‎proxygen/httpclient/samples/H3Datagram/H3DatagramClient.cpp‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include<folly/init/Init.h>
1111
#include<folly/io/async/EventBase.h>
1212
#include<folly/portability/GFlags.h>
13+
#include<proxygen/httpclient/samples/curl/CurlClient.h>
1314
#include<proxygen/httpserver/samples/hq/InsecureVerifierDangerousDoNotUseInProduction.h>
1415
#include<proxygen/lib/transport/H3DatagramAsyncSocket.h>
1516

@@ -25,6 +26,8 @@ DEFINE_int32(proxy_port, 6666, "Proxy port");
2526
DEFINE_string(cert,"","Certificate file path");
2627
DEFINE_string(key,"","Private key file path");
2728

29+
DEFINE_string(headers,"","List of N=V headers separated by ,");
30+
2831
constexprsize_tkMaxReadBufferSize{1232};
2932

3033
namespace {
@@ -55,7 +58,13 @@ class DatagramClient
5558

5659
voidstart() {
5760
CHECK(evb_->isInEventBaseThread());
58-
socket_.connect(SocketAddress(FLAGS_proxy_host, FLAGS_proxy_port));
61+
try {
62+
socket_.connect(SocketAddress(FLAGS_proxy_host, FLAGS_proxy_port));
63+
}catch (const std::system_error& e) {
64+
LOG(ERROR) <<"Failed to connect to" << FLAGS_proxy_host <<":"
65+
<< FLAGS_proxy_port <<":" << e.what();
66+
return;
67+
}
5968
socket_.resumeRead(this);
6069

6170
sendPing();
@@ -162,6 +171,11 @@ int main(int argc, char* argv[]) {
162171
options.httpRequest_->setMethod(proxygen::HTTPMethod::CONNECT_UDP);
163172
options.httpRequest_->setURL(fmt::format("{}:{}", FLAGS_host, FLAGS_port));
164173
options.httpRequest_->setMasque();
174+
auto parsedHeaders =CurlService::CurlClient::parseHeaders(FLAGS_headers);
175+
parsedHeaders.forEach(
176+
[&options](const std::string& name,const std::string& value) {
177+
options.httpRequest_->getHeaders().add(name, value);
178+
});
165179
options.certAndKey_ =std::make_pair(FLAGS_cert, FLAGS_key);
166180
options.certVerifier_ = std::make_unique<
167181
proxygen::InsecureVerifierDangerousDoNotUseInProduction>();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp