Skip to content

Commit 05e0fe8

Browse files
Cameron Evansmeta-codesync[bot]
authored andcommitted
Add serializedRequestBuffer to service interceptor RequestInfo.
Summary: This adds the serializedRequestBuffer parameter to ServiceInterceptorBase::RequestInfo. Note: - We're exposing this as a `const folly::IOBuf *` instead of a `const SerializedRequest *` since the latter gives mutable access to the underlying buffer. Meta Internal: This feature will be used by the security team to log requests that come from devservers. Reviewed By: evanjzou Differential Revision: D85141299 fbshipit-source-id: bea5bdf93f4184d341fe50fa01ba69e0728b9f51
1 parent 78608b1 commit 05e0fe8

69 files changed

Lines changed: 8007 additions & 5048 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

third-party/thrift/src/thrift/compiler/generate/templates/cpp2/service_tcc/process_and_return.mustache

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,15 @@ void {{service:parent_service_cpp_name}}AsyncProcessor::executeRequest_{{#servic
162162
{{#service:interaction?}}
163163
auto& iface = static_cast<apache::thrift::ServiceHandler<{{service:parent_service_cpp_name}}>::{{service:name}}If&>(*tile);
164164
{{/service:interaction?}}
165+
apache::thrift::SerializedRequest serializedRequest{nullptr};
165166
try {
166167
auto pargs = args.pargs();
168+
serializedRequest = apache::thrift::detail::ServerRequestHelper::compressedRequest(
169+
std::move(serverRequest)).uncompress();
167170
deserializeRequest<ProtocolIn_>(
168171
pargs,
169172
"{{> common/function_name}}",
170-
apache::thrift::detail::ServerRequestHelper::compressedRequest(
171-
std::move(serverRequest))
172-
.uncompress(),
173+
serializedRequest,
173174
ctxStack.get());
174175
} catch (...) {
175176
{{#function:oneway?}}
@@ -283,19 +284,25 @@ void {{service:parent_service_cpp_name}}AsyncProcessor::executeRequest_{{#servic
283284
#if FOLLY_HAS_COROUTINES
284285
if (apache::thrift::detail::shouldProcessServiceInterceptorsOnRequest(
285286
*callback)) {
286-
[](auto callback, auto executeHandler, ArgsState args)
287-
-> folly::coro::Task<void> {
287+
[](
288+
auto callback,
289+
auto executeHandler,
290+
ArgsState args,
291+
const apache::thrift::SerializedRequest&& serializedRequest
292+
) -> folly::coro::Task<void> {
288293
auto argRefs = args.asTupleOfRefs();
289294
co_await apache::thrift::detail::processServiceInterceptorsOnRequest(
290295
*callback,
291-
apache::thrift::detail::ServiceInterceptorOnRequestArguments(
292-
argRefs));
296+
apache::thrift::detail::ServiceInterceptorOnRequestArguments(argRefs),
297+
std::forward<const apache::thrift::SerializedRequest>(serializedRequest));
293298
executeHandler(std::move(callback), std::move(args));
294-
}(std::move(callback), makeExecuteHandler(), std::move(args))
295-
.scheduleOn(
296-
apache::thrift::detail::ServerRequestHelper::executor(
297-
serverRequest))
298-
.startInlineUnsafe();
299+
}(
300+
std::move(callback),
301+
makeExecuteHandler(),
302+
std::move(args),
303+
std::move(serializedRequest))
304+
.scheduleOn(apache::thrift::detail::ServerRequestHelper::executor(serverRequest))
305+
.startInlineUnsafe();
299306
} else {
300307
makeExecuteHandler()(std::move(callback), std::move(args));
301308
}

third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/cpp2/gen-cpp2/AdapterService.tcc

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ void AdapterServiceAsyncProcessor::executeRequest_count(
7171
this->getServiceName(),
7272
"AdapterService.count",
7373
serverRequest.requestContext());
74+
apache::thrift::SerializedRequest serializedRequest{nullptr};
7475
try {
7576
auto pargs = args.pargs();
77+
serializedRequest = apache::thrift::detail::ServerRequestHelper::compressedRequest(
78+
std::move(serverRequest)).uncompress();
7679
deserializeRequest<ProtocolIn_>(
7780
pargs,
7881
"count",
79-
apache::thrift::detail::ServerRequestHelper::compressedRequest(
80-
std::move(serverRequest))
81-
.uncompress(),
82+
serializedRequest,
8283
ctxStack.get());
8384
} catch (...) {
8485
folly::exception_wrapper ew(std::current_exception());
@@ -134,19 +135,25 @@ void AdapterServiceAsyncProcessor::executeRequest_count(
134135
#if FOLLY_HAS_COROUTINES
135136
if (apache::thrift::detail::shouldProcessServiceInterceptorsOnRequest(
136137
*callback)) {
137-
[](auto callback, auto executeHandler, ArgsState args)
138-
-> folly::coro::Task<void> {
138+
[](
139+
auto callback,
140+
auto executeHandler,
141+
ArgsState args,
142+
const apache::thrift::SerializedRequest&& serializedRequest
143+
) -> folly::coro::Task<void> {
139144
auto argRefs = args.asTupleOfRefs();
140145
co_await apache::thrift::detail::processServiceInterceptorsOnRequest(
141146
*callback,
142-
apache::thrift::detail::ServiceInterceptorOnRequestArguments(
143-
argRefs));
147+
apache::thrift::detail::ServiceInterceptorOnRequestArguments(argRefs),
148+
std::forward<const apache::thrift::SerializedRequest>(serializedRequest));
144149
executeHandler(std::move(callback), std::move(args));
145-
}(std::move(callback), makeExecuteHandler(), std::move(args))
146-
.scheduleOn(
147-
apache::thrift::detail::ServerRequestHelper::executor(
148-
serverRequest))
149-
.startInlineUnsafe();
150+
}(
151+
std::move(callback),
152+
makeExecuteHandler(),
153+
std::move(args),
154+
std::move(serializedRequest))
155+
.scheduleOn(apache::thrift::detail::ServerRequestHelper::executor(serverRequest))
156+
.startInlineUnsafe();
150157
} else {
151158
makeExecuteHandler()(std::move(callback), std::move(args));
152159
}
@@ -241,14 +248,15 @@ void AdapterServiceAsyncProcessor::executeRequest_adaptedTypes(
241248
this->getServiceName(),
242249
"AdapterService.adaptedTypes",
243250
serverRequest.requestContext());
251+
apache::thrift::SerializedRequest serializedRequest{nullptr};
244252
try {
245253
auto pargs = args.pargs();
254+
serializedRequest = apache::thrift::detail::ServerRequestHelper::compressedRequest(
255+
std::move(serverRequest)).uncompress();
246256
deserializeRequest<ProtocolIn_>(
247257
pargs,
248258
"adaptedTypes",
249-
apache::thrift::detail::ServerRequestHelper::compressedRequest(
250-
std::move(serverRequest))
251-
.uncompress(),
259+
serializedRequest,
252260
ctxStack.get());
253261
} catch (...) {
254262
folly::exception_wrapper ew(std::current_exception());
@@ -304,19 +312,25 @@ void AdapterServiceAsyncProcessor::executeRequest_adaptedTypes(
304312
#if FOLLY_HAS_COROUTINES
305313
if (apache::thrift::detail::shouldProcessServiceInterceptorsOnRequest(
306314
*callback)) {
307-
[](auto callback, auto executeHandler, ArgsState args)
308-
-> folly::coro::Task<void> {
315+
[](
316+
auto callback,
317+
auto executeHandler,
318+
ArgsState args,
319+
const apache::thrift::SerializedRequest&& serializedRequest
320+
) -> folly::coro::Task<void> {
309321
auto argRefs = args.asTupleOfRefs();
310322
co_await apache::thrift::detail::processServiceInterceptorsOnRequest(
311323
*callback,
312-
apache::thrift::detail::ServiceInterceptorOnRequestArguments(
313-
argRefs));
324+
apache::thrift::detail::ServiceInterceptorOnRequestArguments(argRefs),
325+
std::forward<const apache::thrift::SerializedRequest>(serializedRequest));
314326
executeHandler(std::move(callback), std::move(args));
315-
}(std::move(callback), makeExecuteHandler(), std::move(args))
316-
.scheduleOn(
317-
apache::thrift::detail::ServerRequestHelper::executor(
318-
serverRequest))
319-
.startInlineUnsafe();
327+
}(
328+
std::move(callback),
329+
makeExecuteHandler(),
330+
std::move(args),
331+
std::move(serializedRequest))
332+
.scheduleOn(apache::thrift::detail::ServerRequestHelper::executor(serverRequest))
333+
.startInlineUnsafe();
320334
} else {
321335
makeExecuteHandler()(std::move(callback), std::move(args));
322336
}

third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/cpp2/gen-cpp2/Service.tcc

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ void ServiceAsyncProcessor::executeRequest_func(
7878
this->getServiceName(),
7979
"Service.func",
8080
serverRequest.requestContext());
81+
apache::thrift::SerializedRequest serializedRequest{nullptr};
8182
try {
8283
auto pargs = args.pargs();
84+
serializedRequest = apache::thrift::detail::ServerRequestHelper::compressedRequest(
85+
std::move(serverRequest)).uncompress();
8386
deserializeRequest<ProtocolIn_>(
8487
pargs,
8588
"func",
86-
apache::thrift::detail::ServerRequestHelper::compressedRequest(
87-
std::move(serverRequest))
88-
.uncompress(),
89+
serializedRequest,
8990
ctxStack.get());
9091
} catch (...) {
9192
folly::exception_wrapper ew(std::current_exception());
@@ -141,19 +142,25 @@ void ServiceAsyncProcessor::executeRequest_func(
141142
#if FOLLY_HAS_COROUTINES
142143
if (apache::thrift::detail::shouldProcessServiceInterceptorsOnRequest(
143144
*callback)) {
144-
[](auto callback, auto executeHandler, ArgsState args)
145-
-> folly::coro::Task<void> {
145+
[](
146+
auto callback,
147+
auto executeHandler,
148+
ArgsState args,
149+
const apache::thrift::SerializedRequest&& serializedRequest
150+
) -> folly::coro::Task<void> {
146151
auto argRefs = args.asTupleOfRefs();
147152
co_await apache::thrift::detail::processServiceInterceptorsOnRequest(
148153
*callback,
149-
apache::thrift::detail::ServiceInterceptorOnRequestArguments(
150-
argRefs));
154+
apache::thrift::detail::ServiceInterceptorOnRequestArguments(argRefs),
155+
std::forward<const apache::thrift::SerializedRequest>(serializedRequest));
151156
executeHandler(std::move(callback), std::move(args));
152-
}(std::move(callback), makeExecuteHandler(), std::move(args))
153-
.scheduleOn(
154-
apache::thrift::detail::ServerRequestHelper::executor(
155-
serverRequest))
156-
.startInlineUnsafe();
157+
}(
158+
std::move(callback),
159+
makeExecuteHandler(),
160+
std::move(args),
161+
std::move(serializedRequest))
162+
.scheduleOn(apache::thrift::detail::ServerRequestHelper::executor(serverRequest))
163+
.startInlineUnsafe();
157164
} else {
158165
makeExecuteHandler()(std::move(callback), std::move(args));
159166
}

third-party/thrift/src/thrift/compiler/test/fixtures/basic-annotations/out/cpp2/gen-cpp2/BadService.tcc

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@ void GoodServiceAsyncProcessor::executeRequest_bar(
6969
this->getServiceName(),
7070
"BadService.bar",
7171
serverRequest.requestContext());
72+
apache::thrift::SerializedRequest serializedRequest{nullptr};
7273
try {
7374
auto pargs = args.pargs();
75+
serializedRequest = apache::thrift::detail::ServerRequestHelper::compressedRequest(
76+
std::move(serverRequest)).uncompress();
7477
deserializeRequest<ProtocolIn_>(
7578
pargs,
7679
"bar",
77-
apache::thrift::detail::ServerRequestHelper::compressedRequest(
78-
std::move(serverRequest))
79-
.uncompress(),
80+
serializedRequest,
8081
ctxStack.get());
8182
} catch (...) {
8283
folly::exception_wrapper ew(std::current_exception());
@@ -132,19 +133,25 @@ void GoodServiceAsyncProcessor::executeRequest_bar(
132133
#if FOLLY_HAS_COROUTINES
133134
if (apache::thrift::detail::shouldProcessServiceInterceptorsOnRequest(
134135
*callback)) {
135-
[](auto callback, auto executeHandler, ArgsState args)
136-
-> folly::coro::Task<void> {
136+
[](
137+
auto callback,
138+
auto executeHandler,
139+
ArgsState args,
140+
const apache::thrift::SerializedRequest&& serializedRequest
141+
) -> folly::coro::Task<void> {
137142
auto argRefs = args.asTupleOfRefs();
138143
co_await apache::thrift::detail::processServiceInterceptorsOnRequest(
139144
*callback,
140-
apache::thrift::detail::ServiceInterceptorOnRequestArguments(
141-
argRefs));
145+
apache::thrift::detail::ServiceInterceptorOnRequestArguments(argRefs),
146+
std::forward<const apache::thrift::SerializedRequest>(serializedRequest));
142147
executeHandler(std::move(callback), std::move(args));
143-
}(std::move(callback), makeExecuteHandler(), std::move(args))
144-
.scheduleOn(
145-
apache::thrift::detail::ServerRequestHelper::executor(
146-
serverRequest))
147-
.startInlineUnsafe();
148+
}(
149+
std::move(callback),
150+
makeExecuteHandler(),
151+
std::move(args),
152+
std::move(serializedRequest))
153+
.scheduleOn(apache::thrift::detail::ServerRequestHelper::executor(serverRequest))
154+
.startInlineUnsafe();
148155
} else {
149156
makeExecuteHandler()(std::move(callback), std::move(args));
150157
}
@@ -248,14 +255,15 @@ void GoodServiceAsyncProcessor::executeRequest_BadInteraction_foo(
248255
"BadService.BadInteraction.foo",
249256
serverRequest.requestContext());
250257
auto& iface = static_cast<apache::thrift::ServiceHandler<GoodService>::BadInteractionIf&>(*tile);
258+
apache::thrift::SerializedRequest serializedRequest{nullptr};
251259
try {
252260
auto pargs = args.pargs();
261+
serializedRequest = apache::thrift::detail::ServerRequestHelper::compressedRequest(
262+
std::move(serverRequest)).uncompress();
253263
deserializeRequest<ProtocolIn_>(
254264
pargs,
255265
"BadInteraction.foo",
256-
apache::thrift::detail::ServerRequestHelper::compressedRequest(
257-
std::move(serverRequest))
258-
.uncompress(),
266+
serializedRequest,
259267
ctxStack.get());
260268
} catch (...) {
261269
folly::exception_wrapper ew(std::current_exception());
@@ -314,19 +322,25 @@ void GoodServiceAsyncProcessor::executeRequest_BadInteraction_foo(
314322
#if FOLLY_HAS_COROUTINES
315323
if (apache::thrift::detail::shouldProcessServiceInterceptorsOnRequest(
316324
*callback)) {
317-
[](auto callback, auto executeHandler, ArgsState args)
318-
-> folly::coro::Task<void> {
325+
[](
326+
auto callback,
327+
auto executeHandler,
328+
ArgsState args,
329+
const apache::thrift::SerializedRequest&& serializedRequest
330+
) -> folly::coro::Task<void> {
319331
auto argRefs = args.asTupleOfRefs();
320332
co_await apache::thrift::detail::processServiceInterceptorsOnRequest(
321333
*callback,
322-
apache::thrift::detail::ServiceInterceptorOnRequestArguments(
323-
argRefs));
334+
apache::thrift::detail::ServiceInterceptorOnRequestArguments(argRefs),
335+
std::forward<const apache::thrift::SerializedRequest>(serializedRequest));
324336
executeHandler(std::move(callback), std::move(args));
325-
}(std::move(callback), makeExecuteHandler(), std::move(args))
326-
.scheduleOn(
327-
apache::thrift::detail::ServerRequestHelper::executor(
328-
serverRequest))
329-
.startInlineUnsafe();
337+
}(
338+
std::move(callback),
339+
makeExecuteHandler(),
340+
std::move(args),
341+
std::move(serializedRequest))
342+
.scheduleOn(apache::thrift::detail::ServerRequestHelper::executor(serverRequest))
343+
.startInlineUnsafe();
330344
} else {
331345
makeExecuteHandler()(std::move(callback), std::move(args));
332346
}

0 commit comments

Comments
 (0)