├── proxygen ├── VERSION ├── httpserver │ ├── samples │ │ ├── hq │ │ │ ├── pusheen.txt │ │ │ ├── devious │ │ │ │ └── test │ │ │ │ │ └── CMakeLists.txt │ │ │ ├── quic-interop │ │ │ │ ├── README.md │ │ │ │ └── Dockerfile │ │ │ ├── HQServerModule.h │ │ │ ├── HQLoggerHelper.h │ │ │ ├── HQLoggerHelper.cpp │ │ │ ├── FizzContext.h │ │ │ └── InsecureVerifierDangerousDoNotUseInProduction.h │ │ ├── push │ │ │ ├── pusheen.txt │ │ │ ├── PushStats.h │ │ │ └── PushRequestHandler.h │ │ ├── echo │ │ │ ├── test │ │ │ │ └── CMakeLists.txt │ │ │ ├── EchoStats.h │ │ │ └── EchoHandler.h │ │ ├── proxy │ │ │ ├── ProxyStats.h │ │ │ └── SessionWrapper.h │ │ ├── static │ │ │ └── StaticHandler.h │ │ └── websocket │ │ │ └── WebSocketHandler.h │ ├── filters │ │ ├── tests │ │ │ └── CMakeLists.txt │ │ └── DirectResponseHandler.h │ ├── tests │ │ ├── CMakeLists.txt │ │ └── certs │ │ │ ├── client_cert.pem │ │ │ ├── ca_cert.pem │ │ │ ├── test_cert1.pem │ │ │ ├── test_cert2.pem │ │ │ └── client_ca_cert.pem │ ├── ExMessageHandler.h │ ├── SignalHandler.cpp │ └── SignalHandler.h ├── external │ ├── http_parser │ │ ├── http_parser.c │ │ ├── CONTRIBUTIONS │ │ └── LICENSE-MIT │ └── CMakeLists.txt ├── lib │ ├── sampling │ │ ├── test │ │ │ └── CMakeLists.txt │ │ ├── Sampled.h │ │ ├── Sampling.h │ │ ├── MultiSampled.h │ │ └── SamplingFunctions.h │ ├── services │ │ ├── test │ │ │ └── CMakeLists.txt │ │ ├── ServiceConfiguration.h │ │ └── Service.cpp │ ├── http │ │ ├── connpool │ │ │ ├── test │ │ │ │ └── CMakeLists.txt │ │ │ └── ThreadIdleSessionController.cpp │ │ ├── stats │ │ │ ├── SPDYStatsFilter.h │ │ │ ├── SPDYStats.h │ │ │ ├── ResponseCodeStatsMinute.h │ │ │ ├── ResponseCodeStatsMinute.cpp │ │ │ └── HeaderCodecStats.h │ │ ├── Types.h │ │ ├── codec │ │ │ ├── compress │ │ │ │ ├── HPACKHeader.cpp │ │ │ │ ├── NoPathIndexingStrategy.cpp │ │ │ │ ├── QPACKStaticHeaderTable.h │ │ │ │ ├── StaticHeaderTable.h │ │ │ │ ├── Logging.h │ │ │ │ ├── experimental │ │ │ │ │ └── simulator │ │ │ │ │ │ ├── CompressionUtils.h │ │ │ │ │ │ └── CompressionTypes.h │ │ │ │ ├── HPACKEncoderBase.cpp │ │ │ │ ├── HPACKStreamingCallback.h │ │ │ │ ├── test │ │ │ │ │ ├── HeaderPieceTests.cpp │ │ │ │ │ ├── HTTPArchive.h │ │ │ │ │ └── CMakeLists.txt │ │ │ │ ├── NoPathIndexingStrategy.h │ │ │ │ ├── HeaderPiece.h │ │ │ │ ├── QPACKContext.cpp │ │ │ │ ├── HeaderIndexingStrategy.h │ │ │ │ ├── HeaderIndexingStrategy.cpp │ │ │ │ └── Header.h │ │ │ ├── test │ │ │ │ ├── HTTP2FramerTest.h │ │ │ │ └── CMakeLists.txt │ │ │ ├── TransportDirection.h │ │ │ ├── DefaultHTTPCodecFactory.h │ │ │ ├── TransportDirection.cpp │ │ │ ├── HTTPCodecFactory.cpp │ │ │ ├── HTTPChecks.h │ │ │ ├── HQUnidirectionalCodec.cpp │ │ │ ├── DirectErrorsRateLimitFilter.h │ │ │ ├── ResetsRateLimitFilter.h │ │ │ ├── HeadersRateLimitFilter.h │ │ │ ├── ErrorCode.h │ │ │ ├── ControlMessageRateLimitFilter.h │ │ │ ├── ErrorCode.cpp │ │ │ └── HTTP2Constants.cpp │ │ ├── test │ │ │ └── CMakeLists.txt │ │ ├── structuredheaders │ │ │ ├── test │ │ │ │ └── CMakeLists.txt │ │ │ ├── StructuredHeadersUtilities.h │ │ │ └── StructuredHeadersDecoder.h │ │ ├── session │ │ │ ├── AckLatencyEvent.h │ │ │ ├── test │ │ │ │ ├── ByteEventTrackerMocks.h │ │ │ │ ├── HTTP2PriorityQueueBench.cpp │ │ │ │ ├── test_cert1.pem │ │ │ │ ├── MockHTTPTransactionObserver.h │ │ │ │ ├── TestUtils.h │ │ │ │ ├── TestUtils.cpp │ │ │ │ └── MockSessionObserver.h │ │ │ ├── HTTPErrorPage.cpp │ │ │ ├── ByteEvents.cpp │ │ │ ├── TTLBAStats.h │ │ │ ├── HQByteEventTracker.h │ │ │ ├── HTTPEvent.cpp │ │ │ ├── HTTPDefaultSessionCodecFactory.h │ │ │ ├── CodecErrorResponseHandler.h │ │ │ ├── CodecErrorResponseHandler.cpp │ │ │ ├── HTTPTransactionEgressSM.h │ │ │ ├── HTTPDefaultSessionCodecFactory.cpp │ │ │ └── SecondaryAuthManagerBase.h │ │ ├── webtransport │ │ │ ├── test │ │ │ │ └── CMakeLists.txt │ │ │ └── CMakeLists.txt │ │ ├── HTTPPriorityFunctions.h │ │ ├── sink │ │ │ └── FlowControlInfo.h │ │ ├── HeaderConstants.h │ │ ├── HeaderConstants.cpp │ │ ├── StatusTypeEnum.cpp │ │ ├── ProxygenErrorEnum.cpp │ │ ├── HTTPConstants.cpp │ │ ├── observer │ │ │ ├── HTTPSessionObserverContainer.h │ │ │ └── HTTPTransactionObserverContainer.h │ │ ├── SynchronizedLruQuicPskCache.h │ │ ├── HTTPMessageFilters.cpp │ │ ├── HTTPHeaderSize.h │ │ ├── HTTPConnectorWithFizz.h │ │ ├── SynchronizedLruQuicPskCache.cpp │ │ ├── HTTPCommonHeaders.txt │ │ └── HTTP3ErrorCode.h │ ├── stats │ │ ├── test │ │ │ ├── ResourceDataTest.cpp │ │ │ └── CMakeLists.txt │ │ ├── BaseStats.cpp │ │ ├── ResourceStats.cpp │ │ ├── gen_StatsWrapper.sh │ │ └── ResourceStats.h │ ├── pools │ │ └── generators │ │ │ ├── MemberGroupConfig.h │ │ │ └── ServerListGenerator.cpp │ ├── dns │ │ ├── test │ │ │ ├── MockDNSModule.cpp │ │ │ ├── MockDNSModule.h │ │ │ ├── Mocks.h │ │ │ ├── SyncDNSResolverTest.h │ │ │ └── MockDNSResolver.h │ │ ├── NaiveResolutionCallback.h │ │ ├── DNSModule.cpp │ │ ├── SyncDNSResolver.h │ │ └── NaiveResolutionCallback.cpp │ ├── utils │ │ ├── HTTPTime.h │ │ ├── NullTraceEventObserver.h │ │ ├── CryptUtil.h │ │ ├── TraceEventContext.cpp │ │ ├── StreamCompressor.h │ │ ├── StreamDecompressor.h │ │ ├── Export.h │ │ ├── TraceEventObserver.h │ │ ├── Exception.cpp │ │ ├── test │ │ │ ├── CMakeLists.txt │ │ │ ├── MockTime.h │ │ │ └── CryptUtilTest.cpp │ │ ├── HTTPTime.cpp │ │ ├── ConsistentHash.h │ │ ├── ZlibStreamCompressor.h │ │ ├── samples │ │ │ └── TraceEventType.txt │ │ ├── CobHelper.h │ │ ├── TraceEventContext.h │ │ └── AcceptorAddress.h │ ├── transport │ │ ├── test │ │ │ ├── CMakeLists.txt │ │ │ └── MockAsyncTransportCertificate.h │ │ ├── PersistentFizzPskCache.cpp │ │ ├── PersistentQuicTokenCache.cpp │ │ ├── PersistentQuicTokenCache.h │ │ └── AsyncUDPSocketFactory.h │ ├── test │ │ ├── TestMain.cpp │ │ └── CMakeLists.txt │ └── ssl │ │ └── ProxygenSSL.h ├── httpclient │ ├── CMakeLists.txt │ └── samples │ │ ├── CMakeLists.txt │ │ ├── pricli │ │ └── CMakeLists.txt │ │ ├── httperf2 │ │ ├── HTTPerf2.h │ │ ├── Main.cpp │ │ └── CMakeLists.txt │ │ ├── H3Datagram │ │ └── CMakeLists.txt │ │ ├── curl │ │ └── CMakeLists.txt │ │ └── websocket │ │ └── CMakeLists.txt ├── CMakeLists.txt └── install.sh ├── CoreProxygenArchitecture.png ├── .github ├── dependabot.yml └── workflows │ ├── close_stale.yml │ └── publish_mvfst_interop.yml ├── .gitignore ├── getdeps.sh ├── cmake └── FindZstd.cmake ├── cmake_uninstall.cmake.in └── LICENSE /proxygen/VERSION: -------------------------------------------------------------------------------- 1 | 32:0 2 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/hq/pusheen.txt: -------------------------------------------------------------------------------- 1 | Pusheen!! 2 | -------------------------------------------------------------------------------- /proxygen/external/http_parser/http_parser.c: -------------------------------------------------------------------------------- 1 | http_parser_cpp.cpp -------------------------------------------------------------------------------- /CoreProxygenArchitecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gaerwn/proxygen/HEAD/CoreProxygenArchitecture.png -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | -------------------------------------------------------------------------------- /proxygen/external/http_parser/CONTRIBUTIONS: -------------------------------------------------------------------------------- 1 | Contributors must agree to the Contributor License Agreement before patches 2 | can be accepted. 3 | 4 | http://spreadsheets2.google.com/viewform?hl=en&formkey=dDJXOGUwbzlYaWM4cHN1MERwQS1CSnc6MQ 5 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/push/pusheen.txt: -------------------------------------------------------------------------------- 1 | * * * About Pusheen the cat. * * * 2 | 3 | Breed: Domestic shorthair 4 | 5 | Coat Type: Grey Tabby 6 | 7 | Age: All 9 lives left 8 | 9 | Sex: Female 10 | 11 | Pusheen the cat is an animated web comic series produced by Pusheen Corp 12 | 13 | http://www.pusheen.com/about 14 | -------------------------------------------------------------------------------- /proxygen/lib/sampling/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | proxygen_add_test(TARGET SamplingTest DEPENDS proxygen testmain) 8 | -------------------------------------------------------------------------------- /proxygen/httpclient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | if (BUILD_SAMPLES) 8 | add_subdirectory(samples) 9 | endif() 10 | -------------------------------------------------------------------------------- /proxygen/httpclient/samples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | add_subdirectory(curl) 8 | add_subdirectory(H3Datagram) 9 | add_subdirectory(httperf2) 10 | -------------------------------------------------------------------------------- /proxygen/lib/services/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | proxygen_add_test(TARGET AcceptorTest DEPENDS proxygen testmain) 8 | proxygen_add_test(TARGET RequestWorkerThreadTest DEPENDS proxygen testmain) 9 | -------------------------------------------------------------------------------- /proxygen/httpclient/samples/pricli/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | add_executable(proxygen_pricli PriCli.cpp) 8 | target_compile_options( 9 | proxygen_pricli PRIVATE 10 | ${_PROXYGEN_COMMON_COMPILE_OPTIONS} 11 | ) 12 | -------------------------------------------------------------------------------- /proxygen/lib/http/connpool/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | proxygen_add_test(TARGET ConnpoolTests 8 | SOURCES 9 | SessionPoolTest.cpp 10 | DEPENDS 11 | proxygen 12 | testtransport 13 | testmain 14 | ) 15 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/hq/devious/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | proxygen_add_test(TARGET DeviousBatonTests 8 | SOURCES 9 | DeviousBatonTests.cpp 10 | DEPENDS 11 | proxygendeviousbaton 12 | testmain 13 | ) 14 | -------------------------------------------------------------------------------- /proxygen/httpserver/filters/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | proxygen_add_test(TARGET HTTPServerFilterTests 8 | SOURCES 9 | CompressionFilterTest.cpp 10 | DEPENDS 11 | proxygen 12 | proxygenhttpserver 13 | testmain 14 | ) 15 | -------------------------------------------------------------------------------- /proxygen/lib/http/stats/SPDYStatsFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | using SPDYStatsFilter = HTTPCodecStatsFilter; 15 | } 16 | -------------------------------------------------------------------------------- /proxygen/lib/stats/test/ResourceDataTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include "proxygen/lib/stats/ResourceData.h" 10 | #include 11 | 12 | using namespace proxygen; 13 | 14 | class ResourceDataTest : public ::testing::Test {}; 15 | -------------------------------------------------------------------------------- /proxygen/lib/http/Types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | using HTTPQueryParamMap = folly::F14FastMap; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /proxygen/lib/pools/generators/MemberGroupConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | using MemberGroupId = int32_t; 15 | const MemberGroupId kInvalidPoolMemberGroupId{-1}; 16 | } // namespace proxygen 17 | -------------------------------------------------------------------------------- /proxygen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | if (NOT DEFINED LIB_INSTALL_DIR) 8 | set(LIB_INSTALL_DIR "lib") 9 | endif() 10 | 11 | add_subdirectory(external) 12 | add_subdirectory(lib) 13 | add_subdirectory(httpserver) 14 | add_subdirectory(httpclient) 15 | add_subdirectory(fuzzers) 16 | -------------------------------------------------------------------------------- /proxygen/lib/http/stats/SPDYStats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | using SPDYStats = HTTPCodecStats; 15 | using TLSPDYStats = TLHTTPCodecStats; 16 | } // namespace proxygen 17 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/hq/quic-interop/README.md: -------------------------------------------------------------------------------- 1 | mvfst+proxygen Docker image for use with the 2 | [quic-network-simulator](https://github.com/marten-seemann/quic-network-simulator/) and [quic-interop-runner](https://github.com/marten-seemann/quic-interop-runner) 3 | 4 | Build your own by running this after checking out the repo: 5 | ``` 6 | docker build . -f proxygen/httpserver/samples/hq/quic-interop/Dockerfile 7 | ``` 8 | or download the latest image build from Github under the packages section of this repo. 9 | -------------------------------------------------------------------------------- /proxygen/lib/dns/test/MockDNSModule.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include "proxygen/lib/dns/test/MockDNSModule.h" 10 | 11 | namespace proxygen { 12 | 13 | MockDNSModule::MockDNSModule() { 14 | } 15 | 16 | MockDNSModule::~MockDNSModule() { 17 | } 18 | 19 | } // namespace proxygen 20 | -------------------------------------------------------------------------------- /proxygen/lib/utils/HTTPTime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace proxygen { 16 | 17 | folly::Optional parseHTTPDateTime(const std::string& s); 18 | 19 | } // namespace proxygen 20 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/echo/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | proxygen_add_test(TARGET EchoHandlerTests 8 | SOURCES 9 | EchoHandlerTest.cpp 10 | ../EchoServer.cpp 11 | ../EchoHandler.cpp 12 | DEPENDS 13 | proxygen 14 | proxygenhttpserver 15 | proxygencurl 16 | testmain 17 | ) 18 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/HPACKHeader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | namespace proxygen { 12 | 13 | std::ostream& operator<<(std::ostream& os, const HPACKHeader& h) { 14 | os << h.name << ": " << h.value; 15 | return os; 16 | } 17 | 18 | } // namespace proxygen 19 | -------------------------------------------------------------------------------- /proxygen/httpclient/samples/httperf2/HTTPerf2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | DECLARE_string(ip); 14 | DECLARE_string(server); 15 | DECLARE_int32(port); 16 | 17 | namespace proxygen { 18 | 19 | int httperf2(folly::Optional bindAddr = folly::none); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /proxygen/httpserver/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | proxygen_add_test(TARGET HTTPServerTests 8 | SOURCES 9 | HTTPServerTest.cpp 10 | RequestHandlerAdaptorTest.cpp 11 | DEPENDS 12 | codectestutils 13 | proxygen 14 | proxygenhttpserver 15 | proxygencurl 16 | testmain 17 | Boost::filesystem 18 | Boost::regex 19 | ) 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | \#*\# 3 | 4 | # Build artifacts 5 | .libs 6 | *.log 7 | *.trs 8 | *.o 9 | *.lo 10 | *.a 11 | *.la 12 | gen-cpp 13 | gen-cpp2 14 | 15 | # Generated files 16 | /proxygen/lib/http/HTTPCommonHeaders.cpp 17 | /proxygen/lib/http/HTTPCommonHeaders.h 18 | /proxygen/lib/utils/TraceEventType.cpp 19 | /proxygen/lib/utils/TraceEventType.h 20 | /proxygen/lib/utils/TraceFieldType.cpp 21 | /proxygen/lib/utils/TraceFieldType.h 22 | /proxygen/lib/stats/StatsWrapper.h 23 | _build/ 24 | 25 | # common editor artifacts 26 | *~ 27 | *.vscode* 28 | 29 | # Generated document 30 | html/ 31 | latex/ 32 | -------------------------------------------------------------------------------- /proxygen/lib/http/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | proxygen_add_test(TARGET LibHTTPTests 8 | SOURCES 9 | HTTPCommonHeadersTests.cpp 10 | HTTPConnectorWithFizzTest.cpp 11 | HTTPMessageTest.cpp 12 | HTTPPriorityFunctionsTest.cpp 13 | ProxyStatusTest.cpp 14 | RFC2616Test.cpp 15 | WindowTest.cpp 16 | DEPENDS 17 | proxygen 18 | testmain 19 | ) 20 | -------------------------------------------------------------------------------- /proxygen/lib/http/structuredheaders/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | proxygen_add_test(TARGET StructuredHeadersTests 8 | SOURCES 9 | StructuredHeadersBufferTest.cpp 10 | StructuredHeadersDecoderTest.cpp 11 | StructuredHeadersEncoderTest.cpp 12 | StructuredHeadersStandardTest.cpp 13 | StructuredHeadersUtilitiesTest.cpp 14 | DEPENDS 15 | proxygen 16 | testmain 17 | ) 18 | -------------------------------------------------------------------------------- /proxygen/lib/stats/BaseStats.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include "proxygen/lib/stats/BaseStats.h" 10 | 11 | DEFINE_bool(basestats_all_time_timeseries, 12 | false, 13 | "If true, BaseStats will use all-time aggregations"); 14 | 15 | /*static*/ 16 | bool proxygen::BaseStats::isAllTimeTimeseriesEnabled() { 17 | return FLAGS_basestats_all_time_timeseries; 18 | } 19 | -------------------------------------------------------------------------------- /proxygen/lib/utils/NullTraceEventObserver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | /* 15 | * A no-op trace event observer 16 | */ 17 | struct NullTraceEventObserver : public TraceEventObserver { 18 | void traceEventAvailable(TraceEvent) noexcept override { 19 | } 20 | }; 21 | 22 | } // namespace proxygen 23 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/NoPathIndexingStrategy.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | namespace proxygen { 12 | 13 | const NoPathIndexingStrategy* NoPathIndexingStrategy::getInstance() { 14 | static const NoPathIndexingStrategy* instance = new NoPathIndexingStrategy(); 15 | return instance; 16 | } 17 | 18 | } // namespace proxygen 19 | -------------------------------------------------------------------------------- /proxygen/lib/utils/CryptUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | // Base64 encode using openssl, may return empty string on allocation failure 17 | std::string base64Encode(folly::ByteRange text); 18 | 19 | // MD5 encode using openssl 20 | std::string md5Encode(folly::ByteRange text); 21 | } // namespace proxygen 22 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/hq/HQServerModule.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace quic::samples { 14 | 15 | void startServer(const HQToolServerParams& params, 16 | std::unique_ptr&& 17 | statsFactory = nullptr); 18 | 19 | } // namespace quic::samples 20 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/AckLatencyEvent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | struct AckLatencyEvent { 16 | // The byte number that was acknowledged. 17 | unsigned int byteNo; 18 | // The latency between sending the byte and receiving the ack for that byte. 19 | std::chrono::nanoseconds latency; 20 | }; 21 | 22 | } // namespace proxygen 23 | -------------------------------------------------------------------------------- /proxygen/lib/transport/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | if(NOT BUILD_TESTS) 8 | return() 9 | endif() 10 | 11 | proxygen_add_test(TARGET TransportTests 12 | SOURCES 13 | H3DatagramAsyncSocketTest.cpp 14 | DEPENDS 15 | codectestutils 16 | sessiontestutils 17 | proxygen 18 | testmain 19 | mvfst::mvfst_codec_types 20 | mvfst::mvfst_dsr_types 21 | mvfst::mvfst_state_machine 22 | ) 23 | -------------------------------------------------------------------------------- /proxygen/httpclient/samples/httperf2/Main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main(int argc, char* argv[]) { 14 | gflags::SetUsageMessage(std::string("\n\nusage: httperf2 (see flags)\n")); 15 | auto _ = folly::Init(&argc, &argv, true); 16 | 17 | return proxygen::httperf2(); 18 | } 19 | -------------------------------------------------------------------------------- /proxygen/lib/http/webtransport/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | if(NOT BUILD_TESTS) 8 | return() 9 | endif() 10 | 11 | proxygen_add_test(TARGET WebTransportAPITest 12 | SOURCES 13 | WebTransportAPITest.cpp 14 | DEPENDS 15 | proxygen 16 | testmain 17 | ) 18 | 19 | proxygen_add_test(TARGET QuicWebTransportTest 20 | SOURCES 21 | QuicWebTransportTest.cpp 22 | DEPENDS 23 | quicwebtransport 24 | testmain 25 | ) 26 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/test/HTTP2FramerTest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | // Writes out the common frame header without checks 14 | void writeFrameHeaderManual(folly::IOBufQueue& queue, 15 | uint32_t length, 16 | uint8_t type, 17 | uint8_t flags, 18 | uint32_t stream); 19 | -------------------------------------------------------------------------------- /proxygen/lib/http/HTTPPriorityFunctions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace proxygen { 16 | 17 | folly::Optional httpPriorityFromString( 18 | folly::StringPiece priority); 19 | 20 | folly::Optional httpPriorityFromHTTPMessage( 21 | const HTTPMessage& message); 22 | 23 | } // namespace proxygen 24 | -------------------------------------------------------------------------------- /proxygen/httpclient/samples/H3Datagram/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | add_executable(proxygen_h3datagram_client H3DatagramClient.cpp) 8 | target_compile_options( 9 | proxygen_h3datagram_client PRIVATE 10 | ${_PROXYGEN_COMMON_COMPILE_OPTIONS} 11 | ) 12 | target_link_libraries( 13 | proxygen_h3datagram_client 14 | PUBLIC 15 | proxygen 16 | ) 17 | install( 18 | TARGETS proxygen_h3datagram_client 19 | EXPORT proxygen-exports 20 | DESTINATION bin 21 | ) 22 | -------------------------------------------------------------------------------- /proxygen/lib/stats/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | proxygen_add_test(TARGET PeriodicStatsTest 8 | SOURCES 9 | PeriodicStatsTest.cpp 10 | DEPENDS 11 | proxygen 12 | testmain 13 | ) 14 | 15 | proxygen_add_test(TARGET ResourceDataTest 16 | SOURCES 17 | ResourceDataTest.cpp 18 | DEPENDS 19 | proxygen 20 | testmain 21 | ) 22 | 23 | proxygen_add_test(TARGET ResourceStatsTest 24 | SOURCES 25 | ResourceStatsTest.cpp 26 | DEPENDS 27 | proxygen 28 | testmain 29 | ) 30 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/QPACKStaticHeaderTable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | class QPACKStaticHeaderTable { 17 | 18 | public: 19 | static const StaticHeaderTable& get(); 20 | 21 | // Not currently used 22 | static bool isHeaderCodeInTableWithNonEmptyValue(HTTPHeaderCode headerCode); 23 | }; 24 | 25 | } // namespace proxygen 26 | -------------------------------------------------------------------------------- /proxygen/lib/utils/TraceEventContext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | namespace proxygen { 13 | 14 | void TraceEventContext::traceEventAvailable(const TraceEvent& event) { 15 | for (const auto observer : observers_) { 16 | observer->traceEventAvailable(event); 17 | } 18 | } 19 | 20 | bool TraceEventContext::isAllTraceEventNeeded() const { 21 | return allTraceEventNeeded_; 22 | } 23 | 24 | } // namespace proxygen 25 | -------------------------------------------------------------------------------- /proxygen/lib/test/TestMain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | // Use this main function in gtest unit tests to enable glog 10 | #include 11 | #include 12 | #include 13 | 14 | int main(int argc, char* argv[]) { 15 | testing::InitGoogleTest(&argc, argv); 16 | gflags::ParseCommandLineFlags(&argc, &argv, true); 17 | google::InitGoogleLogging(argv[0]); 18 | google::InstallFailureSignalHandler(); 19 | LOG(INFO) << "Running tests from TestMain.cpp"; 20 | return RUN_ALL_TESTS(); 21 | } 22 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/StaticHeaderTable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | class StaticHeaderTable : public HeaderTable { 17 | 18 | public: 19 | explicit StaticHeaderTable(const char* entries[][2], int size); 20 | 21 | static const StaticHeaderTable& get(); 22 | 23 | static bool isHeaderCodeInTableWithNonEmptyValue(HTTPHeaderCode headerCode); 24 | }; 25 | 26 | } // namespace proxygen 27 | -------------------------------------------------------------------------------- /.github/workflows/close_stale.yml: -------------------------------------------------------------------------------- 1 | name: Close inactive issues 2 | on: 3 | schedule: 4 | - cron: "30 1 * * *" 5 | 6 | jobs: 7 | close-issues: 8 | runs-on: ubuntu-latest 9 | permissions: 10 | issues: write 11 | steps: 12 | - uses: actions/stale@v9 13 | with: 14 | days-before-issue-stale: -1 15 | days-before-issue-close: 14 16 | stale-issue-label: "need-input" 17 | stale-issue-message: "This issue is stale because it has been open too long with no activity." 18 | close-issue-message: "This issue was closed because it has been inactive for two weeks since being marked as need-input." 19 | days-before-pr-stale: -1 20 | days-before-pr-close: -1 21 | repo-token: ${{ secrets.GITHUB_TOKEN }} 22 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/TransportDirection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | enum class TransportDirection : uint8_t { 17 | DOWNSTREAM, // toward the client 18 | UPSTREAM // toward the origin application or data 19 | }; 20 | 21 | const char* getTransportDirectionString(TransportDirection dir); 22 | 23 | TransportDirection operator!(TransportDirection dir); 24 | 25 | std::ostream& operator<<(std::ostream& os, const TransportDirection dir); 26 | 27 | } // namespace proxygen 28 | -------------------------------------------------------------------------------- /proxygen/lib/utils/StreamCompressor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace folly { 14 | class IOBuf; 15 | } 16 | 17 | namespace proxygen { 18 | 19 | /** 20 | * Interface to be implemented by all stream compressors 21 | */ 22 | class StreamCompressor { 23 | public: 24 | virtual ~StreamCompressor() { 25 | } 26 | 27 | virtual std::unique_ptr compress(const folly::IOBuf* in, 28 | bool trailer = true) = 0; 29 | virtual bool hasError() = 0; 30 | }; 31 | 32 | } // namespace proxygen 33 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/test/ByteEventTrackerMocks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | class MockByteEventTrackerCallback 15 | : public proxygen::ByteEventTracker::Callback { 16 | public: 17 | MOCK_METHOD((void), onPingReplyLatency, (int64_t), (noexcept)); 18 | MOCK_METHOD((void), 19 | onTxnByteEventWrittenToBuf, 20 | (const proxygen::ByteEvent&), 21 | (noexcept)); 22 | MOCK_METHOD((void), onDeleteTxnByteEvent, (), (noexcept)); 23 | }; 24 | -------------------------------------------------------------------------------- /proxygen/lib/http/sink/FlowControlInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | namespace proxygen { 12 | struct FlowControlInfo { 13 | bool sessionWritesPaused_{false}; 14 | bool sessionReadsPaused_{false}; 15 | bool flowControlEnabled_{false}; 16 | int64_t sessionSendWindow_{-1}; 17 | int64_t sessionRecvWindow_{-1}; 18 | int64_t sessionSendOutstanding_{-1}; 19 | int64_t sessionRecvOutstanding_{-1}; 20 | int64_t streamSendWindow_{-1}; 21 | int64_t streamRecvWindow_{-1}; 22 | int64_t streamSendOutstanding_{-1}; 23 | int64_t streamRecvOutstanding_{-1}; 24 | }; 25 | 26 | } // namespace proxygen 27 | -------------------------------------------------------------------------------- /proxygen/install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # All rights reserved. 4 | # 5 | # This source code is licensed under the BSD-style license found in the 6 | # LICENSE file in the root directory of this source tree. 7 | 8 | ## Run this script to (re)install proxygen and its dependencies (fbthrift 9 | ## and folly). You must first compile all the dependencies before running this. This 10 | ## Usually this is done by first running `deps.sh`. 11 | 12 | set -e 13 | start_dir=$(pwd) 14 | trap 'cd $start_dir' EXIT 15 | 16 | # Must execute from the directory containing this script 17 | cd "$(dirname "$0")" 18 | 19 | cd _build 20 | # Uninstall is expected to fail the first time 21 | make uninstall || true 22 | make install 23 | 24 | # Make sure the libraries are available 25 | # Linux only 26 | /sbin/ldconfig || true 27 | -------------------------------------------------------------------------------- /proxygen/lib/http/HeaderConstants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { namespace headers { 14 | extern const std::string kAuthority; 15 | extern const std::string kMethod; 16 | extern const std::string kPath; 17 | extern const std::string kScheme; 18 | extern const std::string kStatus; 19 | extern const std::string kProtocol; 20 | 21 | extern const std::string kHttp; 22 | extern const std::string kHttps; 23 | extern const std::string kMasque; 24 | 25 | extern const std::string kWebsocketString; 26 | extern const std::string kStatus200; 27 | 28 | }} // namespace proxygen::headers 29 | -------------------------------------------------------------------------------- /proxygen/lib/dns/test/MockDNSModule.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include "proxygen/lib/dns/DNSModule.h" 12 | 13 | namespace proxygen { 14 | 15 | class MockDNSModule : public DNSModule { 16 | public: 17 | MockDNSModule(); 18 | 19 | ~MockDNSModule() override; 20 | 21 | void setMockDNSResolver(DNSResolver::UniquePtr r) { 22 | resolver = std::move(r); 23 | } 24 | 25 | DNSResolver::UniquePtr provideDNSResolver( 26 | folly::EventBase* /*eventBase*/) override { 27 | return std::move(resolver); 28 | } 29 | 30 | private: 31 | DNSResolver::UniquePtr resolver; 32 | }; 33 | 34 | } // namespace proxygen 35 | -------------------------------------------------------------------------------- /proxygen/lib/utils/StreamDecompressor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace folly { 15 | class IOBuf; 16 | } 17 | 18 | namespace proxygen { 19 | 20 | enum class CompressionType : uint8_t { NONE, DEFLATE, GZIP, ZSTD }; 21 | 22 | /** 23 | * Abstract base class for stream decompressor implementations. 24 | */ 25 | class StreamDecompressor { 26 | public: 27 | virtual ~StreamDecompressor() = default; 28 | virtual std::unique_ptr decompress(const folly::IOBuf* in) = 0; 29 | virtual bool hasError() = 0; 30 | virtual bool finished() = 0; 31 | }; 32 | } // namespace proxygen 33 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/Logging.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace proxygen { 17 | 18 | std::ostream& operator<<(std::ostream& os, const std::list* refset); 19 | 20 | std::ostream& operator<<(std::ostream& os, const std::vector& v); 21 | 22 | /** 23 | * print the difference between 2 sorted list of headers 24 | */ 25 | std::string printDelta(const std::vector& v1, 26 | const std::vector& v2); 27 | 28 | } // namespace proxygen 29 | -------------------------------------------------------------------------------- /proxygen/lib/http/stats/ResponseCodeStatsMinute.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | struct ResponseCodeStatsMinute { 16 | explicit ResponseCodeStatsMinute(const std::string& name); 17 | 18 | void addStatus(int status); 19 | 20 | StatsWrapper::TLTimeseriesMinute statusOther; 21 | StatsWrapper::TLTimeseriesMinute status1xx; 22 | StatsWrapper::TLTimeseriesMinute status2xx; 23 | StatsWrapper::TLTimeseriesMinute status3xx; 24 | StatsWrapper::TLTimeseriesMinute status4xx; 25 | StatsWrapper::TLTimeseriesMinute status5xx; 26 | }; 27 | 28 | } // namespace proxygen 29 | -------------------------------------------------------------------------------- /proxygen/external/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | add_library( 8 | proxygen_http_parser OBJECT 9 | http_parser/http_parser_cpp.cpp 10 | ) 11 | 12 | target_compile_options( 13 | proxygen_http_parser PRIVATE 14 | ${_PROXYGEN_COMMON_COMPILE_OPTIONS} 15 | "-DHTTP_PARSER_STRICT_URL=1" 16 | "-Wno-implicit-fallthrough" 17 | ) 18 | 19 | if (BUILD_SHARED_LIBS) 20 | set_property(TARGET proxygen_http_parser PROPERTY POSITION_INDEPENDENT_CODE ON) 21 | endif() 22 | 23 | target_include_directories( 24 | proxygen_http_parser PRIVATE 25 | ${PROXYGEN_FBCODE_ROOT} 26 | ) 27 | install(FILES http_parser/http_parser.h DESTINATION 28 | include/proxygen/external/http_parser) 29 | -------------------------------------------------------------------------------- /proxygen/httpserver/ExMessageHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | /** 16 | * Interface to be implemented to handle EX messages from client. 17 | */ 18 | class ExMessageHandler : public RequestHandler { 19 | public: 20 | virtual void onUpgrade(proxygen::UpgradeProtocol /*prot*/) noexcept override { 21 | LOG(FATAL) << "ExMessageHandler doesn't support upgrade"; 22 | } 23 | 24 | virtual ExMessageHandler* getExHandler() noexcept override { 25 | LOG(FATAL) << "getExHandler can't be called on ExMessageHandler"; 26 | } 27 | }; 28 | 29 | } // namespace proxygen 30 | -------------------------------------------------------------------------------- /proxygen/lib/utils/Export.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | // From https://gcc.gnu.org/wiki/Visibility 12 | #if defined _WIN32 || defined __CYGWIN__ 13 | // The current uses of this doesn't actually 14 | // have any need to be present on Windows, 15 | // and building proxygen as a dynamic lib 16 | // under Windows is not currently supported. 17 | // HHVM builds Proxygen as a static library. 18 | #define FB_EXPORT 19 | #define FB_LOCAL 20 | #else 21 | #if __GNUC__ >= 4 22 | #define FB_EXPORT __attribute__((visibility("default"))) 23 | #define FB_LOCAL __attribute__((visibility("hidden"))) 24 | #else 25 | #define FB_EXPORT 26 | #define FB_LOCAL 27 | #endif 28 | #endif 29 | -------------------------------------------------------------------------------- /proxygen/lib/http/HeaderConstants.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | namespace proxygen { namespace headers { 12 | 13 | const std::string kAuthority(":authority"); 14 | const std::string kMethod(":method"); 15 | const std::string kPath(":path"); 16 | const std::string kScheme(":scheme"); 17 | const std::string kStatus(":status"); 18 | const std::string kProtocol(":protocol"); 19 | 20 | const std::string kHttp("http"); 21 | const std::string kHttps("https"); 22 | const std::string kMasque("masque"); 23 | 24 | const std::string kWebsocketString("websocket"); 25 | const std::string kStatus200("200"); 26 | 27 | }} // namespace proxygen::headers 28 | -------------------------------------------------------------------------------- /proxygen/lib/transport/PersistentFizzPskCache.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace folly { 14 | 15 | template <> 16 | dynamic toDynamic(const proxygen::PersistentCachedPsk& cached) { 17 | dynamic d = dynamic::object; 18 | d["psk"] = cached.serialized; 19 | d["uses"] = cached.uses; 20 | return d; 21 | } 22 | 23 | template <> 24 | proxygen::PersistentCachedPsk convertTo(const dynamic& d) { 25 | proxygen::PersistentCachedPsk psk; 26 | psk.serialized = d["psk"].asString(); 27 | psk.uses = folly::to(d["uses"].asInt()); 28 | return psk; 29 | } 30 | } // namespace folly 31 | -------------------------------------------------------------------------------- /proxygen/lib/services/ServiceConfiguration.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | namespace proxygen { 12 | 13 | /** 14 | * Base class for all the Configuration objects 15 | */ 16 | class ServiceConfiguration { 17 | public: 18 | ServiceConfiguration() : takeoverEnabled_(false) { 19 | } 20 | 21 | virtual ~ServiceConfiguration() { 22 | } 23 | 24 | /** 25 | * Set/get whether or not we should enable socket takeover 26 | */ 27 | void setTakeoverEnabled(bool enabled) { 28 | takeoverEnabled_ = enabled; 29 | } 30 | bool takeoverEnabled() const { 31 | return takeoverEnabled_; 32 | } 33 | 34 | private: 35 | bool takeoverEnabled_; 36 | }; 37 | 38 | } // namespace proxygen 39 | -------------------------------------------------------------------------------- /proxygen/lib/http/StatusTypeEnum.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #define STATUS_TYPE_STR(statusType) #statusType 12 | 13 | namespace { 14 | static const char* statusTypeStrings[] = {STATUS_TYPES_GEN(STATUS_TYPE_STR)}; 15 | } 16 | 17 | namespace proxygen { 18 | 19 | const char* getStatusTypeString(StatusType statusType) { 20 | int statusTypeInt = static_cast(statusType); 21 | if (static_cast(statusType) < 0 || 22 | statusType >= StatusType::ENUM_COUNT) { 23 | return statusTypeStrings[static_cast(StatusType::ENUM_COUNT)]; 24 | } else { 25 | return statusTypeStrings[statusTypeInt]; 26 | } 27 | } 28 | 29 | } // namespace proxygen 30 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/hq/HQLoggerHelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | /** 17 | * Allows adding FileQLogger objects to transport, which will output logs 18 | * prior to destrution 19 | */ 20 | namespace quic::samples { 21 | 22 | class HQLoggerHelper : public ::quic::FileQLogger { 23 | public: 24 | HQLoggerHelper(const std::string& /* path */, 25 | bool /* pretty */, 26 | quic::VantagePoint); 27 | 28 | ~HQLoggerHelper() override; 29 | 30 | private: 31 | std::string outputPath_; 32 | bool pretty_; 33 | }; 34 | } // namespace quic::samples 35 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/experimental/simulator/CompressionUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace proxygen { 18 | namespace compress { 19 | 20 | // Convert an HTTPMessage into a format that can be passed to a HeaderCodec 21 | std::vector
prepareMessageForCompression( 22 | const HTTPMessage& msg, std::vector& cookies); 23 | 24 | } // namespace compress 25 | 26 | // Compare two HTTPMessage's for equality 27 | bool operator==(const HTTPMessage& msg1, const HTTPMessage& msg2); 28 | 29 | } // namespace proxygen 30 | -------------------------------------------------------------------------------- /proxygen/lib/stats/ResourceStats.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | namespace proxygen { 12 | 13 | ResourceStats::ResourceStats(std::unique_ptr resources) 14 | : PeriodicStats( 15 | new ResourceData(resources->getCurrentData())), 16 | resources_(std::move(resources)) { 17 | } 18 | 19 | ResourceStats::~ResourceStats() { 20 | // Stop refreshing on destruction so the function scheduler thread can 21 | // not access destructed class members. 22 | stopRefresh(); 23 | } 24 | 25 | ResourceData* ResourceStats::getNewData() const { 26 | return new ResourceData(resources_->getCurrentData()); 27 | } 28 | 29 | } // namespace proxygen 30 | -------------------------------------------------------------------------------- /proxygen/lib/utils/TraceEventObserver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | /* 16 | * Observer interface to record trace events. 17 | * 18 | * Subclasses of TraceEventObserver may log the trace events 19 | * to a destination analytics pipeline or forward them elsewhere. 20 | */ 21 | struct TraceEventObserver { 22 | virtual ~TraceEventObserver() { 23 | } 24 | /** 25 | * Lets the handler receive an arbitrary TraceEvent. 26 | */ 27 | virtual void traceEventAvailable(TraceEvent) noexcept { 28 | } 29 | virtual void emitTraceEvents(std::vector) noexcept { 30 | } 31 | }; 32 | 33 | } // namespace proxygen 34 | -------------------------------------------------------------------------------- /getdeps.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # All rights reserved. 4 | # 5 | # This source code is licensed under the BSD-style license found in the 6 | # LICENSE file in the root directory of this source tree. 7 | 8 | set -xeo pipefail 9 | 10 | TOOLCHAIN_DIR=/opt/rh/devtoolset-8/root/usr/bin 11 | if [[ -d "$TOOLCHAIN_DIR" ]]; then 12 | PATH="$TOOLCHAIN_DIR:$PATH" 13 | fi 14 | 15 | PROJECT_DIR=$(dirname "$0") 16 | GETDEPS_PATHS=( 17 | "$PROJECT_DIR/build/fbcode_builder/getdeps.py" 18 | "$PROJECT_DIR/../../opensource/fbcode_builder/getdeps.py" 19 | ) 20 | 21 | ROOT_DIR=$(pwd) 22 | STAGE=${ROOT_DIR}/_build/ 23 | mkdir -p "$STAGE" 24 | 25 | for getdeps in "${GETDEPS_PATHS[@]}"; do 26 | if [[ -x "$getdeps" ]]; then 27 | "$getdeps" build proxygen --current-project proxygen "$@" --install-prefix=${STAGE} 28 | exit 0 29 | fi 30 | done 31 | 32 | echo "Could not find getdeps.py!?" >&2 33 | exit 1 34 | -------------------------------------------------------------------------------- /proxygen/httpserver/SignalHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | using folly::EventBaseManager; 15 | 16 | namespace proxygen { 17 | 18 | SignalHandler::SignalHandler(HTTPServer* server) 19 | : folly::AsyncSignalHandler(EventBaseManager::get()->getEventBase()), 20 | server_(server) { 21 | } 22 | 23 | void SignalHandler::install(const std::vector& signals) { 24 | for (const int& signal : signals) { 25 | registerSignalHandler(signal); 26 | } 27 | } 28 | 29 | void SignalHandler::signalReceived(int /*signum*/) noexcept { 30 | server_->stop(); 31 | } 32 | } // namespace proxygen 33 | -------------------------------------------------------------------------------- /proxygen/lib/dns/test/Mocks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | #include "proxygen/lib/dns/DNSResolver.h" 14 | 15 | namespace proxygen { 16 | 17 | class MockDNSClient : public DNSResolver::ResolutionCallback { 18 | public: 19 | void resolutionSuccess( 20 | std::vector answers) noexcept override { 21 | _resolutionSuccess(answers); 22 | } 23 | MOCK_METHOD(void, _resolutionSuccess, (std::vector)); 24 | 25 | void resolutionError(const folly::exception_wrapper& ex) noexcept override { 26 | _resolutionError(ex); 27 | } 28 | MOCK_METHOD(void, _resolutionError, (const folly::exception_wrapper&)); 29 | }; 30 | 31 | } // namespace proxygen 32 | -------------------------------------------------------------------------------- /proxygen/lib/http/ProxygenErrorEnum.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #define PROXYGEN_ERROR_STR(error) #error 12 | 13 | namespace { 14 | static const char* errorStrings[] = {PROXYGEN_ERROR_GEN(PROXYGEN_ERROR_STR)}; 15 | } 16 | 17 | namespace proxygen { 18 | 19 | static_assert(kErrorMax < 1 << PROXYGEN_ERROR_BITSIZE, 20 | "ProxygenError overflow"); 21 | 22 | const char* getErrorString(ProxygenError error) { 23 | if (error < kErrorNone || error >= kErrorMax) { 24 | return errorStrings[kErrorMax]; 25 | } else { 26 | return errorStrings[error]; 27 | } 28 | } 29 | 30 | const char* getErrorStringByIndex(int i) { 31 | return errorStrings[i]; 32 | } 33 | 34 | } // namespace proxygen 35 | -------------------------------------------------------------------------------- /proxygen/lib/utils/Exception.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | namespace proxygen { 12 | 13 | Exception::Exception(std::string const& msg) : msg_(msg), code_(0) { 14 | } 15 | 16 | Exception::Exception(const char* msg) : msg_(msg), code_(0) { 17 | } 18 | 19 | Exception::Exception(const Exception& other) 20 | : msg_(other.msg_), 21 | code_(other.code_), 22 | proxygenError_(other.proxygenError_) { 23 | } 24 | 25 | Exception::Exception(Exception&& other) noexcept 26 | : msg_(other.msg_), 27 | code_(other.code_), 28 | proxygenError_(other.proxygenError_) { 29 | } 30 | 31 | const char* Exception::what(void) const noexcept { 32 | return msg_.c_str(); 33 | } 34 | 35 | } // namespace proxygen 36 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/DefaultHTTPCodecFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | #include 11 | #include 12 | 13 | namespace proxygen { 14 | class HeaderIndexingStrategy; 15 | 16 | class DefaultHTTPCodecFactory : public HTTPCodecFactory { 17 | public: 18 | DefaultHTTPCodecFactory() = default; 19 | explicit DefaultHTTPCodecFactory(CodecConfig config); 20 | ~DefaultHTTPCodecFactory() override = default; 21 | 22 | /** 23 | * Get a codec instance 24 | */ 25 | std::unique_ptr getCodec(const std::string& nextProtocol, 26 | TransportDirection direction, 27 | bool isTLS) override; 28 | }; 29 | 30 | } // namespace proxygen 31 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/hq/HQLoggerHelper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | using namespace quic::samples; 12 | 13 | HQLoggerHelper::HQLoggerHelper(const std::string& path, 14 | bool pretty, 15 | quic::VantagePoint vantagePoint) 16 | : quic::FileQLogger(vantagePoint, 17 | quic::kHTTP3ProtocolType, 18 | path, 19 | pretty, 20 | false /* streaming */), 21 | outputPath_(path), 22 | pretty_(pretty) { 23 | } 24 | 25 | HQLoggerHelper::~HQLoggerHelper() { 26 | try { 27 | outputLogsToFile(outputPath_, pretty_); 28 | } catch (...) { 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/HPACKEncoderBase.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | namespace proxygen { 12 | 13 | uint32_t HPACKEncoderBase::handlePendingContextUpdate(HPACKEncodeBuffer& buf, 14 | uint32_t tableCapacity) { 15 | CHECK_EQ(HPACK::TABLE_SIZE_UPDATE.code, HPACK::Q_TABLE_SIZE_UPDATE.code) 16 | << "Code assumes these are equal"; 17 | uint32_t encoded = 0; 18 | if (pendingContextUpdate_) { 19 | VLOG(5) << "Encoding table size update size=" << tableCapacity; 20 | encoded = buf.encodeInteger(tableCapacity, HPACK::TABLE_SIZE_UPDATE); 21 | pendingContextUpdate_ = false; 22 | } 23 | 24 | return encoded; 25 | } 26 | 27 | } // namespace proxygen 28 | -------------------------------------------------------------------------------- /proxygen/lib/stats/gen_StatsWrapper.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. 3 | # All rights reserved. 4 | # 5 | # This source code is licensed under the BSD-style license found in the 6 | # LICENSE file in the root directory of this source tree. 7 | 8 | set -e 9 | 10 | if [ "x$1" != "x" ];then 11 | OUTPUT_DIR="$1" 12 | fi 13 | 14 | statsWrapper=$(cat < 24 | 25 | #pragma once 26 | 27 | namespace proxygen { 28 | 29 | using StatsWrapper = proxygen::BaseStats; 30 | 31 | } // proxygen 32 | EOF 33 | ) 34 | 35 | touch "${OUTPUT_DIR?}/proxygen/lib/stats/StatsWrapper.h" 36 | echo "$statsWrapper" > "${OUTPUT_DIR?}/proxygen/lib/stats/StatsWrapper.h" 37 | 38 | echo "Generated StatsWrapper.h" 39 | -------------------------------------------------------------------------------- /proxygen/lib/utils/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | proxygen_add_test(TARGET AsyncTimeoutSetTest 8 | SOURCES 9 | AsyncTimeoutSetTest.cpp 10 | DEPENDS 11 | proxygen 12 | testmain 13 | ) 14 | 15 | proxygen_add_test(TARGET TraceEventTest 16 | SOURCES 17 | TraceEventTest.cpp 18 | DEPENDS 19 | proxygen 20 | testmain 21 | ) 22 | 23 | proxygen_add_test(TARGET UtilTests 24 | SOURCES 25 | ConditionalGateTest.cpp 26 | CryptUtilTest.cpp 27 | GenericFilterTest.cpp 28 | HTTPTimeTest.cpp 29 | LoggingTests.cpp 30 | ParseURLTest.cpp 31 | PerfectIndexMapTest.cpp 32 | RendezvousHashTest.cpp 33 | TimeTest.cpp 34 | UtilTest.cpp 35 | WeakRefCountedPtrTest.cpp 36 | ZlibTests.cpp 37 | #ZstdTests.cpp 38 | DEPENDS 39 | proxygen 40 | testmain 41 | ) 42 | -------------------------------------------------------------------------------- /proxygen/lib/http/HTTPConstants.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | namespace proxygen { 12 | 13 | #define CONNECTION_CLOSE_REASON_STRING(e, r) r, 14 | const char* connectionCloseStrings[] = { 15 | CONNECTION_CLOSE_REASON_GEN(CONNECTION_CLOSE_REASON_STRING)}; 16 | #undef CONNECTION_CLOSE_REASON_STRING 17 | 18 | const char* getConnectionCloseReasonStringByIndex(unsigned int index) { 19 | if (index >= (unsigned int)ConnectionCloseReason::kMAX_REASON) { 20 | index = (unsigned int)ConnectionCloseReason::kMAX_REASON - 1; 21 | } 22 | 23 | return connectionCloseStrings[index]; 24 | } 25 | 26 | const char* getConnectionCloseReasonString(ConnectionCloseReason r) { 27 | return connectionCloseStrings[(unsigned int)r]; 28 | } 29 | 30 | } // namespace proxygen 31 | -------------------------------------------------------------------------------- /proxygen/lib/http/webtransport/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | add_library( 8 | quicwebtransport 9 | QuicWebTransport.cpp 10 | ) 11 | add_dependencies( 12 | quicwebtransport 13 | proxygen 14 | ) 15 | target_include_directories( 16 | quicwebtransport PUBLIC 17 | $ 18 | $ 19 | $ 20 | ${LIBGMOCK_INCLUDE_DIR} 21 | ${LIBGTEST_INCLUDE_DIR} 22 | ) 23 | target_compile_options( 24 | quicwebtransport PRIVATE 25 | ${_PROXYGEN_COMMON_COMPILE_OPTIONS} 26 | ) 27 | target_link_libraries(quicwebtransport PUBLIC proxygen) 28 | install( 29 | TARGETS quicwebtransport 30 | EXPORT proxygen-exports 31 | ARCHIVE DESTINATION ${LIB_INSTALL_DIR} 32 | LIBRARY DESTINATION ${LIB_INSTALL_DIR} 33 | ) 34 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/HTTPErrorPage.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | using std::string; 14 | 15 | namespace proxygen { 16 | 17 | HTTPStaticErrorPage::HTTPStaticErrorPage(std::unique_ptr content, 18 | const string& contentType) 19 | : content_(std::move(content)), contentType_(contentType) { 20 | } 21 | 22 | HTTPErrorPage::Page HTTPStaticErrorPage::generate( 23 | uint64_t /*requestID*/, 24 | unsigned /*httpStatusCode*/, 25 | const std::string& /*reason*/, 26 | std::unique_ptr /*body*/, 27 | const std::string& /*detailReason*/) const { 28 | 29 | return HTTPErrorPage::Page(contentType_, content_->clone()); 30 | } 31 | 32 | } // namespace proxygen 33 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/HPACKStreamingCallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace proxygen { namespace HPACK { 16 | class StreamingCallback { 17 | public: 18 | virtual ~StreamingCallback() { 19 | } 20 | 21 | virtual void onHeader(const HPACKHeaderName& name, 22 | const folly::fbstring& value) = 0; 23 | virtual void onHeadersComplete(HTTPHeaderSize decodedSize, 24 | bool acknowledge) = 0; 25 | virtual void onDecodeError(HPACK::DecodeError decodeError) = 0; 26 | HeaderCodec::Stats* stats{nullptr}; 27 | }; 28 | 29 | }} // namespace proxygen::HPACK 30 | -------------------------------------------------------------------------------- /proxygen/httpserver/SignalHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | class HTTPServer; 17 | 18 | /** 19 | * Installs signal handler which will stop HTTPServer when the user presses 20 | * Ctrl-C. To be used if HTTPServer is the main process. 21 | * 22 | * Note: Should only be created from the thread invoking `HTTPServer::start()`. 23 | */ 24 | class SignalHandler : private folly::AsyncSignalHandler { 25 | public: 26 | explicit SignalHandler(HTTPServer* server); 27 | 28 | void install(const std::vector& signals); 29 | 30 | private: 31 | // AsyncSignalHandler 32 | void signalReceived(int signum) noexcept override; 33 | 34 | HTTPServer* const server_{nullptr}; 35 | }; 36 | 37 | } // namespace proxygen 38 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/ByteEvents.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace proxygen { 18 | 19 | const char* const kTypeStrings[] = { 20 | "FIRST_BYTE", 21 | "LAST_BYTE", 22 | "PING_REPLY_SENT", 23 | "FIRST_HEADER_BYTE", 24 | "TRACKED_BYTE", 25 | "SECOND_TO_LAST_PACKET", 26 | }; 27 | 28 | std::ostream& operator<<(std::ostream& os, const ByteEvent& be) { 29 | os << folly::to( 30 | "(", kTypeStrings[be.eventType_], ", ", be.byteOffset_, ")"); 31 | return os; 32 | } 33 | 34 | int64_t PingByteEvent::getLatency() { 35 | return millisecondsSince(pingRequestReceivedTime_).count(); 36 | } 37 | 38 | } // namespace proxygen 39 | -------------------------------------------------------------------------------- /proxygen/lib/transport/PersistentQuicTokenCache.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | namespace proxygen { 12 | 13 | PersistentQuicTokenCache::PersistentQuicTokenCache( 14 | const std::string& filename, wangle::PersistentCacheConfig config) 15 | : cache_(filename, std::move(config)) { 16 | } 17 | 18 | folly::Optional PersistentQuicTokenCache::getToken( 19 | const std::string& hostname) { 20 | return cache_.get(hostname); 21 | } 22 | 23 | void PersistentQuicTokenCache::putToken(const std::string& hostname, 24 | std::string token) { 25 | cache_.put(hostname, token); 26 | } 27 | 28 | void PersistentQuicTokenCache::removeToken(const std::string& hostname) { 29 | cache_.remove(hostname); 30 | } 31 | 32 | } // namespace proxygen 33 | -------------------------------------------------------------------------------- /proxygen/lib/transport/test/MockAsyncTransportCertificate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace proxygen { 16 | 17 | class MockAsyncTransportCertificate : public folly::AsyncTransportCertificate { 18 | public: 19 | MOCK_METHOD(std::string, getIdentity, (), (const, override)); 20 | MOCK_METHOD(std::optional, getDER, (), (const, override)); 21 | }; 22 | 23 | class MockOpenSSLTransportCertificate 24 | : public folly::OpenSSLTransportCertificate { 25 | public: 26 | MOCK_METHOD(folly::ssl::X509UniquePtr, getX509, (), (const, override)); 27 | MOCK_METHOD(std::string, getIdentity, (), (const, override)); 28 | }; 29 | 30 | } // namespace proxygen 31 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/hq/FizzContext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace quic::samples { 17 | 18 | using FizzServerContextPtr = 19 | std::shared_ptr; 20 | 21 | using FizzClientContextPtr = std::shared_ptr; 22 | 23 | FizzServerContextPtr createFizzServerContext(const HQServerParams& params); 24 | 25 | FizzClientContextPtr createFizzClientContext(const HQBaseParams& params, 26 | bool earlyData); 27 | 28 | wangle::SSLContextConfig createSSLContext(const HQBaseParams& params); 29 | } // namespace quic::samples 30 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/test/HeaderPieceTests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace proxygen::compress; 14 | 15 | class HeaderPieceTests : public testing::Test {}; 16 | 17 | TEST_F(HeaderPieceTests, Basic) { 18 | HeaderPiece *hp; 19 | 20 | // creating non-owner piece with null pointer 21 | hp = new HeaderPiece(nullptr, 0, false, true); 22 | EXPECT_TRUE(hp->isMultiValued()); 23 | // destructing this should be fine, since will not try to release the memory 24 | delete hp; 25 | 26 | char *buf = new char[16]; 27 | hp = new HeaderPiece(buf, 16, true, true); 28 | EXPECT_EQ(hp->str.data(), buf); 29 | EXPECT_EQ(hp->str.size(), 16); 30 | // this should release the mem 31 | delete hp; 32 | } 33 | -------------------------------------------------------------------------------- /proxygen/lib/http/structuredheaders/StructuredHeadersUtilities.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #pragma once 13 | 14 | namespace proxygen { namespace StructuredHeaders { 15 | 16 | bool isLcAlpha(char c); 17 | 18 | bool isValidIdentifierChar(char c); 19 | 20 | bool isValidEncodedBinaryContentChar(char c); 21 | 22 | bool isValidStringChar(char c); 23 | 24 | bool isValidIdentifier(const std::string& s); 25 | 26 | bool isValidString(const std::string& s); 27 | 28 | bool isValidEncodedBinaryContent(const std::string& s); 29 | 30 | bool itemTypeMatchesContent(const StructuredHeaderItem& input); 31 | 32 | std::string decodeBase64(const std::string& encoded); 33 | 34 | std::string encodeBase64(const std::string& input); 35 | 36 | }} // namespace proxygen::StructuredHeaders 37 | -------------------------------------------------------------------------------- /proxygen/lib/http/observer/HTTPSessionObserverContainer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | using HTTPSessionObserverContainerBaseT = folly::ObserverContainer< 17 | HTTPSessionObserverInterface, 18 | HTTPSessionObserverAccessor, 19 | folly::ObserverContainerBasePolicyDefault< 20 | HTTPSessionObserverInterface::Events /* EventEnum */, 21 | 32 /* BitsetSize (max number of interface events) */>>; 22 | 23 | class HTTPSessionObserverContainer : public HTTPSessionObserverContainerBaseT { 24 | 25 | using HTTPSessionObserverContainerBaseT::HTTPSessionObserverContainerBaseT; 26 | 27 | public: 28 | ~HTTPSessionObserverContainer() override = default; 29 | }; 30 | 31 | } // namespace proxygen 32 | -------------------------------------------------------------------------------- /proxygen/lib/transport/PersistentQuicTokenCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace proxygen { 17 | 18 | class PersistentQuicTokenCache : public quic::QuicTokenCache { 19 | public: 20 | PersistentQuicTokenCache(const std::string& filename, 21 | wangle::PersistentCacheConfig config); 22 | 23 | [[nodiscard]] folly::Optional getToken( 24 | const std::string& hostname) override; 25 | 26 | void putToken(const std::string& hostname, std::string token) override; 27 | 28 | void removeToken(const std::string&) override; 29 | 30 | private: 31 | wangle::FilePersistentCache cache_; 32 | }; 33 | 34 | } // namespace proxygen 35 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/NoPathIndexingStrategy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | class NoPathIndexingStrategy : public HeaderIndexingStrategy { 16 | public: 17 | static const NoPathIndexingStrategy* getInstance(); 18 | 19 | NoPathIndexingStrategy() : HeaderIndexingStrategy() { 20 | } 21 | 22 | // For compression simulations we do not want to index :path headers 23 | bool indexHeader(const HPACKHeaderName& name, 24 | folly::StringPiece value, 25 | bool) const override { 26 | if (name.getHeaderCode() == HTTP_HEADER_COLON_PATH) { 27 | return false; 28 | } else { 29 | return HeaderIndexingStrategy::indexHeader(name, value); 30 | } 31 | } 32 | }; 33 | 34 | } // namespace proxygen 35 | -------------------------------------------------------------------------------- /proxygen/lib/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | if(NOT BUILD_TESTS) 8 | return() 9 | endif() 10 | 11 | add_library(testtransport TestAsyncTransport.cpp) 12 | target_include_directories( 13 | testtransport PUBLIC 14 | $ 15 | ${LIBGMOCK_INCLUDE_DIR} 16 | ${LIBGTEST_INCLUDE_DIR} 17 | ) 18 | target_compile_options( 19 | testtransport PRIVATE 20 | ${_PROXYGEN_COMMON_COMPILE_OPTIONS} 21 | ) 22 | target_link_libraries(testtransport PUBLIC proxygen) 23 | 24 | add_library(testmain TestMain.cpp) 25 | target_include_directories( 26 | testmain PUBLIC 27 | $ 28 | ${LIBGMOCK_INCLUDE_DIR} 29 | ${LIBGTEST_INCLUDE_DIR} 30 | ) 31 | target_link_libraries(testmain PUBLIC Folly::folly) 32 | target_compile_options( 33 | testmain PRIVATE 34 | ${_PROXYGEN_COMMON_COMPILE_OPTIONS} 35 | ) 36 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/echo/EchoStats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace EchoService { 14 | 15 | /** 16 | * Just some dummy class containing request count. Since we keep 17 | * one instance of this in each class, there is no need of 18 | * synchronization 19 | */ 20 | class EchoStats { 21 | public: 22 | virtual ~EchoStats() { 23 | } 24 | 25 | // NOTE: We make the following methods `virtual` so that we can 26 | // mock them using Gmock for our C++ unit-tests. EchoStats 27 | // is an external dependency to handler and we should be 28 | // able to mock it. 29 | 30 | virtual void recordRequest() { 31 | ++reqCount_; 32 | } 33 | 34 | virtual uint64_t getRequestCount() { 35 | return reqCount_; 36 | } 37 | 38 | private: 39 | uint64_t reqCount_{0}; 40 | }; 41 | 42 | } // namespace EchoService 43 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/push/PushStats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace PushService { 14 | 15 | /** 16 | * Just some dummy class containing request count. Since we keep 17 | * one instance of this in each class, there is no need of 18 | * synchronization 19 | */ 20 | class PushStats { 21 | public: 22 | virtual ~PushStats() { 23 | } 24 | 25 | // NOTE: We make the following methods `virtual` so that we can 26 | // mock them using Gmock for our C++ unit-tests. PushStats 27 | // is an external dependency to handler and we should be 28 | // able to mock it. 29 | 30 | virtual void recordRequest() { 31 | ++reqCount_; 32 | } 33 | 34 | virtual uint64_t getRequestCount() { 35 | return reqCount_; 36 | } 37 | 38 | private: 39 | uint64_t reqCount_{0}; 40 | }; 41 | 42 | } // namespace PushService 43 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/proxy/ProxyStats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace ProxyService { 14 | 15 | /** 16 | * Just some dummy class containing request count. Since we keep 17 | * one instance of this in each class, there is no need of 18 | * synchronization 19 | */ 20 | class ProxyStats { 21 | public: 22 | virtual ~ProxyStats() { 23 | } 24 | 25 | // NOTE: We make the following methods `virtual` so that we can 26 | // mock them using Gmock for our C++ unit-tests. ProxyStats 27 | // is an external dependency to handler and we should be 28 | // able to mock it. 29 | 30 | virtual void recordRequest() { 31 | ++reqCount_; 32 | } 33 | 34 | virtual uint64_t getRequestCount() { 35 | return reqCount_; 36 | } 37 | 38 | private: 39 | uint64_t reqCount_{0}; 40 | }; 41 | 42 | } // namespace ProxyService 43 | -------------------------------------------------------------------------------- /proxygen/lib/dns/test/SyncDNSResolverTest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | #include "proxygen/lib/dns/SyncDNSResolver.h" 15 | #include "proxygen/lib/dns/test/MockDNSResolver.h" 16 | 17 | namespace proxygen { 18 | 19 | class SyncDNSResolverTest : public testing::Test { 20 | public: 21 | void SetUp() override { 22 | resolver_ = new MockDNSResolver(); 23 | syncResolver_ = 24 | std::make_unique(DNSResolver::UniquePtr(resolver_)); 25 | evb_ = syncResolver_->getEventBase(); 26 | } 27 | 28 | void TearDown() override { 29 | syncResolver_.reset(); 30 | evb_ = nullptr; 31 | } 32 | 33 | protected: 34 | MockDNSResolver* resolver_; // unowned 35 | std::unique_ptr syncResolver_; 36 | folly::EventBase* evb_; 37 | }; 38 | 39 | } // namespace proxygen 40 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/TransportDirection.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | const char* getTransportDirectionString(TransportDirection dir) { 16 | switch (dir) { 17 | case TransportDirection::UPSTREAM: 18 | return "upstream"; 19 | case TransportDirection::DOWNSTREAM: 20 | return "downstream"; 21 | } 22 | // unreachable 23 | return ""; 24 | } 25 | 26 | TransportDirection operator!(TransportDirection dir) { 27 | return dir == TransportDirection::DOWNSTREAM ? TransportDirection::UPSTREAM 28 | : TransportDirection::DOWNSTREAM; 29 | } 30 | 31 | std::ostream& operator<<(std::ostream& os, const TransportDirection dir) { 32 | os << getTransportDirectionString(dir); 33 | return os; 34 | } 35 | 36 | } // namespace proxygen 37 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/TTLBAStats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | namespace proxygen { 12 | 13 | class TTLBAStats { 14 | public: 15 | virtual ~TTLBAStats() noexcept { 16 | } 17 | 18 | virtual void recordPresendIOSplit() noexcept = 0; 19 | virtual void recordPresendExceedLimit() noexcept = 0; 20 | virtual void recordTTLBAExceedLimit() noexcept = 0; 21 | virtual void recordTTLBANotFound() noexcept = 0; 22 | virtual void recordTTLBAReceived() noexcept = 0; 23 | virtual void recordTTLBATimeout() noexcept = 0; 24 | virtual void recordTTLBATracked() noexcept = 0; 25 | virtual void recordTTBTXExceedLimit() noexcept = 0; 26 | virtual void recordTTBTXReceived() noexcept = 0; 27 | virtual void recordTTBTXTimeout() noexcept = 0; 28 | virtual void recordTTBTXNotFound() noexcept = 0; 29 | virtual void recordTTBTXTracked() noexcept = 0; 30 | }; 31 | 32 | } // namespace proxygen 33 | -------------------------------------------------------------------------------- /proxygen/lib/utils/test/MockTime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | template 17 | class MockTimeUtilGeneric : public TimeUtilGeneric { 18 | public: 19 | void advance(std::chrono::milliseconds ms) { 20 | t_ += ms; 21 | } 22 | 23 | void setCurrentTime(std::chrono::time_point t) { 24 | CHECK(t.time_since_epoch() > t_.time_since_epoch()) 25 | << "Time can not move backwards"; 26 | t_ = t; 27 | } 28 | 29 | void verifyAndClear() { 30 | } 31 | 32 | std::chrono::time_point now() const override { 33 | return t_; 34 | } 35 | 36 | private: 37 | std::chrono::time_point t_; 38 | }; 39 | 40 | using MockTimeUtil = MockTimeUtilGeneric<>; 41 | 42 | } // namespace proxygen 43 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/proxy/SessionWrapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace ProxyService { 14 | class SessionWrapper : public proxygen::HTTPSession::InfoCallback { 15 | private: 16 | proxygen::HTTPUpstreamSession* session_{nullptr}; 17 | 18 | public: 19 | explicit SessionWrapper(proxygen::HTTPUpstreamSession* session) 20 | : session_(session) { 21 | session_->setInfoCallback(this); 22 | } 23 | 24 | ~SessionWrapper() override { 25 | if (session_) { 26 | session_->drain(); 27 | } 28 | } 29 | 30 | proxygen::HTTPUpstreamSession* operator->() const { 31 | return session_; 32 | } 33 | 34 | // Note: you must not start any asynchronous work from onDestroy() 35 | void onDestroy(const proxygen::HTTPSessionBase&) override { 36 | session_ = nullptr; 37 | } 38 | }; 39 | 40 | } // namespace ProxyService 41 | -------------------------------------------------------------------------------- /proxygen/lib/http/SynchronizedLruQuicPskCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace proxygen { 16 | 17 | class SynchronizedLruQuicPskCache : public quic::QuicPskCache { 18 | public: 19 | ~SynchronizedLruQuicPskCache() override = default; 20 | 21 | explicit SynchronizedLruQuicPskCache(uint64_t mapMax); 22 | 23 | folly::Optional getPsk( 24 | const std::string& identity) override; 25 | 26 | void putPsk(const std::string& identity, quic::QuicCachedPsk psk) override; 27 | 28 | void removePsk(const std::string& identity) override; 29 | 30 | private: 31 | using EvictingPskMap = 32 | folly::EvictingCacheMap; 33 | folly::Synchronized cache_; 34 | }; 35 | 36 | } // namespace proxygen 37 | -------------------------------------------------------------------------------- /proxygen/lib/sampling/Sampled.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | /** 16 | * implements the concept of a sampled object, which maintains the side effects 17 | * of using a sampling object. Designed to be inherited. 18 | */ 19 | class Sampled { 20 | 21 | public: 22 | Sampled() { 23 | } 24 | 25 | explicit Sampled(const Sampling& sampling) { 26 | sample(sampling); 27 | } 28 | 29 | virtual ~Sampled() { 30 | } 31 | 32 | void sample(const Sampling& sampling) { 33 | if (sampling.isLucky()) { 34 | samplingWeight_ = sampling.getWeight(); 35 | } 36 | } 37 | 38 | uint32_t getSamplingWeight() const { 39 | return samplingWeight_; 40 | } 41 | 42 | bool isSampled() const { 43 | return samplingWeight_ > 0; 44 | } 45 | 46 | protected: 47 | uint32_t samplingWeight_{0}; 48 | }; 49 | 50 | } // namespace proxygen 51 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/HTTPCodecFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | std::unique_ptr HTTPCodecFactory::getCodec( 17 | CodecProtocol protocol, 18 | TransportDirection direction, 19 | bool strictValidation) { 20 | // Static m 21 | switch (protocol) { 22 | case CodecProtocol::HTTP_1_1: 23 | return std::make_unique( 24 | direction, /*force_1_1=*/false, strictValidation); 25 | case CodecProtocol::HTTP_2: { 26 | auto codec = std::make_unique(direction); 27 | codec->setStrictValidation(strictValidation); 28 | return codec; 29 | } 30 | default: 31 | LOG(FATAL) << "Unreachable"; 32 | return nullptr; 33 | } 34 | } 35 | 36 | } // namespace proxygen 37 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/echo/EchoHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | class ResponseHandler; 16 | } 17 | 18 | namespace EchoService { 19 | 20 | class EchoStats; 21 | 22 | class EchoHandler : public proxygen::RequestHandler { 23 | public: 24 | explicit EchoHandler(EchoStats* stats); 25 | 26 | void onRequest( 27 | std::unique_ptr headers) noexcept override; 28 | 29 | void onBody(std::unique_ptr body) noexcept override; 30 | 31 | void onEOM() noexcept override; 32 | 33 | void onUpgrade(proxygen::UpgradeProtocol proto) noexcept override; 34 | 35 | void requestComplete() noexcept override; 36 | 37 | void onError(proxygen::ProxygenError err) noexcept override; 38 | 39 | private: 40 | EchoStats* const stats_{nullptr}; 41 | }; 42 | 43 | } // namespace EchoService 44 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/test/HTTPArchive.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace proxygen { 20 | 21 | class HTTPArchive { 22 | public: 23 | std::vector requests; 24 | std::vector responses; 25 | 26 | static std::vector> convertToHPACK( 27 | const std::vector& msgs); 28 | 29 | static std::unique_ptr fromFile(const std::string& filename); 30 | 31 | static std::unique_ptr fromPublicFile(const std::string& fname); 32 | 33 | static uint32_t getSize(const HTTPMessage& msg); 34 | static uint32_t getSize(const std::vector& headers); 35 | }; 36 | } // namespace proxygen 37 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/hq/InsecureVerifierDangerousDoNotUseInProduction.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | // This is an insecure certificate verifier and is not meant to be 16 | // used in production. Using it in production would mean that this will 17 | // leave everyone insecure. 18 | class InsecureVerifierDangerousDoNotUseInProduction 19 | : public fizz::CertificateVerifier { 20 | public: 21 | ~InsecureVerifierDangerousDoNotUseInProduction() override = default; 22 | 23 | std::shared_ptr verify( 24 | const std::vector>& certs) 25 | const override { 26 | return certs.front(); 27 | } 28 | 29 | std::vector getCertificateRequestExtensions() 30 | const override { 31 | return std::vector(); 32 | } 33 | }; 34 | } // namespace proxygen 35 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/HTTPChecks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | /** 16 | * This class enforces certain higher-level HTTP semantics. It does not enforce 17 | * conditions that require state to decide. That is, this class is stateless and 18 | * only examines the calls and callbacks that go through it. 19 | */ 20 | 21 | class HTTPChecks : public PassThroughHTTPCodecFilter { 22 | public: 23 | // HTTPCodec::Callback methods 24 | 25 | void onHeadersComplete(StreamID stream, 26 | std::unique_ptr msg) override; 27 | 28 | // HTTPCodec methods 29 | 30 | void generateHeader( 31 | folly::IOBufQueue& writeBuf, 32 | StreamID stream, 33 | const HTTPMessage& msg, 34 | bool eom, 35 | HTTPHeaderSize* sizeOut, 36 | const folly::Optional& extraHeaders = folly::none) override; 37 | }; 38 | 39 | } // namespace proxygen 40 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | if(NOT BUILD_TESTS) 8 | return() 9 | endif() 10 | 11 | add_library(hpacktestutils TestUtil.cpp) 12 | target_include_directories( 13 | hpacktestutils PUBLIC 14 | $ 15 | ${LIBGMOCK_INCLUDE_DIR} 16 | ${LIBGTEST_INCLUDE_DIR} 17 | ) 18 | target_compile_options( 19 | hpacktestutils PRIVATE 20 | ${_PROXYGEN_COMMON_COMPILE_OPTIONS} 21 | ) 22 | target_link_libraries(hpacktestutils PUBLIC proxygen) 23 | 24 | proxygen_add_test(TARGET HPACKTests 25 | SOURCES 26 | HeaderPieceTests.cpp 27 | HeaderTableTests.cpp 28 | HTTPArchive.cpp 29 | HPACKBufferTests.cpp 30 | HPACKCodecTests.cpp 31 | HPACKContextTests.cpp 32 | HPACKHeaderTests.cpp 33 | HuffmanTests.cpp 34 | LoggingTests.cpp 35 | QPACKCodecTests.cpp 36 | QPACKContextTests.cpp 37 | QPACKHeaderTableTests.cpp 38 | RFCExamplesTests.cpp 39 | DEPENDS 40 | hpacktestutils 41 | proxygen 42 | testmain 43 | ) 44 | -------------------------------------------------------------------------------- /proxygen/lib/services/Service.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace proxygen { 16 | 17 | Service::Service() { 18 | } 19 | 20 | Service::~Service() { 21 | } 22 | 23 | void Service::addServiceWorker(std::unique_ptr worker, 24 | RequestWorkerThread* reqWorker) { 25 | reqWorker->addServiceWorker(this, worker.get()); 26 | workers_.emplace_back(std::move(worker)); 27 | } 28 | 29 | void Service::addServiceWorker(std::unique_ptr worker, 30 | RequestWorkerThreadNoExecutor* reqWorker) { 31 | reqWorker->addServiceWorker(this, worker.get()); 32 | workers_.emplace_back(std::move(worker)); 33 | } 34 | 35 | void Service::clearServiceWorkers() { 36 | workers_.clear(); 37 | } 38 | 39 | } // namespace proxygen 40 | -------------------------------------------------------------------------------- /proxygen/lib/http/HTTPMessageFilters.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | namespace proxygen { 12 | 13 | void HTTPMessageFilter::pause() noexcept { 14 | if (nextElementIsPaused_) { 15 | return; 16 | } 17 | 18 | nextElementIsPaused_ = true; 19 | 20 | if (prev_.which() == 0) { 21 | auto prev = boost::get(prev_); 22 | if (prev) { 23 | prev->pause(); 24 | } 25 | } else { 26 | auto prev = boost::get(prev_); 27 | if (prev) { 28 | prev->pauseIngress(); 29 | } 30 | } 31 | } 32 | 33 | void HTTPMessageFilter::resume(uint64_t offset) noexcept { 34 | nextElementIsPaused_ = false; 35 | if (prev_.which() == 0) { 36 | auto prev = boost::get(prev_); 37 | if (prev) { 38 | prev->resume(offset); 39 | } 40 | } else { 41 | auto prev = boost::get(prev_); 42 | if (prev) { 43 | prev->resumeIngress(); 44 | } 45 | } 46 | } 47 | 48 | } // namespace proxygen 49 | -------------------------------------------------------------------------------- /proxygen/lib/ssl/ProxygenSSL.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | class ProxygenSSL { 17 | public: 18 | static int getSSLAppContextConfigIndex() { 19 | static auto index = [] { 20 | auto idx = 21 | SSL_CTX_get_ex_new_index(0, 22 | (void*)"proxygen client context config", 23 | nullptr, 24 | nullptr, 25 | nullptr); 26 | CHECK(idx >= 0); 27 | return idx; 28 | }(); 29 | return index; 30 | } 31 | 32 | static int getSSLAppContextStatsIndex() { 33 | static auto index = [] { 34 | auto idx = SSL_CTX_get_ex_new_index( 35 | 0, (void*)"proxygen wangle::SSLStats", nullptr, nullptr, nullptr); 36 | CHECK(idx >= 0); 37 | return idx; 38 | }(); 39 | return index; 40 | } 41 | }; 42 | 43 | } // namespace proxygen 44 | -------------------------------------------------------------------------------- /proxygen/lib/http/connpool/ThreadIdleSessionController.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | namespace proxygen { 12 | 13 | ThreadIdleSessionController::ThreadIdleSessionController( 14 | uint32_t totalIdleSessions) 15 | : totalIdleSessions_(totalIdleSessions) { 16 | } 17 | 18 | void ThreadIdleSessionController::onAttachIdle(SessionHolder* holder) { 19 | idleSessionsLRU_.push_back(*holder); 20 | purgeExcessIdleSessions(); 21 | } 22 | 23 | void ThreadIdleSessionController::onDetachIdle(SessionHolder* holder) { 24 | idleSessionsLRU_.erase(idleSessionsLRU_.iterator_to(*holder)); 25 | } 26 | 27 | void ThreadIdleSessionController::purgeExcessIdleSessions() { 28 | while (idleSessionsLRU_.size() > totalIdleSessions_) { 29 | SessionHolder& holder = idleSessionsLRU_.front(); 30 | holder.drain(); 31 | } 32 | } 33 | 34 | uint32_t ThreadIdleSessionController::getTotalIdleSessions() const { 35 | return idleSessionsLRU_.size(); 36 | } 37 | } // namespace proxygen 38 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/HQByteEventTracker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | /** 17 | * ByteEventTracker specialized for HQSession. 18 | */ 19 | class HQByteEventTracker : public ByteEventTracker { 20 | public: 21 | HQByteEventTracker(Callback* callback, 22 | quic::QuicSocket* socket, 23 | quic::StreamId streamId); 24 | 25 | /** 26 | * Called when a ByteEvent offset has been written to the socket. 27 | * 28 | * Triggered by processByteEvents. 29 | * 30 | * HQByteEventTracker implementation registers callbacks for TX and ACK events 31 | * with the underlying QuicSocket when certain ByteEvents are written. 32 | */ 33 | void onByteEventWrittenToSocket(const ByteEvent& event) override; 34 | 35 | private: 36 | quic::QuicSocket* const socket_; 37 | const quic::StreamId streamId_; 38 | }; 39 | 40 | } // namespace proxygen 41 | -------------------------------------------------------------------------------- /proxygen/lib/utils/HTTPTime.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | folly::Optional parseHTTPDateTime(const std::string& s) { 16 | struct tm tm = {}; 17 | 18 | if (s.empty()) { 19 | return folly::none; 20 | } 21 | 22 | // Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 23 | // Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 24 | // Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format 25 | // Assume GMT as per rfc2616 (see HTTP-date): 26 | // - https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html 27 | if (strptime(s.c_str(), "%a, %d %b %Y %H:%M:%S GMT", &tm) != nullptr || 28 | strptime(s.c_str(), "%a, %d-%b-%y %H:%M:%S GMT", &tm) != nullptr || 29 | strptime(s.c_str(), "%a %b %d %H:%M:%S %Y", &tm) != nullptr) { 30 | return folly::Optional(timegm(&tm)); 31 | } 32 | 33 | return folly::none; 34 | } 35 | 36 | } // namespace proxygen 37 | -------------------------------------------------------------------------------- /proxygen/httpserver/tests/certs/client_cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDMDCCAhigAwIBAgIBCjANBgkqhkiG9w0BAQsFADAnMSUwIwYDVQQDDBxBc294 3 | IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MCAXDTI0MDYwNzIxMzAyNFoYDzIxMjQw 4 | NTE0MjEzMDI0WjAUMRIwEAYDVQQDDAl0ZXN0dXNlcjEwggEiMA0GCSqGSIb3DQEB 5 | AQUAA4IBDwAwggEKAoIBAQCsJuwQ/NCdFkJ9WcR2JVBOKRYjCHcOs4EEzbp/eAzs 6 | 3FiQyrTMLC6zLolILa6NOxFHSy9KLMPDXtlAI8gIW6GhIVFuCQHnUn2CBwu19CBc 7 | H8jRMw9xkJQljs5H1oIXeSzKvd6QgHeUvt4kJzMYrmHbuaGNKL7SPkRf+f6pjja6 8 | p+w47OFWbj/S31rktDXFZXi3gusAaRixFeXxd7Sl6D1EiznkRemzVc4NDkubFXqd 9 | AREscX0KN5CEKCuOm0aByeMZQ5SzAqcm6Gdtq85DqYvZ1z+VnjszauylJ21jTuFR 10 | D5LVEzWr3e0EsNQd2SyxIuxvrAMukmQpuXM4trV1bDDhAgMBAAGjeDB2MAwGA1Ud 11 | EwEB/wQCMAAwHQYDVR0OBBYEFBUUGlHHCz0eUE7Yyf9pMOZ5IGJwMB8GA1UdIwQY 12 | MBaAFGW5mAAuvah4WzqcNFwW/jA9+6epMA4GA1UdDwEB/wQEAwIF4DAWBgNVHSUB 13 | Af8EDDAKBggrBgEFBQcDAjANBgkqhkiG9w0BAQsFAAOCAQEADG0ZnxDnrYXPpvzy 14 | YpmyBYJPTBtq+icSn1aAr2FXgz/RXOolDxxwHOIaODamWbdvvveB1rQNgsG64KBM 15 | SQ8qNeV0fhoFi4ocb8QhE5/GFdkqwXaSZWyFxrfohoGj3dml30Umr+EmsBPj2HSi 16 | l/dc6JXtv78AjssFaqESnMYYLyVDupPmJ74P11xoG0YvdFeHIV8keQ0nbj78GCY7 17 | h7U14YR1OcW+t697JI5fbwlWIf2s3uiGu6RtXO/oDDxSwM7Ei8BmB1CPytOSDrx3 18 | VmtYcjX3idT8IWXHOD6lyYAgaRcmXb7XSodl1lWu4RkNnmwbvFLQ/i0pPZuWxBSS 19 | wVtuyA== 20 | -----END CERTIFICATE----- 21 | -------------------------------------------------------------------------------- /cmake/FindZstd.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | # - Find zstd 8 | # Find the zstd compression library and includes 9 | # 10 | # ZSTD_INCLUDE_DIR - where to find zstd.h, etc. 11 | # ZSTD_LIBRARIES - List of libraries when using zstd. 12 | # ZSTD_FOUND - True if zstd found. 13 | 14 | find_path(ZSTD_INCLUDE_DIR 15 | NAMES zstd.h 16 | HINTS ${ZSTD_ROOT_DIR}/include) 17 | 18 | find_library(ZSTD_LIBRARIES 19 | NAMES zstd 20 | HINTS ${ZSTD_ROOT_DIR}/lib) 21 | 22 | include(FindPackageHandleStandardArgs) 23 | find_package_handle_standard_args(zstd DEFAULT_MSG ZSTD_LIBRARIES ZSTD_INCLUDE_DIR) 24 | 25 | mark_as_advanced( 26 | ZSTD_LIBRARIES 27 | ZSTD_INCLUDE_DIR 28 | ) 29 | 30 | if(NOT TARGET zstd) 31 | if("${ZSTD_LIBRARIES}" MATCHES ".*.a$") 32 | add_library(zstd STATIC IMPORTED) 33 | else() 34 | add_library(zstd SHARED IMPORTED) 35 | endif() 36 | set_target_properties( 37 | zstd 38 | PROPERTIES 39 | IMPORTED_LOCATION ${ZSTD_LIBRARIES} 40 | INTERFACE_INCLUDE_DIRECTORIES ${ZSTD_INCLUDE_DIR} 41 | ) 42 | endif() 43 | -------------------------------------------------------------------------------- /proxygen/lib/http/stats/ResponseCodeStatsMinute.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | using facebook::fb303::COUNT; 12 | 13 | namespace proxygen { 14 | 15 | ResponseCodeStatsMinute::ResponseCodeStatsMinute(const std::string& name) 16 | : statusOther(name + "other", COUNT), 17 | status1xx(name + "1xx", COUNT), 18 | status2xx(name + "2xx", COUNT), 19 | status3xx(name + "3xx", COUNT), 20 | status4xx(name + "4xx", COUNT), 21 | status5xx(name + "5xx", COUNT) { 22 | } 23 | 24 | void ResponseCodeStatsMinute::addStatus(int status) { 25 | if (status < 100) { 26 | statusOther.add(1); 27 | } else if (status < 200) { 28 | status1xx.add(1); 29 | } else if (status < 300) { 30 | status2xx.add(1); 31 | } else if (status < 400) { 32 | status3xx.add(1); 33 | } else if (status < 500) { 34 | status4xx.add(1); 35 | } else if (status < 600) { 36 | status5xx.add(1); 37 | } else { 38 | statusOther.add(1); 39 | } 40 | } 41 | 42 | } // namespace proxygen 43 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/push/PushRequestHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | class ResponseHandler; 16 | } 17 | 18 | namespace PushService { 19 | 20 | class PushStats; 21 | 22 | class PushRequestHandler : public proxygen::RequestHandler { 23 | public: 24 | explicit PushRequestHandler(PushStats* stats); 25 | 26 | void onRequest( 27 | std::unique_ptr headers) noexcept override; 28 | 29 | void onBody(std::unique_ptr body) noexcept override; 30 | 31 | void onEOM() noexcept override; 32 | 33 | void onUpgrade(proxygen::UpgradeProtocol proto) noexcept override; 34 | 35 | void requestComplete() noexcept override; 36 | 37 | void onError(proxygen::ProxygenError err) noexcept override; 38 | 39 | private: 40 | PushStats* const stats_{nullptr}; 41 | 42 | std::unique_ptr body_; 43 | 44 | proxygen::ResponseHandler* downstreamPush_{nullptr}; 45 | }; 46 | 47 | } // namespace PushService 48 | -------------------------------------------------------------------------------- /proxygen/lib/sampling/Sampling.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace proxygen { 18 | 19 | class Sampling { 20 | public: 21 | static const uint32_t kErrTolerance = 1000000; 22 | 23 | explicit Sampling(double rate = 1.0); 24 | virtual ~Sampling(); 25 | 26 | static uint32_t rateToWeight(double rate); 27 | 28 | static uint32_t rateToKey(double rate); 29 | 30 | static bool isLucky(uint32_t samplingKey); 31 | 32 | bool isLucky() const; 33 | 34 | bool isLucky(const std::string& key) const; 35 | bool isLucky(folly::StringPiece key) const; 36 | 37 | uint32_t getWeight() const { 38 | return weight_; 39 | } 40 | 41 | void updateRate(double rate); 42 | 43 | uint32_t getIntRate() const; 44 | 45 | void runSampled(folly::FunctionRef func) { 46 | if (isLucky()) { 47 | func(); 48 | } 49 | } 50 | 51 | private: 52 | double rate_{0.0}; 53 | uint32_t weight_{0}; 54 | }; 55 | 56 | } // namespace proxygen 57 | -------------------------------------------------------------------------------- /proxygen/lib/dns/NaiveResolutionCallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include "proxygen/lib/dns/DNSResolver.h" 18 | 19 | namespace proxygen { 20 | 21 | // Basic callback for name resolution 22 | class NaiveResolutionCallback : public DNSResolver::ResolutionCallback { 23 | public: 24 | typedef std::function&&, 25 | const folly::exception_wrapper&& ex)> 26 | Handler; 27 | 28 | // Return a DNSResolver::Exception(DNSResolver::NODATA) wrapper 29 | static folly::exception_wrapper makeNoNameException() noexcept; 30 | 31 | explicit NaiveResolutionCallback(Handler handler) : handler_(handler) { 32 | } 33 | 34 | void resolutionSuccess( 35 | std::vector answers) noexcept override; 36 | void resolutionError(const folly::exception_wrapper& exp) noexcept override; 37 | 38 | private: 39 | Handler handler_; 40 | }; 41 | 42 | } // namespace proxygen 43 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/test/HTTP2PriorityQueueBench.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | using namespace proxygen; 16 | 17 | namespace { 18 | static char* fakeTxn = (char*)0xface0000; 19 | 20 | const proxygen::HTTPCodec::StreamID kRootNodeId = 21 | std::numeric_limits::max(); 22 | 23 | proxygen::HTTPTransaction* makeFakeTxn(proxygen::HTTPCodec::StreamID id) { 24 | return (proxygen::HTTPTransaction*)(fakeTxn + id); 25 | } 26 | } // namespace 27 | 28 | BENCHMARK(Encode, iters) { 29 | HTTP2PriorityQueue q_(WheelTimerInstance(), kRootNodeId); 30 | uint64_t depth = 0; 31 | for (size_t i = 0; i < iters; ++i) { 32 | HTTPCodec::StreamID id = i * 2 + 1; 33 | q_.addTransaction( 34 | id, http2::DefaultPriority, makeFakeTxn(id), false, &depth); 35 | } 36 | } 37 | 38 | int main(int argc, char** argv) { 39 | gflags::ParseCommandLineFlags(&argc, &argv, true); 40 | folly::runBenchmarks(); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") 8 | message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") 9 | endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") 10 | 11 | file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) 12 | string(REGEX REPLACE "\n" ";" files "${files}") 13 | foreach(file ${files}) 14 | message(STATUS "Uninstalling $ENV{DESTDIR}${file}") 15 | if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 16 | exec_program( 17 | "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 18 | OUTPUT_VARIABLE rm_out 19 | RETURN_VALUE rm_retval 20 | ) 21 | if(NOT "${rm_retval}" STREQUAL 0) 22 | message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") 23 | endif(NOT "${rm_retval}" STREQUAL 0) 24 | else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 25 | message(STATUS "File $ENV{DESTDIR}${file} does not exist.") 26 | endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 27 | endforeach(file) 28 | -------------------------------------------------------------------------------- /proxygen/lib/http/HTTPHeaderSize.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | /** 16 | * A structure that encapsulates byte counters related to the HTTP headers. 17 | */ 18 | struct HTTPHeaderSize { 19 | /** 20 | * The number of bytes used to represent the header after compression or 21 | * before decompression. If header compression is not supported, the value 22 | * is set to 0. 23 | */ 24 | uint32_t compressed{0}; 25 | 26 | /** 27 | * The number of bytes used to represent the serialized header before 28 | * compression or after decompression, in plain-text format. 29 | */ 30 | uint32_t uncompressed{0}; 31 | 32 | /** 33 | * The number of bytes encoded as a compressed header block. 34 | * Header compression algorithms generate a header block plus some control 35 | * information. The `compressed` field accounts for both. So the control 36 | * information size can be computed as `compressed` - `compressedBlock` 37 | */ 38 | uint32_t compressedBlock{0}; 39 | }; 40 | 41 | } // namespace proxygen 42 | -------------------------------------------------------------------------------- /proxygen/lib/sampling/MultiSampled.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace proxygen { 17 | 18 | class MultiSampled { 19 | public: 20 | MultiSampled() { 21 | } 22 | 23 | virtual ~MultiSampled() { 24 | } 25 | 26 | void sample(const std::string& tag, const Sampling& sampling) { 27 | if (sampling.isLucky()) { 28 | weights_[tag] = sampling.getWeight(); 29 | } 30 | } 31 | 32 | int getSamplingWeight(const std::string& tag) const { 33 | auto it = weights_.find(tag); 34 | if (it == weights_.end()) { 35 | return 0; 36 | } 37 | return it->second; 38 | } 39 | 40 | bool isSampled() const { 41 | // we are sampled if we have at least a non-zero weight 42 | return weights_.size() > 0; 43 | } 44 | 45 | bool isSampled(const std::string& tag) const { 46 | return getSamplingWeight(tag) > 0; 47 | } 48 | 49 | private: 50 | folly::F14FastMap weights_; 51 | }; 52 | 53 | } // namespace proxygen 54 | -------------------------------------------------------------------------------- /proxygen/lib/utils/ConsistentHash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace proxygen { 16 | 17 | class ConsistentHash { 18 | public: 19 | virtual ~ConsistentHash() { 20 | } 21 | 22 | /** 23 | * build() builds the hashing pool based on a vector of nodes with their keys 24 | * and weights. 25 | * 26 | * The bevahior of calling build multiple times is undefined. 27 | * 28 | * build() is not thread safe with get(), documented below. 29 | */ 30 | virtual void build(std::vector> &) = 0; 31 | 32 | /** 33 | * get(key, N) finds the node ranked N in the consistent hashing space 34 | * for the given key. 35 | * 36 | * The returning value is the node's index in the input vector of build(). 37 | */ 38 | virtual size_t get(const uint64_t key, const size_t rank = 0) const = 0; 39 | 40 | /** 41 | * get max error rate the current hashing space 42 | * 43 | */ 44 | virtual double getMaxErrorRate() const = 0; 45 | }; 46 | } // namespace proxygen 47 | -------------------------------------------------------------------------------- /proxygen/httpserver/tests/certs/ca_cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDYDCCAkigAwIBAgIBATANBgkqhkiG9w0BAQsFADAnMSUwIwYDVQQDDBxBc294 3 | IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MCAXDTI0MDYwNzIxMzAyNFoYDzIxMjQw 4 | NTE0MjEzMDI0WjAnMSUwIwYDVQQDDBxBc294IENlcnRpZmljYXRpb24gQXV0aG9y 5 | aXR5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoLhS9NHgBJtApF/8 6 | M1PhWI2cBn0zapkJYDWSpk8XXCId/D/VJRWT5ufU0qSUibQJIzdZ1Ejw7YfvwEAV 7 | jERIUi7EqgT1xwyPOSiNJ92Hp4Hf4iePwHzorp5CfxAaKM4F9xiZ452dbE0t3gNO 8 | HvOCc1/063f02VC7Jzp/idZgln6CCipcBCJw0LWHlJlAnXM7Z/7Unnhw+IM2DZuK 9 | KULAeHHhDO91PyM7JiPV9l3RvhmdBXfYMVBZZcPqgix4jhW2HAQz9+2JGcbbxeLA 10 | 8TA1E9p6ofNeyVHPv7EOynbhAdyZ5tDiMKsRGJDv4K84blR8FIlggc6E1oS+5Ya/ 11 | LqZtTQIDAQABo4GUMIGRMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFNIqtvCq 12 | ljXBfJIVsQ9JWqrFdp/ZME8GA1UdIwRIMEaAFNIqtvCqljXBfJIVsQ9JWqrFdp/Z 13 | oSukKTAnMSUwIwYDVQQDDBxBc294IENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEB 14 | MA4GA1UdDwEB/wQEAwIBhjANBgkqhkiG9w0BAQsFAAOCAQEAnik394vCmmp9kxOw 15 | xxQCBAYt1JZpCqSAvC/GFsRpYrWnBCHojUcUBkVgElB7LbuzXtGpRBP5Qmrbq1T1 16 | 2QaEhJg24QH12JE1D7j3tdje/siNsMZyhtqxhVYPP/BzBWuCeio11qsPpFhIT6IT 17 | ZoDh5kKrpIrbOsFcHrI8EYDrGxfzh8zfVc+AD4v8LLnJZjR5HQgB49U0WN5orMMR 18 | mN0wXdMO8RQJ1XubtGP6jDusyepU3noUxPK5a+1VDxJX0CTcoOPnKUWZahwvTXcI 19 | ynyJ9z1q0cr9LguFA/35xlIips5beGbKucgkLp4MMXuXkvyLRuZ1q8tY0q7xjeRE 20 | W4BcCA== 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /proxygen/httpserver/tests/certs/test_cert1.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDYDCCAkigAwIBAgIBATANBgkqhkiG9w0BAQsFADAnMSUwIwYDVQQDDBxBc294 3 | IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MCAXDTI0MDYwNzIxMzAyNFoYDzIxMjQw 4 | NTE0MjEzMDI0WjAVMRMwEQYDVQQDDAp0ZXN0X2NlcnQxMIIBIjANBgkqhkiG9w0B 5 | AQEFAAOCAQ8AMIIBCgKCAQEA6HpcGHdbSuMsC2w4AW65yrR5oW6NKhRILUMMqyT8 6 | Yd16YUWVLKonmcqcJIobhvdeFe3VrPBSHj2pngPpfyPgxNRCBZm0D+ICSUoW8AYd 7 | ESl2H4f81+/msqyClWBlJHt9ZxN91Np+cGhjgYWhGv9e9yUM/FQlDZ4mOIWp9RSy 8 | WeCgEUVE56vCaq7+TdMrVH5sBFCbuLpnYS/Y4AZfbCqwERbJgK3W/MyjNH+n99KK 9 | T7VOOP197PbTo7Nc58EWOoJrLiGsZycHl/UTirdUy5LkHg3j/MGOkl3dPhVbKE6z 10 | vz+QM+jauiY3ImartaYBGK12KDjrZ23kjAynTt8Dmi8I7wIDAQABo4GmMIGjMAwG 11 | A1UdEwEB/wQCMAAwHQYDVR0OBBYEFGi9EI4Mflu5DGvPAYiLqShkjYQnMB8GA1Ud 12 | IwQYMBaAFGW5mAAuvah4WzqcNFwW/jA9+6epMA4GA1UdDwEB/wQEAwID6DAgBgNV 13 | HSUBAf8EFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwIQYDVR0RBBowGIcEfwAAAYcQ 14 | AAAAAAAAAAAAAAAAAAAAATANBgkqhkiG9w0BAQsFAAOCAQEAGxv8aNCoHrZHvzNR 15 | hPacICxhnY87fNuYL5oSzbUNdceThMN2Bcni+OnQtJkmpHlW4ka5CrcHfEb7zyzI 16 | PJkFOCc5U9PZWg+ya0xq7UEx5xd8RiBZidYAPXCj+fzPE4jBUGQxcJFMg1HXLOKH 17 | V127AlwgYAB54C84x3IdutDytsdF/MJ+NeDGfDNDWvjK+mbM58uY5+XnvFb9cHCl 18 | MBVa+Kr82X3yDnAZjXOAtmICjDoq/9X25+alt29Xs3vqhdsQX87AXfxM90iHkkM0 19 | 9lGhV1UZj3yznkTpG37WKqLQU9yh6K23ch5Ddj2YkNVSNFafvjgf2Fr03kx7zMbL 20 | JjmaQQ== 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /proxygen/httpserver/tests/certs/test_cert2.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDYDCCAkigAwIBAgIBATANBgkqhkiG9w0BAQsFADAnMSUwIwYDVQQDDBxBc294 3 | IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MCAXDTI0MDYwNzIxMzAyNFoYDzIxMjQw 4 | NTE0MjEzMDI0WjAVMRMwEQYDVQQDDAp0ZXN0X2NlcnQyMIIBIjANBgkqhkiG9w0B 5 | AQEFAAOCAQ8AMIIBCgKCAQEAqT7JKAm5ToEjPoRI/BRvZ65iQL5jOj9aBWARG1m5 6 | mxbRZ4yWBL07tX/uFMYvoq6it5tsnqsIO+YnnRFJxwZsh8rLe5KXZLWSfBI+4fzF 7 | M9NXVa634hnJQWQtErN6RAcLKYZHQctHvij1IhMyacfLTmH/iZCtWhpplSISmTDm 8 | l7t0+FsE0wTy6rUwgl6JK2oZa8/pWp4n2KYojWPXmGeA2W5ov+iFoCCNk7XUikPb 9 | vvC38smJErJV9ooWCZKPjEOntJuHjd0/PiqcZrrFwBU51EFe9JYJQA2szAfJ1MFT 10 | zE+vLjrurE5PC5t67nNT9qBATSFpb6R+T9tm18RRl5a1OwIDAQABo4GmMIGjMAwG 11 | A1UdEwEB/wQCMAAwHQYDVR0OBBYEFLEoOdkozRsNg+3DKtJdRGWnsgynMB8GA1Ud 12 | IwQYMBaAFGW5mAAuvah4WzqcNFwW/jA9+6epMA4GA1UdDwEB/wQEAwID6DAgBgNV 13 | HSUBAf8EFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwIQYDVR0RBBowGIcEfwAAAYcQ 14 | AAAAAAAAAAAAAAAAAAAAATANBgkqhkiG9w0BAQsFAAOCAQEAEuyRrGGJ+3veqAYx 15 | R6SG5gwgfMDX+Aik2TWtRUPOlrwvAO8ud3X5nihNRvwM8cOrggrh7LfYaLVKSqm0 16 | sfIT+QgDezQIGjWmFevNU7oAlCViQ/B/Ik2HgBvuOzcrg9lOsh7pIO7ZRhX9Zdwl 17 | CE/foDU4LUIfw64u6vxR5ErYxumifRRlhx2rxZIUrtAEEHHA9iWXC2GD+TPOC86F 18 | ePmpXaKH56d80OsvZDDfGW0FJ3vRkZR2Fhu5vmpIDr+mT5dLTAbD+mnc9YMzlcW6 19 | Jen4pE/Mjsd+QNUjCkeNVN0PFrTiKnJfB4Mv2AdP7jPidfyWgU8v0DyOMi5BJLBO 20 | NgAwOg== 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/test/test_cert1.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDYDCCAkigAwIBAgIBATANBgkqhkiG9w0BAQsFADAnMSUwIwYDVQQDDBxUaHJp 3 | ZnQgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MCAXDTIwMDUyODE2MDIyOFoYDzIxMjAw 4 | NTA0MTYwMjI4WjAnMSUwIwYDVQQDDBxUaHJpZnQgQ2VydGlmaWNhdGUgQXV0aG9y 5 | aXR5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvS23j+9p6oBzjAQw 6 | T0WW9vjnZJiQe1D7AtN4lFfoPsMhCb3xWyLhCnC1sastBb8aSY8cmnjTes4Q8NIF 7 | F5dHGWIXt/Uk9r0gPOHSbGfqDhCBsnR84x+dn/+QQ3RTY2rrs9fgoiXOcz/W0TKq 8 | TVhbEUkrLyOfmiZ1B2AcX3FndwK3AEJJ3Vyx6xhAHCCe0cHw4gStVp2t0w25cgk8 9 | +wuFTwIakd1B1MY4c7MBjGLZHPMJ9hA1K9WUBGfVlxc1ZqSjJh61iGpq2Ms7JYgF 10 | 19vzonGJ/5MndwBYuv1KES5uPymZSab3DHybeCsGaQj6VEhIhiEdBzTJb/9jc3A8 11 | oUOEHQIDAQABo4GUMIGRMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFP8oUaI9 12 | jhoc3ODIS9BSnw4M+SCuME8GA1UdIwRIMEaAFP8oUaI9jhoc3ODIS9BSnw4M+SCu 13 | oSukKTAnMSUwIwYDVQQDDBxUaHJpZnQgQ2VydGlmaWNhdGUgQXV0aG9yaXR5ggEB 14 | MA4GA1UdDwEB/wQEAwIBhjANBgkqhkiG9w0BAQsFAAOCAQEAb9GFRPWp3MdAnm5x 15 | RmXmqhFkxW9FwN0jKz49t+jM/tjgOkJ3hk5cxYAUrIiAwYoWo+qxkVbuGQDaLAmE 16 | 5jm9BqCGorP1ZLTyy6uSmgD3BlVn27Zn5Hn52ab0D+3FjdRZ/yzqQzl71VwQ+nz1 17 | Lc6clwY2aZBM1pFk8NeMDdylXqvOqiRjjhHGrBfvJtgWuXf9TElR5kqCt1cIYqpq 18 | gWRdf54bUtxD/RLNF3SxYxJF9TL/COASI7AF9beKqznMCvGazpPxEs+63a96t1UE 19 | PP5qOdgEMojA2amj7bWG6nMK60LpenBEpsQWuQD05MRla9uqN+8nzKEuWvg4cslE 20 | 9MU9rQ== 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /proxygen/httpserver/tests/certs/client_ca_cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDYDCCAkigAwIBAgIBATANBgkqhkiG9w0BAQsFADAnMSUwIwYDVQQDDBxBc294 3 | IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MCAXDTI0MDYwNzIxMzAyNFoYDzIxMjQw 4 | NTE0MjEzMDI0WjAnMSUwIwYDVQQDDBxBc294IENlcnRpZmljYXRpb24gQXV0aG9y 5 | aXR5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqMdLeznOGloPM1qj 6 | mkvxwAklg2k5j1Knf97PDNZQSuynrSul03sA01JYSqtWEroI4yfTCMIMUynfT+hp 7 | nQyGdg9g//gdV5oeKncLn7840RfxzlMRnCqGPDk5OdDJYAe0ZM6y0jwgK/3Ensko 8 | 1k30YnMs0vQ4d08ufAXpNuXzwbvZ4zVl/e7umb6YoJXKJuUv/VWC/2I6J5L9uNie 9 | b0gtXvhgBsQsxA6dTSXvdEM/Zpf5cGU1jOuIXB0AJ+RCubBd+8ZT4qleV8aorw7j 10 | LGUKw/S3ZkxrDE3kwU9Z4mXBpUCoUZjN0m61Z0S83yPEnPnCrnlRE0U6VK6kJJ+c 11 | 898U+wIDAQABo4GUMIGRMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFGW5mAAu 12 | vah4WzqcNFwW/jA9+6epME8GA1UdIwRIMEaAFGW5mAAuvah4WzqcNFwW/jA9+6ep 13 | oSukKTAnMSUwIwYDVQQDDBxBc294IENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEB 14 | MA4GA1UdDwEB/wQEAwIBhjANBgkqhkiG9w0BAQsFAAOCAQEAfs3oCDggNBPyVJ9t 15 | oDYbfubuJI9+WQiNskqtK/XoZfL90nJ7pBTPWRG884Uif+JkCHT507XWpRlbbzRE 16 | bZH11+ppnvIByz5UTxZre1lU69r1+cyOvzNZiZfmoOf96JYEmVgTclTwTFb7cb4L 17 | tzzTDIbXSVNdBBs3zFVRU/izFFagyRInrTT1idfN/iBy9ndPQKl99vzMMVk+VGMJ 18 | 9ZjiqqpJqPzJ50R0WX089W+3LWL0OJxfx2S/ywn/Aj99h/n0QkWsm4enSt91wpt3 19 | yaffCF54cLVTiGAwNfWGtcPGXE/Bf8ZjYCaJF61gBZRaVl/HV7wgA3t8TISWV/S/ 20 | V9kPtw== 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /proxygen/external/http_parser/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | http_parser.c is based on src/http/ngx_http_parse.c from NGINX copyright 2 | Igor Sysoev. 3 | 4 | Additional changes are licensed under the same terms as NGINX and 5 | copyright Joyent, Inc. and other Node contributors. All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to 9 | deal in the Software without restriction, including without limitation the 10 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 11 | sell copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23 | IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/HTTPEvent.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | std::ostream& operator<<(std::ostream& os, HTTPEvent::Type e) { 16 | switch (e) { 17 | case HTTPEvent::Type::MESSAGE_BEGIN: 18 | os << "message_begin"; 19 | break; 20 | case HTTPEvent::Type::HEADERS_COMPLETE: 21 | os << "headers_complete"; 22 | break; 23 | case HTTPEvent::Type::BODY: 24 | os << "body"; 25 | break; 26 | case HTTPEvent::Type::CHUNK_HEADER: 27 | os << "chunk_header"; 28 | break; 29 | case HTTPEvent::Type::CHUNK_COMPLETE: 30 | os << "chunk_complete"; 31 | break; 32 | case HTTPEvent::Type::TRAILERS_COMPLETE: 33 | os << "trailers_complete"; 34 | break; 35 | case HTTPEvent::Type::MESSAGE_COMPLETE: 36 | os << "message_complete"; 37 | break; 38 | case HTTPEvent::Type::UPGRADE: 39 | os << "uprade"; 40 | break; 41 | case HTTPEvent::Type::ERROR: 42 | os << "error"; 43 | break; 44 | } 45 | 46 | return os; 47 | } 48 | 49 | } // namespace proxygen 50 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/HTTPDefaultSessionCodecFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace proxygen { 17 | 18 | /** 19 | * This factory is for an HTTP server to create codecs for new connections. 20 | * 21 | * Though this factory cannot modify the passed in accConfig, the owner can 22 | * change parameters at runtime which affects new codecs. 23 | */ 24 | class HTTPDefaultSessionCodecFactory : public HTTPCodecFactory { 25 | public: 26 | explicit HTTPDefaultSessionCodecFactory( 27 | std::shared_ptr accConfig); 28 | ~HTTPDefaultSessionCodecFactory() override { 29 | } 30 | 31 | /** 32 | * Get a codec instance 33 | */ 34 | std::unique_ptr getCodec(const std::string& nextProtocol, 35 | TransportDirection direction, 36 | bool isTLS) override; 37 | 38 | protected: 39 | std::shared_ptr accConfig_; 40 | }; 41 | 42 | } // namespace proxygen 43 | -------------------------------------------------------------------------------- /proxygen/lib/dns/DNSModule.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include "proxygen/lib/dns/DNSModule.h" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | using folly::SocketAddress; 16 | 17 | DEFINE_int32(dns_cache_size, 4096, "DNS cache size"); 18 | DEFINE_int32(dns_cache_clear_size, 256, "DNS cache clear size"); 19 | DEFINE_int32(stale_dns_cache_size_multiplier, 20 | 4, 21 | "Size multiplier for stale dns cache"); 22 | DEFINE_int32(stale_cache_ttl_min, 86400, "Stale dns cache min TTL in secs"); 23 | DEFINE_int32(stale_cache_ttl_scale, 3, "Stale dns cache TTL multiplier"); 24 | 25 | namespace proxygen { 26 | 27 | static folly::Singleton gDNSModule; 28 | 29 | std::shared_ptr DNSModule::get() { 30 | return gDNSModule.try_get(); 31 | } 32 | 33 | DNSModule::DNSModule() { 34 | cacheMaxSize_ = FLAGS_dns_cache_size; 35 | cacheClearSize_ = FLAGS_dns_cache_clear_size; 36 | staleCacheSizeMultiplier_ = FLAGS_stale_dns_cache_size_multiplier; 37 | staleCacheTTLMin_ = FLAGS_stale_cache_ttl_min; 38 | staleCacheTTLScale_ = FLAGS_stale_cache_ttl_scale; 39 | } 40 | 41 | } // namespace proxygen 42 | -------------------------------------------------------------------------------- /proxygen/lib/http/structuredheaders/StructuredHeadersDecoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace proxygen { 16 | 17 | class StructuredHeadersDecoder { 18 | public: 19 | explicit StructuredHeadersDecoder(const std::string& s) : buf_(s) { 20 | } 21 | 22 | explicit StructuredHeadersDecoder(folly::StringPiece s) : buf_(s) { 23 | } 24 | 25 | StructuredHeaders::DecodeError decodeItem(StructuredHeaderItem& result); 26 | 27 | StructuredHeaders::DecodeError decodeList( 28 | std::vector& result); 29 | 30 | StructuredHeaders::DecodeError decodeDictionary(Dictionary& result); 31 | 32 | StructuredHeaders::DecodeError decodeParameterisedList( 33 | ParameterisedList& result); 34 | 35 | private: 36 | enum class MapType { DICTIONARY = 0, PARAMETERISED_MAP = 1 }; 37 | 38 | StructuredHeaders::DecodeError decodeMap( 39 | std::unordered_map& result, 40 | MapType mapType); 41 | 42 | StructuredHeadersBuffer buf_; 43 | }; 44 | 45 | } // namespace proxygen 46 | -------------------------------------------------------------------------------- /proxygen/httpclient/samples/curl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | add_library(proxygencurl CurlClient.cpp) 8 | target_include_directories( 9 | proxygencurl PUBLIC 10 | $ 11 | ) 12 | target_compile_options( 13 | proxygencurl PRIVATE 14 | ${_PROXYGEN_COMMON_COMPILE_OPTIONS} 15 | ) 16 | 17 | if (BUILD_SHARED_LIBS) 18 | set_property(TARGET proxygencurl PROPERTY POSITION_INDEPENDENT_CODE ON) 19 | if (DEFINED PACKAGE_VERSION) 20 | set_target_properties( 21 | proxygencurl PROPERTIES VERSION ${PACKAGE_VERSION} 22 | ) 23 | endif() 24 | endif() 25 | 26 | target_link_libraries(proxygencurl PUBLIC proxygen) 27 | 28 | install( 29 | TARGETS proxygencurl 30 | EXPORT proxygen-exports 31 | ARCHIVE DESTINATION ${LIB_INSTALL_DIR} 32 | LIBRARY DESTINATION ${LIB_INSTALL_DIR} 33 | ) 34 | 35 | add_executable(proxygen_curl CurlClientMain.cpp) 36 | target_link_libraries( 37 | proxygen_curl PUBLIC 38 | proxygencurl 39 | ) 40 | target_compile_options( 41 | proxygen_curl PRIVATE 42 | ${_PROXYGEN_COMMON_COMPILE_OPTIONS} 43 | ) 44 | 45 | install( 46 | TARGETS proxygen_curl 47 | EXPORT proxygen-exports 48 | DESTINATION bin 49 | ) 50 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/test/MockHTTPTransactionObserver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace proxygen { 16 | 17 | class MockHTTPTransactionObserver 18 | : public HTTPTransactionObserverContainerBaseT::ManagedObserver { 19 | public: 20 | using HTTPTransactionObserverContainerBaseT::ManagedObserver::ManagedObserver; 21 | 22 | ~MockHTTPTransactionObserver() override = default; 23 | MOCK_METHOD(void, attached, (HTTPTransactionObserverAccessor*), (noexcept)); 24 | MOCK_METHOD(void, detached, (HTTPTransactionObserverAccessor*), (noexcept)); 25 | MOCK_METHOD(void, 26 | destroyed, 27 | (HTTPTransactionObserverAccessor*, 28 | typename HTTPTransactionObserverContainer::ObserverContainer:: 29 | ManagedObserver::DestroyContext*), 30 | (noexcept)); 31 | MOCK_METHOD(void, 32 | onBytesEvent, 33 | (HTTPTransactionObserverAccessor*, const TxnBytesEvent&), 34 | (noexcept)); 35 | }; 36 | 37 | } // namespace proxygen 38 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/HQUnidirectionalCodec.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { namespace hq { 15 | 16 | std::ostream& operator<<(std::ostream& os, UnidirectionalStreamType type) { 17 | switch (type) { 18 | case UnidirectionalStreamType::CONTROL: 19 | os << "control"; 20 | break; 21 | case UnidirectionalStreamType::QPACK_ENCODER: 22 | os << "QPACK encoder"; 23 | break; 24 | case UnidirectionalStreamType::QPACK_DECODER: 25 | os << "QPACK decoder"; 26 | break; 27 | case UnidirectionalStreamType::PUSH: 28 | os << "push"; 29 | break; 30 | default: 31 | os << "unknown"; 32 | break; 33 | } 34 | return os; 35 | } 36 | 37 | std::ostream& operator<<(std::ostream& os, StreamDirection direction) { 38 | switch (direction) { 39 | case StreamDirection::INGRESS: 40 | os << "ingress"; 41 | break; 42 | case StreamDirection::EGRESS: 43 | os << "egress"; 44 | break; 45 | default: 46 | os << "unknown"; 47 | break; 48 | } 49 | return os; 50 | } 51 | 52 | }} // namespace proxygen::hq 53 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/CodecErrorResponseHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | class HTTPErrorPage; 16 | 17 | class CodecErrorResponseHandler : public HTTPTransaction::Handler { 18 | public: 19 | explicit CodecErrorResponseHandler(ErrorCode statusCode); 20 | 21 | // HTTPTransaction::Handler methods 22 | void setTransaction(HTTPTransaction* txn) noexcept override; 23 | void detachTransaction() noexcept override; 24 | void onHeadersComplete(std::unique_ptr msg) noexcept override; 25 | void onBody(std::unique_ptr chain) noexcept override; 26 | void onTrailers(std::unique_ptr trailers) noexcept override; 27 | void onEOM() noexcept override; 28 | void onUpgrade(UpgradeProtocol protocol) noexcept override; 29 | void onError(const HTTPException& error) noexcept override; 30 | // These are no-ops since the error response is already in memory 31 | void onEgressPaused() noexcept override { 32 | } 33 | void onEgressResumed() noexcept override { 34 | } 35 | 36 | private: 37 | ~CodecErrorResponseHandler() override; 38 | 39 | HTTPTransaction* txn_; 40 | }; 41 | 42 | } // namespace proxygen 43 | -------------------------------------------------------------------------------- /proxygen/lib/stats/ResourceStats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | /** 17 | * ResourceStats: 18 | * 19 | * A class designed to abstract away the internals of retrieving 20 | * various resource utilization metrics, built using PeriodicStats. 21 | * See PeriodicStats class documentation for specifics. 22 | */ 23 | class ResourceStats : public PeriodicStats { 24 | public: 25 | /** 26 | * Note: as CPU pct utilization requires intervals and at init time there 27 | * is only a single data point, pct utilization is initially seeded from 28 | * proc loadavg. 29 | */ 30 | explicit ResourceStats(std::unique_ptr resources); 31 | ~ResourceStats() override; 32 | 33 | protected: 34 | /** 35 | * Override getNewData so that we can return an instance of ResourceData. 36 | */ 37 | ResourceData* getNewData() const override; 38 | 39 | /** 40 | * Abstraction that enables callers to provide their own implementations 41 | * of the entity that actually queries various metrics. 42 | */ 43 | std::unique_ptr resources_; 44 | }; 45 | 46 | } // namespace proxygen 47 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/static/StaticHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace proxygen { 17 | class ResponseHandler; 18 | } 19 | 20 | namespace StaticService { 21 | 22 | class StaticHandler : public proxygen::RequestHandler { 23 | public: 24 | void onRequest( 25 | std::unique_ptr headers) noexcept override; 26 | 27 | void onBody(std::unique_ptr body) noexcept override; 28 | 29 | void onEOM() noexcept override; 30 | 31 | void onUpgrade(proxygen::UpgradeProtocol proto) noexcept override; 32 | 33 | void requestComplete() noexcept override; 34 | 35 | void onError(proxygen::ProxygenError err) noexcept override; 36 | 37 | void onEgressPaused() noexcept override; 38 | 39 | void onEgressResumed() noexcept override; 40 | 41 | private: 42 | void readFile(folly::EventBase* evb); 43 | bool checkForCompletion(); 44 | 45 | std::unique_ptr file_; 46 | bool readFileScheduled_{false}; 47 | std::atomic paused_{false}; 48 | bool finished_{false}; 49 | std::atomic error_{false}; 50 | }; 51 | 52 | } // namespace StaticService 53 | -------------------------------------------------------------------------------- /proxygen/lib/utils/ZlibStreamCompressor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace folly { 18 | class IOBuf; 19 | } 20 | 21 | FOLLY_GFLAGS_DECLARE_int64(zlib_compressor_buffer_growth); 22 | 23 | namespace proxygen { 24 | 25 | class ZlibStreamCompressor : public StreamCompressor { 26 | public: 27 | explicit ZlibStreamCompressor(CompressionType type, int level); 28 | 29 | ~ZlibStreamCompressor() override; 30 | 31 | void init(); 32 | 33 | std::unique_ptr compress(const folly::IOBuf* in, 34 | bool trailer = true) override; 35 | 36 | int getStatus() { 37 | return status_; 38 | } 39 | 40 | bool hasError() override { 41 | return status_ != Z_OK && status_ != Z_STREAM_END; 42 | } 43 | 44 | bool finished() { 45 | return status_ == Z_STREAM_END; 46 | } 47 | 48 | private: 49 | CompressionType type_{CompressionType::NONE}; 50 | int level_{Z_DEFAULT_COMPRESSION}; 51 | z_stream zlibStream_; 52 | int status_{Z_OK}; 53 | bool init_{false}; 54 | }; 55 | } // namespace proxygen 56 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/experimental/simulator/CompressionTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { namespace compress { 14 | enum class SchemeType { QPACK, QMIN, HPACK }; 15 | 16 | // Metadata about encoded blocks. In a real stack, these might be 17 | // conveyed via HTTP frame (HEADERS or PUSH_PROMISE) flags. 18 | struct FrameFlags { 19 | FrameFlags(bool ooo = false, bool depends = false) 20 | : allowOOO(ooo), QPACKPrefixHasDepends(depends) { 21 | } 22 | 23 | bool allowOOO{false}; 24 | bool QPACKPrefixHasDepends{false}; 25 | }; 26 | 27 | struct SimParams { 28 | SchemeType type; 29 | int64_t seed; 30 | std::chrono::milliseconds rtt; 31 | double lossProbability; 32 | double delayProbability; 33 | std::chrono::milliseconds maxDelay; 34 | uint16_t minOOOThresh; 35 | bool blend; 36 | bool samePacketCompression; 37 | uint32_t tableSize; 38 | uint32_t maxBlocking; 39 | }; 40 | 41 | struct SimStats { 42 | uint64_t allowedOOO{0}; 43 | uint64_t packetLosses{0}; 44 | uint64_t maxQueueBufferBytes{0}; 45 | std::chrono::milliseconds holDelay{0}; 46 | uint64_t uncompressed{0}; 47 | uint64_t compressed{0}; 48 | uint64_t packets{0}; 49 | }; 50 | }} // namespace proxygen::compress 51 | -------------------------------------------------------------------------------- /proxygen/lib/utils/samples/TraceEventType.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Trace Event Type, please follow the pattern when you add new one. 3 | */ 4 | 5 | TotalRequest, "TotalRequest" 6 | RequestExchange, "HTTPRequestExchange" 7 | ResponseBodyRead, "HTTPResponseBodyRead" 8 | PreConnect, "PreConnect" 9 | PostConnect, "PostConnect" 10 | DnsResolution, "DNSResolution" 11 | DnsCache, "DNSCache" 12 | RetryingDnsResolution, "RetryingDNSResolution" 13 | TcpConnect, "TCPConnect" 14 | TlsSetup, "TLSSetup" 15 | TotalConnect, "TotalConnect" 16 | Decompression, "decompression_filter" 17 | CertVerification, "cert_verification" 18 | ProxyConnect, "proxy_connect" 19 | Push, "push" 20 | Scheduling, "scheduling" 21 | NetworkChange, "network_change" 22 | MultiConnector, "multi_connector" 23 | SingleConnector, "single_connector" 24 | SessionTransactions, "SessionTransactions" 25 | TCPInfo, "TCPInfo" 26 | ConnInfo, "ConnInfo" 27 | ZeroSetup, "ZeroSetup" 28 | ZeroVerification, "ZeroVerification" 29 | ZeroConnector, "ZeroConnector" 30 | ReplaySafety, "ReplaySafety" 31 | HTTPPerfParameters, "HTTPPerfParameters" 32 | RetryFilter, "RetryFilter" 33 | ZeroFallback, "ZeroFallback" 34 | TLSCachedInfo, "TLSCachedInfo" 35 | 36 | /* 37 | * XXX: Too bad we have to define events in Liger core for the platform 38 | * wrappers :( 39 | */ 40 | FBLigerProtocol, "FBLigerProtocol" 41 | 42 | /* 43 | * MQTT Client events 44 | */ 45 | MQTTClient, "MQTTClient" 46 | MQTTMessage, "MQTTMessage" 47 | MQTTConnect, "MQTTConnect" 48 | MQTTMessageStart, "MQTTMessageStart" 49 | -------------------------------------------------------------------------------- /proxygen/lib/utils/test/CryptUtilTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | using namespace proxygen; 15 | 16 | using folly::ByteRange; 17 | 18 | TEST(CryptUtilTest, Base64EncodeTest) { 19 | ASSERT_EQ("", 20 | base64Encode(ByteRange(reinterpret_cast(""), 21 | (size_t)0))); 22 | ASSERT_EQ( 23 | "YQ==", 24 | base64Encode(ByteRange(reinterpret_cast("a"), 1))); 25 | ASSERT_EQ( 26 | "YWE=", 27 | base64Encode(ByteRange(reinterpret_cast("aa"), 2))); 28 | ASSERT_EQ( 29 | "QWxhZGRpbjpvcGVuIHNlc2FtZQ==", 30 | base64Encode(ByteRange( 31 | reinterpret_cast("Aladdin:open sesame"), 19))); 32 | } 33 | 34 | TEST(CryptUtilTest, MD5EncodeTest) { 35 | ASSERT_EQ("d41d8cd98f00b204e9800998ecf8427e", 36 | md5Encode(ByteRange(reinterpret_cast(""), 37 | (size_t)0))); 38 | ASSERT_EQ( 39 | "a7a93b8ac14a48faa68e4afb57b00fc7", 40 | md5Encode(ByteRange( 41 | reinterpret_cast("Aladdin:open sesame"), 19))); 42 | } 43 | -------------------------------------------------------------------------------- /proxygen/httpclient/samples/httperf2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | add_library(libhttperf2 HTTPerf2.cpp Client.cpp) 8 | target_include_directories( 9 | libhttperf2 PUBLIC 10 | $ 11 | ) 12 | target_compile_options( 13 | libhttperf2 PRIVATE 14 | ${_PROXYGEN_COMMON_COMPILE_OPTIONS} 15 | ) 16 | 17 | if (BUILD_SHARED_LIBS) 18 | set_property(TARGET libhttperf2 PROPERTY POSITION_INDEPENDENT_CODE ON) 19 | if (DEFINED PACKAGE_VERSION) 20 | set_target_properties( 21 | libhttperf2 PROPERTIES VERSION ${PACKAGE_VERSION} 22 | ) 23 | endif() 24 | endif() 25 | 26 | target_link_libraries( 27 | libhttperf2 PUBLIC 28 | proxygenhqloggerhelper 29 | proxygen 30 | ) 31 | 32 | install( 33 | TARGETS libhttperf2 34 | EXPORT proxygen-exports 35 | ARCHIVE DESTINATION ${LIB_INSTALL_DIR} 36 | LIBRARY DESTINATION ${LIB_INSTALL_DIR} 37 | ) 38 | 39 | add_executable(proxygen_httperf2 Main.cpp) 40 | target_link_libraries( 41 | proxygen_httperf2 PUBLIC 42 | libhttperf2 43 | ) 44 | target_compile_options( 45 | proxygen_httperf2 PRIVATE 46 | ${_PROXYGEN_COMMON_COMPILE_OPTIONS} 47 | ) 48 | 49 | install( 50 | TARGETS proxygen_httperf2 51 | EXPORT proxygen-exports 52 | DESTINATION bin 53 | ) 54 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/HeaderPiece.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | 17 | namespace proxygen { namespace compress { 18 | 19 | /** 20 | * in-place representation of a header name or value 21 | */ 22 | class HeaderPiece { 23 | public: 24 | /** 25 | * Construct a view around the data 26 | */ 27 | HeaderPiece(const char* inData, 28 | uint32_t inLen, 29 | bool inOwner, 30 | bool inMultiValued) 31 | : str(inData, inLen), owner(inOwner), multiValued(inMultiValued) { 32 | } 33 | 34 | HeaderPiece(HeaderPiece&& goner) noexcept 35 | : str(goner.str), owner(goner.owner), multiValued(goner.multiValued) { 36 | goner.owner = false; 37 | } 38 | 39 | ~HeaderPiece() { 40 | if (owner) { 41 | CHECK_NOTNULL(str.data()); 42 | delete[] str.data(); 43 | } 44 | } 45 | 46 | bool isMultiValued() const { 47 | return multiValued; 48 | } 49 | 50 | // should be const, but for one use in GzipHeaderCodec 51 | folly::StringPiece str; 52 | 53 | private: 54 | bool owner; 55 | bool multiValued; 56 | }; 57 | 58 | using HeaderPieceList = std::deque; 59 | 60 | }} // namespace proxygen::compress 61 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/DirectErrorsRateLimitFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | class DirectErrorsRateLimiter : public RateLimiter { 16 | public: 17 | static const uint32_t kDefaultMaxEventsPerInterval = 100; 18 | static const uint32_t kMaxEventsPerIntervalLowerBound = 50; 19 | static constexpr std::chrono::milliseconds kDefaultTimeoutDuration{100}; 20 | 21 | explicit DirectErrorsRateLimiter(folly::HHWheelTimer* timer, 22 | HTTPSessionStats* httpSessionStats) 23 | : RateLimiter(timer, httpSessionStats) { 24 | maxEventsInInterval_ = kDefaultMaxEventsPerInterval; 25 | timeoutDuration_ = kDefaultTimeoutDuration; 26 | } 27 | 28 | void recordNumEventsInCurrentInterval(uint32_t /* numEvents */) override { 29 | // We don't currently record the number of direct errors in an interval 30 | } 31 | 32 | void recordRateLimitBreached() override { 33 | // We don't currently record how frequenlty we breach the direct errors 34 | // rate limit in an interval 35 | } 36 | 37 | uint32_t getMaxEventsPerInvervalLowerBound() const override { 38 | return kMaxEventsPerIntervalLowerBound; 39 | } 40 | }; 41 | 42 | } // namespace proxygen 43 | -------------------------------------------------------------------------------- /proxygen/lib/utils/CobHelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace proxygen { 17 | 18 | /** 19 | * A helper class to schedule N async jobs in (possibly) different threads 20 | * and invoke a final callback in a given thread once all are done. 21 | */ 22 | class CobHelper { 23 | public: 24 | CobHelper(size_t itemsLeft, 25 | const std::function& cob, 26 | const std::function& ecob) 27 | : itemsLeft_(itemsLeft), cob_(cob), ecob_(ecob) { 28 | } 29 | 30 | void setError(const std::string& emsg) { 31 | CHECK(!emsg.empty()); 32 | emsg_ = emsg; 33 | } 34 | 35 | void workerDone() { 36 | uint32_t oldValue = itemsLeft_.fetch_sub(1); 37 | if (oldValue != 1) { 38 | return; 39 | } 40 | 41 | allDone(); 42 | } 43 | 44 | private: 45 | void allDone() { 46 | if (!emsg_.empty()) { 47 | ecob_(std::runtime_error(emsg_)); 48 | } else { 49 | cob_(); 50 | } 51 | 52 | delete this; 53 | } 54 | 55 | std::atomic itemsLeft_; 56 | std::string emsg_; 57 | std::function cob_; 58 | std::function ecob_; 59 | }; 60 | 61 | } // namespace proxygen 62 | -------------------------------------------------------------------------------- /proxygen/lib/http/HTTPConnectorWithFizz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | /** 16 | * Extension of the HTTPConnector that uses Fizz to 17 | * support TLS 1.3 connections. 18 | **/ 19 | 20 | namespace proxygen { 21 | 22 | class HTTPConnectorWithFizz : public HTTPConnector { 23 | public: 24 | using HTTPConnector::HTTPConnector; 25 | 26 | void connectFizz( 27 | folly::EventBase* eventBase, 28 | const folly::SocketAddress& connectAddr, 29 | std::shared_ptr context, 30 | std::shared_ptr verifier, 31 | std::chrono::milliseconds totalTimeout = std::chrono::milliseconds(0), 32 | std::chrono::milliseconds tcpConnectTimeout = 33 | std::chrono::milliseconds(0), 34 | const folly::SocketOptionMap& socketOptions = folly::emptySocketOptionMap, 35 | const folly::SocketAddress& bindAddr = folly::AsyncSocket::anyAddress(), 36 | folly::Optional sni = folly::none, 37 | folly::Optional pskIdentity = folly::none); 38 | 39 | protected: 40 | void connectSuccess() noexcept override; 41 | }; 42 | 43 | } // namespace proxygen 44 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/QPACKContext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | QPACKContext::QPACKContext(uint32_t tableSize, bool trackReferences) 16 | : table_(tableSize, trackReferences) { 17 | } 18 | 19 | const HPACKHeader& QPACKContext::getHeader(bool isStatic, 20 | uint32_t index, 21 | uint32_t base, 22 | bool aboveBase) { 23 | if (isStatic) { 24 | staticRefs_++; 25 | return getStaticTable().getHeader(index); 26 | } 27 | if (aboveBase) { 28 | CHECK_LE(base, std::numeric_limits::max() - index); 29 | base += index; 30 | index = 1; 31 | } 32 | return table_.getHeader(index, base); 33 | } 34 | 35 | void QPACKContext::seedHeaderTable(std::vector& headers) { 36 | for (auto& header : headers) { 37 | CHECK(table_.add(std::move(header))); 38 | } 39 | } 40 | 41 | void QPACKContext::describe(std::ostream& os) const { 42 | os << table_; 43 | } 44 | 45 | std::ostream& operator<<(std::ostream& os, const QPACKContext& context) { 46 | context.describe(os); 47 | return os; 48 | } 49 | 50 | } // namespace proxygen 51 | -------------------------------------------------------------------------------- /proxygen/lib/dns/SyncDNSResolver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | #include "proxygen/lib/dns/DNSResolver.h" 14 | 15 | namespace proxygen { 16 | 17 | /** 18 | * SyncDNSResolver provides a synchronous interface around the async 19 | * DNSResolver. Internally it runs a separate thread running event loop 20 | * and does all the DNS resolution there. 21 | * 22 | * Use this if you want timeout functionality, etc or if you are doing a lot 23 | * of lookups and want to avoid hitting the bug in `getaddrinfo` described 24 | * here - 25 | * 26 | * https://sourceware.org/bugzilla/show_bug.cgi?id=15946 27 | */ 28 | class SyncDNSResolver { 29 | public: 30 | SyncDNSResolver(); 31 | explicit SyncDNSResolver(DNSResolver::UniquePtr resolver); 32 | ~SyncDNSResolver(); 33 | 34 | std::vector resolveHostname( 35 | const std::string& hostname, 36 | std::chrono::milliseconds timeout = std::chrono::milliseconds(100), 37 | sa_family_t family = AF_UNSPEC, 38 | bool rfc6724sort = true); 39 | 40 | // Helpful while testing 41 | folly::EventBase* getEventBase() { 42 | return &evb_; 43 | } 44 | 45 | private: 46 | std::thread thread_; 47 | folly::EventBase evb_; 48 | DNSResolver::UniquePtr resolver_; 49 | }; 50 | 51 | } // namespace proxygen 52 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/test/TestUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace proxygen { 21 | 22 | extern const wangle::TransportInfo mockTransportInfo; 23 | extern const folly::SocketAddress localAddr; 24 | extern const folly::SocketAddress peerAddr; 25 | 26 | folly::HHWheelTimer::UniquePtr makeInternalTimeoutSet(folly::EventBase* evb); 27 | 28 | folly::HHWheelTimer::UniquePtr makeTimeoutSet(folly::EventBase* evb); 29 | 30 | testing::NiceMock* newMockTransport( 31 | folly::EventBase* evb); 32 | 33 | struct HTTP1xCodecPair { 34 | using Codec = HTTP1xCodec; 35 | static const int version = 1; 36 | }; 37 | 38 | struct HTTP2CodecPair { 39 | using Codec = HTTP2Codec; 40 | static const int version = 2; 41 | }; 42 | 43 | struct MockHTTPCodecPair { 44 | using Codec = MockHTTPCodec; 45 | static const int version = 0; 46 | }; 47 | 48 | } // namespace proxygen 49 | -------------------------------------------------------------------------------- /proxygen/httpclient/samples/websocket/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | add_library(proxygenwsclientlib WebSocketClient.cpp) 8 | target_include_directories( 9 | proxygenwsclientlib PUBLIC 10 | $ 11 | ) 12 | target_compile_options( 13 | proxygenwsclientlib PRIVATE 14 | ${_PROXYGEN_COMMON_COMPILE_OPTIONS} 15 | ) 16 | 17 | if (BUILD_SHARED_LIBS) 18 | set_property( 19 | TARGET proxygenwsclientlib PROPERTY POSITION_INDEPENDENT_CODE ON 20 | ) 21 | if (DEFINED PACKAGE_VERSION) 22 | set_target_properties( 23 | proxygenwsclientlib PROPERTIES VERSION ${PACKAGE_VERSION} 24 | ) 25 | endif() 26 | endif() 27 | 28 | target_link_libraries(proxygenwsclientlib PUBLIC proxygen) 29 | 30 | install( 31 | TARGETS proxygenwsclientlib 32 | EXPORT proxygen-exports 33 | ARCHIVE DESTINATION ${LIB_INSTALL_DIR} 34 | LIBRARY DESTINATION ${LIB_INSTALL_DIR} 35 | ) 36 | 37 | add_executable(proxygen_websocket_client main.cpp) 38 | target_link_libraries( 39 | proxygen_websocket_client PUBLIC 40 | proxygenwsclientlib 41 | ) 42 | target_compile_options( 43 | proxygen_websocket_client PRIVATE 44 | ${_PROXYGEN_COMMON_COMPILE_OPTIONS} 45 | ) 46 | 47 | install( 48 | TARGETS proxygen_websocket_client 49 | EXPORT proxygen-exports 50 | DESTINATION bin 51 | ) 52 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/ResetsRateLimitFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | class ResetsRateLimiter : public RateLimiter { 17 | public: 18 | static const uint32_t kDefaultMaxEventsPerInterval = 10000; 19 | static const uint32_t kMaxEventsPerIntervalLowerBound = 100; 20 | static constexpr std::chrono::milliseconds kDefaultTimeoutDuration{1000}; 21 | 22 | explicit ResetsRateLimiter(folly::HHWheelTimer* timer, 23 | HTTPSessionStats* httpSessionStats) 24 | : RateLimiter(timer, httpSessionStats) { 25 | maxEventsInInterval_ = kDefaultMaxEventsPerInterval; 26 | timeoutDuration_ = kDefaultTimeoutDuration; 27 | } 28 | 29 | void recordNumEventsInCurrentInterval(uint32_t numEvents) override { 30 | if (httpSessionStats_) { 31 | httpSessionStats_->recordResetsInInterval(numEvents); 32 | } 33 | } 34 | 35 | void recordRateLimitBreached() override { 36 | if (httpSessionStats_) { 37 | httpSessionStats_->recordResetsRateLimited(); 38 | } 39 | } 40 | 41 | uint32_t getMaxEventsPerInvervalLowerBound() const override { 42 | return kMaxEventsPerIntervalLowerBound; 43 | } 44 | }; 45 | 46 | } // namespace proxygen 47 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/HeadersRateLimitFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | class HeadersRateLimiter : public RateLimiter { 17 | public: 18 | static const uint32_t kDefaultMaxEventsPerInterval = 50000; 19 | static const uint32_t kMaxEventsPerIntervalLowerBound = 100; 20 | static constexpr std::chrono::milliseconds kDefaultTimeoutDuration{100}; 21 | 22 | explicit HeadersRateLimiter(folly::HHWheelTimer* timer, 23 | HTTPSessionStats* httpSessionStats) 24 | : RateLimiter(timer, httpSessionStats) { 25 | maxEventsInInterval_ = kDefaultMaxEventsPerInterval; 26 | timeoutDuration_ = kDefaultTimeoutDuration; 27 | } 28 | 29 | void recordNumEventsInCurrentInterval(uint32_t numEvents) override { 30 | if (httpSessionStats_) { 31 | httpSessionStats_->recordHeadersInInterval(numEvents); 32 | } 33 | } 34 | 35 | void recordRateLimitBreached() override { 36 | if (httpSessionStats_) { 37 | httpSessionStats_->recordHeadersRateLimited(); 38 | } 39 | } 40 | 41 | uint32_t getMaxEventsPerInvervalLowerBound() const override { 42 | return kMaxEventsPerIntervalLowerBound; 43 | } 44 | }; 45 | 46 | } // namespace proxygen 47 | -------------------------------------------------------------------------------- /.github/workflows/publish_mvfst_interop.yml: -------------------------------------------------------------------------------- 1 | # Following instruction from https://docs.github.com/en/actions/publishing-packages/publishing-docker-images 2 | 3 | name: Publish mvfst interop image 4 | 5 | on: 6 | push: 7 | tags: 8 | # Build a new image weekly with each TagIt release 9 | - 'v20*' 10 | 11 | env: 12 | REGISTRY: ghcr.io 13 | IMAGE_NAME: ${{ github.repository }}/mvfst-interop 14 | 15 | jobs: 16 | build-and-push-image: 17 | runs-on: ubuntu-latest 18 | 19 | permissions: 20 | contents: read 21 | packages: write 22 | 23 | steps: 24 | - name: Checkout repository 25 | uses: actions/checkout@v4 26 | 27 | - name: Log in to the Container registry 28 | uses: docker/login-action@7ca345011ac4304463197fac0e56eab1bc7e6af0 29 | with: 30 | registry: ${{ env.REGISTRY }} 31 | username: ${{ github.actor }} 32 | password: ${{ secrets.GITHUB_TOKEN }} 33 | 34 | - name: Extract metadata (tags, labels) for Docker 35 | id: meta 36 | uses: docker/metadata-action@b53be03109c4ef6f6cc7aa545b84b17a7fe51c1e 37 | with: 38 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} 39 | 40 | - name: Build and push Docker image 41 | uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 42 | with: 43 | context: . 44 | file: proxygen/httpserver/samples/hq/quic-interop/Dockerfile 45 | push: true 46 | tags: ${{ steps.meta.outputs.tags }} 47 | labels: ${{ steps.meta.outputs.labels }} 48 | -------------------------------------------------------------------------------- /proxygen/lib/transport/AsyncUDPSocketFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace proxygen { 17 | 18 | class AsyncUDPSocketFactory { 19 | public: 20 | struct SocketCreateOptions { 21 | bool connectSocket{false}; 22 | }; 23 | 24 | explicit AsyncUDPSocketFactory( 25 | folly::EventBase* eventBase, 26 | folly::SocketAddress v6BindAddress, 27 | folly::Optional v4BindAddress = folly::none); 28 | ~AsyncUDPSocketFactory() = default; 29 | 30 | folly::Expected, proxygen::Exception> 31 | createSocket(const folly::SocketAddress& destinationAddress, 32 | SocketCreateOptions options = getDefaultCreateOptions()); 33 | 34 | private: 35 | static SocketCreateOptions getDefaultCreateOptions() { 36 | return SocketCreateOptions{.connectSocket = false}; 37 | } 38 | 39 | folly::Expected getBindingAddress( 40 | const folly::SocketAddress& destination); 41 | 42 | folly::EventBase* eventBase_{nullptr}; 43 | folly::SocketAddress v6Address_; 44 | folly::Optional v4Address_; 45 | }; 46 | } // namespace proxygen 47 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/ErrorCode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | #define RETURN_IF_ERROR(err) \ 14 | if (err != ErrorCode::NO_ERROR) { \ 15 | VLOG(4) << "Returning with error=" << getErrorCodeString(err); \ 16 | return err; \ 17 | } \ 18 | static_assert(true, "semicolon required") 19 | 20 | namespace proxygen { 21 | 22 | // Error codes are 32-bit fields that are used in RST_STREAM and GOAWAY 23 | // frames to convey the reasons for the stream or connection error. 24 | 25 | // We only need <1 byte to represent it in memory 26 | enum class ErrorCode : uint8_t { 27 | NO_ERROR = 0, 28 | PROTOCOL_ERROR = 1, 29 | INTERNAL_ERROR = 2, 30 | FLOW_CONTROL_ERROR = 3, 31 | SETTINGS_TIMEOUT = 4, 32 | STREAM_CLOSED = 5, 33 | FRAME_SIZE_ERROR = 6, 34 | REFUSED_STREAM = 7, 35 | CANCEL = 8, 36 | COMPRESSION_ERROR = 9, 37 | CONNECT_ERROR = 10, 38 | ENHANCE_YOUR_CALM = 11, 39 | INADEQUATE_SECURITY = 12, 40 | HTTP_1_1_REQUIRED = 13, 41 | MAX, 42 | }; 43 | 44 | /** 45 | * Returns a string representation of the error code. 46 | */ 47 | extern const char* getErrorCodeString(ErrorCode error); 48 | 49 | } // namespace proxygen 50 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/ControlMessageRateLimitFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | class ControlMessageRateLimiter : public RateLimiter { 17 | public: 18 | static const uint32_t kDefaultMaxEventsPerInterval = 50000; 19 | static const uint32_t kMaxEventsPerIntervalLowerBound = 100; 20 | static constexpr std::chrono::milliseconds kDefaultTimeoutDuration{100}; 21 | 22 | explicit ControlMessageRateLimiter(folly::HHWheelTimer* timer, 23 | HTTPSessionStats* httpSessionStats) 24 | : RateLimiter(timer, httpSessionStats) { 25 | maxEventsInInterval_ = kDefaultMaxEventsPerInterval; 26 | timeoutDuration_ = kDefaultTimeoutDuration; 27 | } 28 | 29 | void recordNumEventsInCurrentInterval(uint32_t numEvents) override { 30 | if (httpSessionStats_) { 31 | httpSessionStats_->recordControlMsgsInInterval(numEvents); 32 | } 33 | } 34 | 35 | void recordRateLimitBreached() override { 36 | if (httpSessionStats_) { 37 | httpSessionStats_->recordControlMsgRateLimited(); 38 | } 39 | } 40 | 41 | uint32_t getMaxEventsPerInvervalLowerBound() const override { 42 | return kMaxEventsPerIntervalLowerBound; 43 | } 44 | }; 45 | 46 | } // namespace proxygen 47 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/HeaderIndexingStrategy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | class HeaderIndexingStrategy { 16 | public: 17 | static const HeaderIndexingStrategy* getDefaultInstance(); 18 | 19 | // Explicitly defined constructor/destructor 20 | // Destructor is virtual so that a subclass can provide an implementation 21 | // and that it will be correctly called even when aliased by a 22 | // HPACKEnoderStrat* var 23 | HeaderIndexingStrategy() { 24 | } 25 | virtual ~HeaderIndexingStrategy() { 26 | } 27 | 28 | // Virtual method for subclasses to implement as they see fit 29 | // Returns a bool that indicates whether the specified header should be 30 | // indexed 31 | virtual bool indexHeader(const HPACKHeaderName& name, 32 | folly::StringPiece value, 33 | bool nameExists = false) const; 34 | 35 | // Only apply huffman to literal strings in the range [first, second] 36 | // Huffman encoding small strings doesn't save that many bytes 37 | // Huffman encoding very large strings is expensive 38 | [[nodiscard]] virtual std::pair getHuffmanLimits() const { 39 | return {0, std::numeric_limits::max()}; 40 | } 41 | }; 42 | 43 | } // namespace proxygen 44 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/websocket/WebSocketHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace proxygen { 16 | class ResponseHandler; 17 | } 18 | 19 | namespace websockethandler { 20 | 21 | /* 22 | * Websocket stream parser. 23 | */ 24 | class WebSocketStream { 25 | public: 26 | enum class WebSocketStreamError {}; 27 | folly::Expected, WebSocketStreamError> onData( 28 | std::unique_ptr chain); 29 | }; 30 | 31 | /* 32 | * Websocket acceptor. 33 | */ 34 | class WebSocketHandler : public proxygen::RequestHandler { 35 | public: 36 | void onRequest( 37 | std::unique_ptr request) noexcept override; 38 | 39 | void onBody(std::unique_ptr body) noexcept override; 40 | 41 | void onEOM() noexcept override; 42 | 43 | void onUpgrade(proxygen::UpgradeProtocol proto) noexcept override; 44 | 45 | void requestComplete() noexcept override; 46 | 47 | void onError(proxygen::ProxygenError err) noexcept override; 48 | 49 | void onEgressPaused() noexcept override; 50 | 51 | void onEgressResumed() noexcept override; 52 | 53 | private: 54 | std::unique_ptr wsStream_; 55 | }; 56 | 57 | } // namespace websockethandler 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD License 2 | 3 | For Proxygen software 4 | 5 | Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | * Neither the name Facebook nor the names of its contributors may be used to 18 | endorse or promote products derived from this software without specific 19 | prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 25 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 28 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /proxygen/lib/dns/test/MockDNSResolver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "proxygen/lib/dns/DNSResolver.h" 17 | 18 | namespace proxygen { 19 | 20 | class MockDNSResolver : public proxygen::DNSResolver { 21 | public: 22 | class MockQueryBase : public DNSResolver::QueryBase { 23 | public: 24 | MOCK_METHOD(void, cancelResolutionImpl, ()); 25 | }; 26 | 27 | MOCK_METHOD(void, 28 | resolveAddress, 29 | (proxygen::DNSResolver::ResolutionCallback*, 30 | const folly::SocketAddress&, 31 | std::chrono::milliseconds)); 32 | 33 | MOCK_METHOD(void, 34 | resolveHostname, 35 | (DNSResolver::ResolutionCallback*, 36 | const std::string&, 37 | std::chrono::milliseconds, 38 | sa_family_t, 39 | TraceEventContext)); 40 | 41 | MOCK_METHOD(void, 42 | resolveMailExchange, 43 | (DNSResolver::ResolutionCallback*, 44 | const std::string&, 45 | std::chrono::milliseconds)); 46 | 47 | MOCK_METHOD(void, setStatsCollector, (DNSResolver::StatsCollector*)); 48 | MOCK_METHOD(DNSResolver::StatsCollector*, getStatsCollector, (), (const)); 49 | }; 50 | 51 | } // namespace proxygen 52 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/test/TestUtils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | using folly::test::MockAsyncTransport; 12 | 13 | using namespace folly; 14 | 15 | namespace proxygen { 16 | 17 | const wangle::TransportInfo mockTransportInfo = wangle::TransportInfo(); 18 | const SocketAddress localAddr{"127.0.0.1", 80}; 19 | const SocketAddress peerAddr{"127.0.0.1", 12345}; 20 | 21 | folly::HHWheelTimer::UniquePtr makeInternalTimeoutSet(EventBase* evb) { 22 | folly::HHWheelTimer::UniquePtr t(folly::HHWheelTimer::newTimer( 23 | evb, 24 | std::chrono::milliseconds(folly::HHWheelTimer::DEFAULT_TICK_INTERVAL), 25 | TimeoutManager::InternalEnum::INTERNAL, 26 | std::chrono::milliseconds(500))); 27 | return t; 28 | } 29 | 30 | folly::HHWheelTimer::UniquePtr makeTimeoutSet(EventBase* evb) { 31 | folly::HHWheelTimer::UniquePtr t(folly::HHWheelTimer::newTimer( 32 | evb, 33 | std::chrono::milliseconds(folly::HHWheelTimer::DEFAULT_TICK_INTERVAL), 34 | folly::AsyncTimeout::InternalEnum::NORMAL, 35 | std::chrono::milliseconds(500))); 36 | return t; 37 | } 38 | 39 | testing::NiceMock* newMockTransport(EventBase* evb) { 40 | auto transport = new testing::NiceMock(); 41 | EXPECT_CALL(*transport, getEventBase()).WillRepeatedly(testing::Return(evb)); 42 | return transport; 43 | } 44 | 45 | } // namespace proxygen 46 | -------------------------------------------------------------------------------- /proxygen/httpserver/filters/DirectResponseHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | /** 17 | * Handler that sends a fixed response back. 18 | */ 19 | class DirectResponseHandler : public RequestHandler { 20 | public: 21 | DirectResponseHandler(int code, std::string message, std::string body) 22 | : code_(code), 23 | message_(std::move(message)), 24 | body_(folly::IOBuf::copyBuffer(body)) { 25 | } 26 | 27 | void onRequest(std::unique_ptr /*headers*/) noexcept override { 28 | ResponseBuilder(downstream_) 29 | .status(code_, std::move(message_)) 30 | .body(std::move(body_)) 31 | .send(); 32 | } 33 | 34 | void onBody(std::unique_ptr /*body*/) noexcept override { 35 | } 36 | 37 | void onUpgrade(proxygen::UpgradeProtocol /*prot*/) noexcept override { 38 | } 39 | 40 | void onEOM() noexcept override { 41 | ResponseBuilder(downstream_).sendWithEOM(); 42 | } 43 | 44 | void requestComplete() noexcept override { 45 | delete this; 46 | } 47 | 48 | void onError(ProxygenError /*err*/) noexcept override { 49 | delete this; 50 | } 51 | 52 | private: 53 | const int code_; 54 | std::string message_; 55 | std::unique_ptr body_; 56 | }; 57 | 58 | } // namespace proxygen 59 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/HeaderIndexingStrategy.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | namespace proxygen { 12 | 13 | const HeaderIndexingStrategy* HeaderIndexingStrategy::getDefaultInstance() { 14 | static const HeaderIndexingStrategy* instance = new HeaderIndexingStrategy(); 15 | return instance; 16 | } 17 | 18 | bool HeaderIndexingStrategy::indexHeader(const HPACKHeaderName& name, 19 | folly::StringPiece value, 20 | bool) const { 21 | // Handle all the cases where we want to return false in the switch statement 22 | // below; else let the code fall through and return true 23 | switch (name.getHeaderCode()) { 24 | case HTTP_HEADER_COLON_PATH: 25 | if (value.find('=') != std::string::npos) { 26 | return false; 27 | } 28 | if (value.find("jpg") != std::string::npos) { 29 | return false; 30 | } 31 | break; 32 | 33 | // The wrapped header should never be HTTP_HEADER_NONE but for completeness 34 | // the condition is included below 35 | case HTTP_HEADER_NONE: 36 | case HTTP_HEADER_CONTENT_LENGTH: 37 | case HTTP_HEADER_IF_MODIFIED_SINCE: 38 | case HTTP_HEADER_LAST_MODIFIED: 39 | return false; 40 | 41 | default: 42 | break; 43 | } 44 | 45 | return true; 46 | } 47 | 48 | } // namespace proxygen 49 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/compress/Header.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { namespace compress { 15 | 16 | /** 17 | * Helper structure used when serializing the uncompressed 18 | * representation of a header name/value list. 19 | */ 20 | struct Header { 21 | HTTPHeaderCode code; 22 | const std::string* name; 23 | const std::string* value; 24 | 25 | Header(HTTPHeaderCode c, const std::string& v) 26 | : code(c), name(HTTPCommonHeaders::getPointerToName(c)), value(&v) { 27 | } 28 | 29 | Header(HTTPHeaderCode c, const std::string& n, const std::string& v) 30 | : code(c), name(&n), value(&v) { 31 | } 32 | 33 | bool operator<(const Header& h) const { 34 | return (code < h.code) || ((code == h.code) && (*name < *h.name)); 35 | } 36 | 37 | // For use by tests 38 | static Header makeHeaderForTest(const std::string& n, const std::string& v) { 39 | return Header(n, v); 40 | } 41 | 42 | private: 43 | // This constructor ideally should not be used in production code 44 | // This is because in prod the common header code is likely already known and 45 | // an above constructor could be used; this exists for test purposes 46 | Header(const std::string& n, const std::string& v) 47 | : code(HTTPCommonHeaders::hash(n)), name(&n), value(&v) { 48 | } 49 | }; 50 | 51 | }} // namespace proxygen::compress 52 | -------------------------------------------------------------------------------- /proxygen/lib/utils/TraceEventContext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | struct TraceEventObserver; 17 | class TraceEvent; 18 | 19 | class TraceEventContext { 20 | public: 21 | // Optional parent id for all sub trace events to add. 22 | uint32_t parentID; 23 | 24 | TraceEventContext(uint32_t pID, 25 | std::vector observers, 26 | bool allTraceEventNeeded = false) 27 | : parentID(pID), 28 | observers_(std::move(observers)), 29 | allTraceEventNeeded_(allTraceEventNeeded) { 30 | } 31 | 32 | explicit TraceEventContext(uint32_t pID = 0, 33 | TraceEventObserver* observer = nullptr, 34 | bool allTraceEventNeeded = false) 35 | : parentID(pID), allTraceEventNeeded_(allTraceEventNeeded) { 36 | if (observer) { 37 | observers_.push_back(observer); 38 | } 39 | } 40 | 41 | void traceEventAvailable(const TraceEvent& event); 42 | 43 | bool isAllTraceEventNeeded() const; 44 | 45 | private: 46 | // Observer vector to observe all trace events about to occur 47 | std::vector observers_; 48 | 49 | // Whether the observers actually care about all trace events from this 50 | // context or only necessary ones. 51 | bool allTraceEventNeeded_; 52 | }; 53 | 54 | } // namespace proxygen 55 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/ErrorCode.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | const char* getErrorCodeString(ErrorCode error) { 16 | switch (error) { 17 | case ErrorCode::NO_ERROR: 18 | return "NO_ERROR"; 19 | case ErrorCode::PROTOCOL_ERROR: 20 | return "PROTOCOL_ERROR"; 21 | case ErrorCode::INTERNAL_ERROR: 22 | return "INTERNAL_ERROR"; 23 | case ErrorCode::FLOW_CONTROL_ERROR: 24 | return "FLOW_CONTROL_ERROR"; 25 | case ErrorCode::SETTINGS_TIMEOUT: 26 | return "SETTINGS_TIMEOUT"; 27 | case ErrorCode::STREAM_CLOSED: 28 | return "STREAM_CLOSED"; 29 | case ErrorCode::FRAME_SIZE_ERROR: 30 | return "FRAME_SIZE_ERROR"; 31 | case ErrorCode::REFUSED_STREAM: 32 | return "REFUSED_STREAM"; 33 | case ErrorCode::CANCEL: 34 | return "CANCEL"; 35 | case ErrorCode::COMPRESSION_ERROR: 36 | return "COMPRESSION_ERROR"; 37 | case ErrorCode::CONNECT_ERROR: 38 | return "CONNECT_ERROR"; 39 | case ErrorCode::ENHANCE_YOUR_CALM: 40 | return "ENHANCE_YOUR_CALM"; 41 | case ErrorCode::INADEQUATE_SECURITY: 42 | return "INADEQUATE_SECURITY"; 43 | case ErrorCode::HTTP_1_1_REQUIRED: 44 | return "HTTP_1_1_REQUIRED"; 45 | case ErrorCode::MAX: 46 | return "MAX"; 47 | } 48 | LOG(FATAL) << "Unreachable"; 49 | return ""; 50 | } 51 | 52 | } // namespace proxygen 53 | -------------------------------------------------------------------------------- /proxygen/lib/http/observer/HTTPTransactionObserverContainer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | class HTTPTransactionObserverAccessor; 17 | 18 | using HTTPTransactionObserverContainerBaseT = folly::ObserverContainer< 19 | HTTPTransactionObserverInterface, 20 | HTTPTransactionObserverAccessor, 21 | folly::ObserverContainerBasePolicyDefault< 22 | HTTPTransactionObserverInterface::Events /* EventEnum */, 23 | 32 /* BitsetSize (max number of interface events) */>>; 24 | 25 | class HTTPTransactionObserverContainer 26 | : public HTTPTransactionObserverContainerBaseT { 27 | public: 28 | using HTTPTransactionObserverContainerBaseT:: 29 | HTTPTransactionObserverContainerBaseT; 30 | ~HTTPTransactionObserverContainer() override = default; 31 | }; 32 | 33 | /** 34 | * Accessor object observed by HTTPTransactionObserver(s). 35 | */ 36 | class HTTPTransactionObserverAccessor { 37 | public: 38 | virtual ~HTTPTransactionObserverAccessor() = default; 39 | 40 | virtual bool addObserver( 41 | HTTPTransactionObserverContainer::Observer* observer) = 0; 42 | 43 | virtual bool addObserver( 44 | std::shared_ptr observer) = 0; 45 | 46 | [[nodiscard]] virtual uint64_t getTxnId() const = 0; 47 | }; 48 | 49 | } // namespace proxygen 50 | -------------------------------------------------------------------------------- /proxygen/lib/http/SynchronizedLruQuicPskCache.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | namespace proxygen { 12 | 13 | SynchronizedLruQuicPskCache::SynchronizedLruQuicPskCache(uint64_t mapMax) 14 | : cache_(EvictingPskMap(mapMax)) { 15 | } 16 | 17 | folly::Optional SynchronizedLruQuicPskCache::getPsk( 18 | const std::string& identity) { 19 | auto cacheMap = cache_.wlock(); 20 | auto result = cacheMap->find(identity); 21 | if (result != cacheMap->end()) { 22 | if (std::chrono::system_clock::now() > 23 | result->second.cachedPsk.ticketExpirationTime) { 24 | VLOG(1) << "PSK expired: " << identity << ", id: " 25 | << (result->second.cachedPsk.serverCert 26 | ? result->second.cachedPsk.serverCert->getIdentity() 27 | : "none"); 28 | cacheMap->erase(result); 29 | return folly::none; 30 | } 31 | return result->second; 32 | } else { 33 | return folly::none; 34 | } 35 | } 36 | 37 | void SynchronizedLruQuicPskCache::putPsk(const std::string& identity, 38 | quic::QuicCachedPsk psk) { 39 | auto cacheMap = cache_.wlock(); 40 | cacheMap->set(identity, std::move(psk)); 41 | } 42 | 43 | void SynchronizedLruQuicPskCache::removePsk(const std::string& identity) { 44 | auto cacheMap = cache_.wlock(); 45 | cacheMap->erase(identity); 46 | } 47 | 48 | } // namespace proxygen 49 | -------------------------------------------------------------------------------- /proxygen/lib/http/stats/HeaderCodecStats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace proxygen { 17 | 18 | class TLHeaderCodecStats : public HeaderCodec::Stats { 19 | public: 20 | explicit TLHeaderCodecStats(const std::string& prefix); 21 | ~TLHeaderCodecStats() override { 22 | } 23 | TLHeaderCodecStats(const TLHeaderCodecStats&) = delete; 24 | TLHeaderCodecStats& operator=(const TLHeaderCodecStats&) = delete; 25 | 26 | void recordEncode(HeaderCodec::Type type, HTTPHeaderSize& size) override; 27 | void recordDecode(HeaderCodec::Type type, HTTPHeaderSize& size) override; 28 | void recordDecodeError(HeaderCodec::Type type) override; 29 | void recordDecodeTooLarge(HeaderCodec::Type type) override; 30 | 31 | private: 32 | std::vector> encodeCompr_; 33 | std::vector> encodeUncompr_; 34 | std::vector> decodeCompr_; 35 | std::vector> decodeUncompr_; 36 | std::vector encodes_; 37 | std::vector decodes_; 38 | std::vector decodeErrors_; 39 | std::vector decodeTooLarge_; 40 | }; 41 | 42 | } // namespace proxygen 43 | -------------------------------------------------------------------------------- /proxygen/lib/http/HTTPCommonHeaders.txt: -------------------------------------------------------------------------------- 1 | :Authority 2 | :Method 3 | :Path 4 | :Scheme 5 | :Status 6 | :Protocol 7 | Accept 8 | Accept-Charset 9 | Accept-Encoding 10 | Accept-Language 11 | Accept-Ranges 12 | Access-Control-Allow-Credentials 13 | Access-Control-Allow-Headers 14 | Access-Control-Allow-Methods 15 | Access-Control-Allow-Origin 16 | Access-Control-Expose-Headers 17 | Access-Control-Max-Age 18 | Access-Control-Request-Headers 19 | Access-Control-Request-Method 20 | Age 21 | Alt-Svc 22 | Authorization 23 | Cache-Control 24 | client_timeout 25 | Connection 26 | content-digest 27 | Content-Disposition 28 | Content-Encoding 29 | Content-Language 30 | Content-Length 31 | Content-Range 32 | content-security-policy 33 | Content-Type 34 | Cookie 35 | cross-origin-embedder-policy-report-only 36 | cross-origin-opener-policy 37 | cross-origin-resource-policy 38 | Date 39 | document-policy 40 | Edge-Control 41 | ETag 42 | Expect 43 | Expires 44 | facebook-api-version 45 | Host 46 | If-Modified-Since 47 | If-None-Match 48 | Keep-Alive 49 | Last-Modified 50 | Link 51 | Location 52 | Origin 53 | origin-trial 54 | permissions-policy 55 | Pragma 56 | Priority 57 | Proxy-Authenticate 58 | Proxy-Authorization 59 | Proxy-Connection 60 | Proxy-Status 61 | queue_timeout 62 | Range 63 | Referer 64 | report-to 65 | Retry-After 66 | rpckind 67 | Sec-WebSocket-Key 68 | Sec-WebSocket-Accept 69 | Server 70 | Set-Cookie 71 | Strict-Transport-Security 72 | TE 73 | thrift_priority 74 | timing-allow-origin 75 | Trailer 76 | Transfer-Encoding 77 | Upgrade 78 | User-Agent 79 | Vary 80 | Via 81 | WWW-Authenticate 82 | X-Content-Type-Options 83 | X-Forwarded-For 84 | X-Forwarded-Proto 85 | X-Frame-Options 86 | X-Thrift-Protocol 87 | X-XSS-Protection 88 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Meta Platforms, Inc. and affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | 7 | if(NOT BUILD_TESTS) 8 | return() 9 | endif() 10 | 11 | add_library(codectestutils TestUtils.cpp) 12 | target_include_directories( 13 | codectestutils PUBLIC 14 | $ 15 | ${LIBGMOCK_INCLUDE_DIR} 16 | ${LIBGTEST_INCLUDE_DIR} 17 | ) 18 | target_compile_options( 19 | codectestutils PRIVATE 20 | ${_PROXYGEN_COMMON_COMPILE_OPTIONS} 21 | ) 22 | target_link_libraries(codectestutils PUBLIC proxygen) 23 | 24 | proxygen_add_test(TARGET CodecTests 25 | SOURCES 26 | CrossCodecTest.cpp 27 | CodecUtilTests.cpp 28 | DefaultHTTPCodecFactoryTest.cpp 29 | FilterTests.cpp 30 | HTTP1xCodecTest.cpp 31 | HTTP2CodecTest.cpp 32 | HTTP2FramerTest.cpp 33 | DEPENDS 34 | codectestutils 35 | proxygen 36 | testmain 37 | ) 38 | 39 | proxygen_add_test(TARGET HQFramerTests 40 | SOURCES 41 | HQFramerTest.cpp 42 | DEPENDS 43 | codectestutils 44 | proxygen 45 | testmain 46 | mvfst::mvfst_codec_types 47 | ) 48 | 49 | proxygen_add_test(TARGET HQCodecTests 50 | SOURCES 51 | HQCodecTest.cpp 52 | HQMultiCodecTest.cpp 53 | DEPENDS 54 | codectestutils 55 | proxygen 56 | testmain 57 | mvfst::mvfst_codec_types 58 | mvfst::mvfst_state_machine 59 | ) 60 | 61 | proxygen_add_test(TARGET BinaryCodecTests 62 | SOURCES 63 | HTTPBinaryCodecTest.cpp 64 | DEPENDS 65 | codectestutils 66 | proxygen 67 | testmain 68 | ) 69 | -------------------------------------------------------------------------------- /proxygen/lib/dns/NaiveResolutionCallback.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include "proxygen/lib/dns/NaiveResolutionCallback.h" 10 | 11 | #include 12 | 13 | namespace proxygen { 14 | 15 | using folly::exception_wrapper; 16 | using folly::make_exception_wrapper; 17 | using DNSAnswer = DNSResolver::Answer; 18 | using DNSException = DNSResolver::Exception; 19 | 20 | using DNSAnswers = std::vector; 21 | 22 | namespace { 23 | const std::string kNoAddr("No valid address or name found"); 24 | static bool isDNSAnswer(const DNSAnswer& a) { 25 | return (a.type == DNSAnswer::AT_ADDRESS || a.type == DNSAnswer::AT_NAME); 26 | } 27 | } // namespace 28 | 29 | // public static 30 | exception_wrapper NaiveResolutionCallback::makeNoNameException() noexcept { 31 | return make_exception_wrapper(DNSResolver::NODATA, kNoAddr); 32 | } 33 | 34 | // public 35 | void NaiveResolutionCallback::resolutionSuccess(DNSAnswers answers) noexcept { 36 | folly::exception_wrapper ex; 37 | 38 | bool have_answer = std::any_of(answers.begin(), answers.end(), isDNSAnswer); 39 | if (!have_answer) { 40 | auto err = NaiveResolutionCallback::makeNoNameException(); 41 | ex = std::move(err); 42 | } 43 | 44 | handler_(std::move(answers), std::move(ex)); 45 | delete this; 46 | } 47 | 48 | // public 49 | void NaiveResolutionCallback::resolutionError( 50 | const exception_wrapper& exp) noexcept { 51 | handler_({}, std::move(exp)); 52 | delete this; 53 | } 54 | 55 | } // namespace proxygen 56 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/test/MockSessionObserver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace proxygen { 16 | 17 | class MockSessionObserver 18 | : public HTTPSessionObserverContainerBaseT::ManagedObserver { 19 | public: 20 | using HTTPSessionObserverContainerBaseT::ManagedObserver::ManagedObserver; 21 | MOCK_METHOD(void, attached, (HTTPSessionObserverAccessor*), (noexcept)); 22 | MOCK_METHOD(void, detached, (HTTPSessionObserverAccessor*), (noexcept)); 23 | MOCK_METHOD(void, 24 | destroyed, 25 | (HTTPSessionObserverAccessor*, 26 | typename HTTPSessionObserverContainer::ObserverContainer:: 27 | ManagedObserver::DestroyContext*), 28 | (noexcept)); 29 | MOCK_METHOD(void, 30 | requestStarted, 31 | (HTTPSessionObserverAccessor*, const RequestStartedEvent&), 32 | (noexcept)); 33 | MOCK_METHOD(void, 34 | preWrite, 35 | (HTTPSessionObserverAccessor*, const PreWriteEvent&), 36 | (noexcept)); 37 | MOCK_METHOD(void, 38 | pingReply, 39 | (HTTPSessionObserverAccessor*, const PingReplyEvent&), 40 | (noexcept)); 41 | ~MockSessionObserver() override = default; 42 | }; 43 | } // namespace proxygen 44 | -------------------------------------------------------------------------------- /proxygen/lib/pools/generators/ServerListGenerator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | using folly::EventBase; 15 | using std::vector; 16 | using std::chrono::milliseconds; 17 | 18 | namespace proxygen { 19 | 20 | void ServerListGenerator::attachEventBase(EventBase* base) { 21 | CHECK(!eventBase_); 22 | CHECK(base->isInEventBaseThread()); 23 | 24 | eventBase_ = base; 25 | } 26 | 27 | void ServerListGenerator::detachEventBase() { 28 | CHECK(!eventBase_ || eventBase_->isInEventBaseThread()); 29 | 30 | eventBase_ = nullptr; 31 | } 32 | 33 | void ServerListGenerator::listServersBlocking(vector* results, 34 | milliseconds timeout) { 35 | // Run a EventBase to drive the asynchronous listServers() call until it 36 | // finishes. 37 | EventBase eventBase; 38 | ServerListCallback callback; 39 | attachEventBase(&eventBase); 40 | listServers(&callback, timeout); 41 | eventBase.loop(); 42 | detachEventBase(); 43 | 44 | if (callback.status != ServerListCallback::SUCCESS) { 45 | if (!callback.errorPtr) { 46 | LOG(FATAL) 47 | << "ServerListGenerator finished without invoking callback, timeout:" 48 | << timeout.count(); 49 | } 50 | std::rethrow_exception(callback.errorPtr); 51 | } 52 | 53 | results->swap(callback.servers); 54 | } 55 | 56 | } // namespace proxygen 57 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/CodecErrorResponseHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | using folly::IOBuf; 14 | using std::unique_ptr; 15 | 16 | namespace proxygen { 17 | 18 | CodecErrorResponseHandler::CodecErrorResponseHandler(ErrorCode /*statusCode*/) 19 | : txn_(nullptr) { 20 | } 21 | 22 | CodecErrorResponseHandler::~CodecErrorResponseHandler() { 23 | } 24 | 25 | void CodecErrorResponseHandler::setTransaction(HTTPTransaction* txn) noexcept { 26 | txn_ = txn; 27 | } 28 | 29 | void CodecErrorResponseHandler::detachTransaction() noexcept { 30 | delete this; 31 | } 32 | 33 | void CodecErrorResponseHandler::onHeadersComplete( 34 | std::unique_ptr /*msg*/) noexcept { 35 | VLOG(4) << "discarding headers"; 36 | } 37 | 38 | void CodecErrorResponseHandler::onBody(unique_ptr /*chain*/) noexcept { 39 | VLOG(4) << "discarding request body"; 40 | } 41 | 42 | void CodecErrorResponseHandler::onTrailers( 43 | unique_ptr /*trailers*/) noexcept { 44 | VLOG(4) << "discarding request trailers"; 45 | } 46 | 47 | void CodecErrorResponseHandler::onEOM() noexcept { 48 | } 49 | 50 | void CodecErrorResponseHandler::onUpgrade( 51 | UpgradeProtocol /*protocol*/) noexcept { 52 | } 53 | 54 | void CodecErrorResponseHandler::onError(const HTTPException& error) noexcept { 55 | VLOG(4) << "processing error " << error; 56 | txn_->sendAbort(); 57 | } 58 | 59 | } // namespace proxygen 60 | -------------------------------------------------------------------------------- /proxygen/httpserver/samples/hq/quic-interop/Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | # Full build image 3 | # 4 | FROM martenseemann/quic-network-simulator-endpoint:latest 5 | 6 | ENV TZ=America/Los_Angeles 7 | RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone 8 | RUN apt-get update 9 | 10 | RUN apt-get --yes --fix-missing update 11 | 12 | # Get and build proxygen with HTTP/3 support 13 | RUN apt-get install --yes wget net-tools iputils-ping tcpdump ethtool iperf git sudo cmake python3 libssl-dev m4 zlib1g-dev gcc-10 g++-10 14 | RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 15 | RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100 16 | RUN update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-10 100 17 | RUN update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-10 100 18 | RUN mkdir proxygen 19 | COPY . /proxygen 20 | RUN cd proxygen && ./getdeps.sh --no-tests --allow-system-packages 21 | RUN ldd /tmp/fbcode_builder_getdeps-ZproxygenZbuildZfbcode_builder-root/build/proxygen/proxygen/httpserver/hq | grep "=> /" | awk '{print $3}' > libs.txt 22 | RUN tar cvf libs.tar --dereference --files-from=libs.txt 23 | 24 | # 25 | # Minimal image 26 | # 27 | FROM martenseemann/quic-network-simulator-endpoint:latest 28 | # copy run script 29 | COPY proxygen/httpserver/samples/hq/quic-interop/run_endpoint.sh . 30 | RUN chmod +x run_endpoint.sh 31 | 32 | # Copy HQ 33 | COPY --from=0 /tmp/fbcode_builder_getdeps-ZproxygenZbuildZfbcode_builder-root/build/proxygen/proxygen/httpserver/hq /proxygen/_build/proxygen/bin/hq 34 | # Copy shared libs 35 | COPY --from=0 libs.tar / 36 | RUN tar xvf libs.tar 37 | RUN rm libs.tar 38 | # Create the logs directory 39 | RUN mkdir /logs 40 | 41 | ENTRYPOINT [ "./run_endpoint.sh" ] 42 | -------------------------------------------------------------------------------- /proxygen/lib/sampling/SamplingFunctions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace proxygen { 18 | 19 | inline bool shouldLogQuicConnection(const quic::ConnectionId& connId, 20 | int64_t salt, 21 | uint32_t weight) { 22 | // Logging is off 23 | if (weight == 0) { 24 | return false; 25 | } 26 | // Hash the combination of connection id and salt. 27 | // If the hash value is less than or equal to (2^32-1)/weight, log, 28 | // in which case sample ratio is 1/weight. 29 | 30 | // Hash code stolen from folly::hash::hash_combine_generic. 31 | // Reason why not using hash_combine_generic directly is that we want to 32 | // generate a hash value whose type size is consistent across systems, 33 | // so that server and client can be sure that they are logging the same 34 | // connection. However hash_combine_generic returns a size_t type which does 35 | // not satisfy this requirement. 36 | uint32_t connIdNumHash = folly::hash::fnv32_buf(connId.data(), connId.size()); 37 | uint32_t saltHash = folly::hash::fnv32_buf(&salt, sizeof(salt)); 38 | uint32_t hash = 39 | folly::hash::twang_32from64((uint64_t(connIdNumHash) << 32) | saltHash); 40 | if (hash <= std::numeric_limits::max() / weight) { 41 | return true; 42 | } 43 | return false; 44 | } 45 | 46 | } // namespace proxygen 47 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/HTTPTransactionEgressSM.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | class HTTPTransactionEgressSMData { 17 | public: 18 | enum class State : uint8_t { 19 | Start, 20 | HeadersSent, 21 | DatagramSent, 22 | RegularBodySent, 23 | ChunkHeaderSent, 24 | ChunkBodySent, 25 | ChunkTerminatorSent, 26 | TrailersSent, 27 | EOMQueued, 28 | SendingDone, 29 | 30 | // Must be last 31 | NumStates 32 | }; 33 | 34 | enum class Event : uint8_t { 35 | // API accessible transitions 36 | sendHeaders, 37 | sendDatagram, 38 | sendBody, 39 | sendChunkHeader, 40 | sendChunkTerminator, 41 | sendTrailers, 42 | sendEOM, 43 | // Internal state transitions 44 | eomFlushed, 45 | 46 | // Must be last 47 | NumEvents 48 | }; 49 | 50 | static State getInitialState() { 51 | return State::Start; 52 | } 53 | 54 | static std::pair find(State s, Event e); 55 | 56 | static const std::string getName() { 57 | return "HTTPTransactionEgress"; 58 | } 59 | }; 60 | 61 | std::ostream& operator<<(std::ostream& os, 62 | HTTPTransactionEgressSMData::State s); 63 | 64 | std::ostream& operator<<(std::ostream& os, 65 | HTTPTransactionEgressSMData::Event e); 66 | 67 | using HTTPTransactionEgressSM = StateMachine; 68 | 69 | } // namespace proxygen 70 | -------------------------------------------------------------------------------- /proxygen/lib/utils/AcceptorAddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace proxygen { 16 | 17 | struct AcceptorAddress { 18 | enum class AcceptorType { TCP, UDP }; 19 | 20 | AcceptorAddress() = delete; 21 | AcceptorAddress(folly::SocketAddress address, AcceptorType protocol) 22 | : address(address), protocol(protocol) { 23 | } 24 | 25 | folly::SocketAddress address; 26 | AcceptorType protocol; 27 | }; 28 | 29 | inline bool operator<(const AcceptorAddress& lv, const AcceptorAddress& rv) { 30 | if (lv.address < rv.address) { 31 | return true; 32 | } 33 | if (rv.address < lv.address) { 34 | return false; 35 | } 36 | return lv.protocol < rv.protocol; 37 | } 38 | 39 | inline std::ostream& operator<<(std::ostream& os, 40 | const AcceptorAddress::AcceptorType& accType) { 41 | switch (accType) { 42 | case AcceptorAddress::AcceptorType::TCP: 43 | os << "TCP"; 44 | break; 45 | case AcceptorAddress::AcceptorType::UDP: 46 | os << "UDP"; 47 | break; 48 | default: 49 | LOG(FATAL) << "Unknown Acceptor type."; 50 | } 51 | return os; 52 | } 53 | 54 | inline std::ostream& operator<<(std::ostream& os, 55 | const AcceptorAddress& accAddr) { 56 | os << accAddr.address << "<" << accAddr.protocol << ">"; 57 | return os; 58 | } 59 | 60 | using AcceptorType = AcceptorAddress::AcceptorType; 61 | 62 | } // namespace proxygen 63 | -------------------------------------------------------------------------------- /proxygen/lib/http/codec/HTTP2Constants.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | 11 | namespace proxygen { namespace http2 { 12 | 13 | const uint32_t kFrameHeaderSize = 9; 14 | 15 | const uint32_t kFrameHeadersBaseMaxSize = kFramePrioritySize + 1; 16 | const uint32_t kFramePrioritySize = 5; 17 | const uint32_t kFrameStreamIDSize = 4; 18 | const uint32_t kFrameRstStreamSize = 4; 19 | const uint32_t kFramePushPromiseSize = 4; 20 | const uint32_t kFramePingSize = 8; 21 | const uint32_t kFrameGoawaySize = 8; 22 | const uint32_t kFrameWindowUpdateSize = 4; 23 | const uint32_t kFrameCertificateRequestSizeBase = 2; 24 | const uint32_t kFrameCertificateSizeBase = 2; 25 | 26 | const uint32_t kFrameAltSvcSizeBase = 8; 27 | 28 | const uint32_t kMaxFramePayloadLengthMin = (1u << 14); 29 | const uint32_t kMaxFramePayloadLength = (1u << 24) - 1; 30 | const uint32_t kMaxStreamID = (1u << 31) - 1; 31 | const uint32_t kInitialWindow = (1u << 16) - 1; 32 | const uint32_t kMaxWindowUpdateSize = (1u << 31) - 1; 33 | const uint32_t kMaxHeaderTableSize = (1u << 16); 34 | 35 | const uint32_t kMaxAuthenticatorBufSize = 0x20000; // 128k 36 | 37 | const std::string kConnectionPreface("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"); 38 | 39 | const std::string kProtocolString("h2"); 40 | const std::string kProtocolDraftString("h2-14"); 41 | const std::string kProtocolExperimentalString("h2-fb"); 42 | const std::string kProtocolCleartextString("h2c"); 43 | const std::string kProtocolSettingsHeader("HTTP2-Settings"); 44 | 45 | }} // namespace proxygen::http2 46 | -------------------------------------------------------------------------------- /proxygen/lib/http/HTTP3ErrorCode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace proxygen { 16 | 17 | namespace HTTP3 { 18 | enum ErrorCode : uint64_t { 19 | // HTTP/3 error codes from draft 20 | HTTP_NO_ERROR = 0x100, 21 | HTTP_GENERAL_PROTOCOL_ERROR = 0x101, 22 | HTTP_INTERNAL_ERROR = 0x102, 23 | HTTP_STREAM_CREATION_ERROR = 0x103, 24 | HTTP_CLOSED_CRITICAL_STREAM = 0x104, 25 | HTTP_FRAME_UNEXPECTED = 0x105, 26 | HTTP_FRAME_ERROR = 0x106, 27 | HTTP_EXCESSIVE_LOAD = 0x107, 28 | HTTP_ID_ERROR = 0x108, 29 | HTTP_SETTINGS_ERROR = 0x109, 30 | HTTP_MISSING_SETTINGS = 0x10A, 31 | HTTP_REQUEST_REJECTED = 0x10B, 32 | HTTP_REQUEST_CANCELLED = 0x10C, 33 | HTTP_INCOMPLETE_REQUEST = 0x10D, 34 | HTTP_MESSAGE_ERROR = 0x10E, 35 | HTTP_CONNECT_ERROR = 0x10F, 36 | HTTP_VERSION_FALLBACK = 0x110, 37 | // QPACK 0x200, all from draft 38 | HTTP_QPACK_DECOMPRESSION_FAILED = 0x200, 39 | HTTP_QPACK_ENCODER_STREAM_ERROR = 0x201, 40 | HTTP_QPACK_DECODER_STREAM_ERROR = 0x202, 41 | 42 | // Internal use only 43 | GIVEUP_ZERO_RTT = 0xF2 44 | }; 45 | } 46 | inline bool isQPACKError(HTTP3::ErrorCode err) { 47 | return err == HTTP3::ErrorCode::HTTP_QPACK_DECOMPRESSION_FAILED || 48 | err == HTTP3::ErrorCode::HTTP_QPACK_ENCODER_STREAM_ERROR || 49 | err == HTTP3::ErrorCode::HTTP_QPACK_DECODER_STREAM_ERROR; 50 | } 51 | 52 | std::string toString(HTTP3::ErrorCode code); 53 | std::vector getAllHTTP3ErrorCodes(); 54 | } // namespace proxygen 55 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/HTTPDefaultSessionCodecFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | namespace { 15 | proxygen::HTTPCodecFactory::CodecConfig getCodecConfigFromAcceptorConfig( 16 | const proxygen::AcceptorConfiguration& accConfig) { 17 | proxygen::HTTPCodecFactory::CodecConfig config; 18 | config.h1.forceHTTP1xCodecTo1_1 = accConfig.forceHTTP1_0_to_1_1; 19 | config.h1.allowedH1UpgradeProtocols = 20 | accConfig.allowedPlaintextUpgradeProtocols; 21 | config.h2.headerIndexingStrategy = accConfig.headerIndexingStrategy; 22 | return config; 23 | } 24 | } // namespace 25 | 26 | namespace proxygen { 27 | 28 | HTTPDefaultSessionCodecFactory::HTTPDefaultSessionCodecFactory( 29 | std::shared_ptr accConfig) 30 | : HTTPCodecFactory(getCodecConfigFromAcceptorConfig(*accConfig)), 31 | accConfig_{std::move(accConfig)} { 32 | } 33 | 34 | std::unique_ptr HTTPDefaultSessionCodecFactory::getCodec( 35 | const std::string& nextProtocol, TransportDirection direction, bool isTLS) { 36 | DefaultHTTPCodecFactory factory(configFn_()); 37 | if (!isTLS && 38 | (accConfig_->plaintextProtocol == http2::kProtocolCleartextString)) { 39 | return factory.getCodec(http2::kProtocolString, direction, isTLS); 40 | } 41 | return factory.getCodec(nextProtocol, direction, isTLS); 42 | } 43 | } // namespace proxygen 44 | -------------------------------------------------------------------------------- /proxygen/lib/http/session/SecondaryAuthManagerBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace proxygen { 15 | 16 | class SecondaryAuthManagerBase { 17 | public: 18 | virtual ~SecondaryAuthManagerBase() = default; 19 | 20 | /** 21 | * Generate an authenticator request given a certificate_request_context and 22 | * a set of extensions. 23 | * @return (request ID, encoded authenticator request) 24 | */ 25 | virtual std::pair> createAuthRequest( 26 | std::unique_ptr certRequestContext, 27 | std::vector extensions) = 0; 28 | 29 | /** 30 | * Generate an authenticator request given the Request-ID and authenticator 31 | * request.. 32 | * @return (cert ID, encoded authenticator) 33 | */ 34 | virtual std::pair> getAuthenticator( 35 | const fizz::AsyncFizzBase& transport, 36 | TransportDirection dir, 37 | uint16_t requestId, 38 | std::unique_ptr authRequest) = 0; 39 | 40 | /** 41 | * Validate an authenticator and cache the received certificate along with the 42 | * Cert-ID if it is valid. 43 | */ 44 | virtual bool validateAuthenticator( 45 | const fizz::AsyncFizzBase& transport, 46 | TransportDirection dir, 47 | uint16_t certId, 48 | std::unique_ptr authenticator) = 0; 49 | }; 50 | 51 | } // namespace proxygen 52 | --------------------------------------------------------------------------------