@@ -1026,32 +1026,36 @@ class THttpMonInitializator : public TActorBootstrapped<THttpMonInitializator> {
1026
1026
class THttpMonAuthorizedActorRequest : public TActorBootstrapped <THttpMonAuthorizedActorRequest> {
1027
1027
public:
1028
1028
NHttp::TEvHttpProxy::TEvHttpIncomingRequest::TPtr Event;
1029
- TActorId TargetActorId ;
1029
+ TMon::TRegisterHandlerFields& Fields ;
1030
1030
TMon::TRequestAuthorizer Authorizer;
1031
- TVector<TString> AllowedSIDs ;
1031
+ NHttp::TEvHttpProxy::TEvSubscribeForCancel::TPtr CancelSubscriber ;
1032
1032
1033
- THttpMonAuthorizedActorRequest (NHttp::TEvHttpProxy::TEvHttpIncomingRequest::TPtr event, TActorId targetActorId , TMon::TRequestAuthorizer authorizer, const TVector<TString>& allowedSIDs )
1033
+ THttpMonAuthorizedActorRequest (NHttp::TEvHttpProxy::TEvHttpIncomingRequest::TPtr event, TMon::TRegisterHandlerFields& fields , TMon::TRequestAuthorizer authorizer)
1034
1034
: Event(std::move(event))
1035
- , TargetActorId(targetActorId )
1035
+ , Fields(fields )
1036
1036
, Authorizer(std::move(authorizer))
1037
- , AllowedSIDs(allowedSIDs)
1038
1037
{}
1039
1038
1040
1039
static constexpr NKikimrServices::TActivity::EType ActorActivityType () {
1041
1040
return NKikimrServices::TActivity::HTTP_MON_AUTHORIZED_ACTOR_REQUEST;
1042
1041
}
1043
1042
1044
1043
void Bootstrap () {
1045
- if (Authorizer) {
1044
+ Send (Event->Sender , new NHttp::TEvHttpProxy::TEvSubscribeForCancel (), IEventHandle::FlagTrackDelivery);
1045
+ if (Fields.UseAuth && Authorizer) {
1046
1046
NActors::IEventHandle* handle = Authorizer (SelfId (), Event->Get ()->Request .Get ());
1047
1047
if (handle) {
1048
1048
Send (handle);
1049
1049
Become (&THttpMonAuthorizedActorRequest::StateWork);
1050
1050
return ;
1051
1051
}
1052
1052
}
1053
- Forward (Event, TargetActorId);
1054
- PassAway ();
1053
+ Send (new IEventHandle (Fields.Handler , SelfId (), Event->ReleaseBase ().Release (), IEventHandle::FlagTrackDelivery, Event->Cookie ));
1054
+ Become (&THttpMonAuthorizedActorRequest::StateWork);
1055
+ }
1056
+
1057
+ void ReplyWith (NHttp::THttpOutgoingResponsePtr response) {
1058
+ Send (Event->Sender , new NHttp::TEvHttpProxy::TEvHttpOutgoingResponse (response));
1055
1059
}
1056
1060
1057
1061
bool CredentialsProvided () {
@@ -1136,7 +1140,7 @@ class THttpMonAuthorizedActorRequest : public TActorBootstrapped<THttpMonAuthori
1136
1140
response << " Content-Length: " << body.size () << " \r\n " ;
1137
1141
response << " \r\n " ;
1138
1142
response << body;
1139
- Send (Event-> Sender , new NHttp::TEvHttpProxy::TEvHttpOutgoingResponse ( request->CreateResponseString (response) ));
1143
+ ReplyWith ( request->CreateResponseString (response));
1140
1144
PassAway ();
1141
1145
}
1142
1146
@@ -1158,14 +1162,25 @@ class THttpMonAuthorizedActorRequest : public TActorBootstrapped<THttpMonAuthori
1158
1162
if (result.UserToken ) {
1159
1163
Event->Get ()->UserToken = result.UserToken ->GetSerializedToken ();
1160
1164
}
1161
- Forward (Event, TargetActorId);
1165
+ Send (new IEventHandle (Fields.Handler , SelfId (), Event->ReleaseBase ().Release (), IEventHandle::FlagTrackDelivery, Event->Cookie ));
1166
+
1162
1167
PassAway ();
1163
1168
}
1164
1169
1165
- void HandleUndelivered (TEvents::TEvUndelivered::TPtr&) {
1170
+ void Cancelled () {
1171
+ if (CancelSubscriber) {
1172
+ Send (CancelSubscriber->Sender , new NHttp::TEvHttpProxy::TEvRequestCancelled (), 0 , CancelSubscriber->Cookie );
1173
+ }
1174
+ PassAway ();
1175
+ }
1176
+
1177
+ void HandleUndelivered (TEvents::TEvUndelivered::TPtr& ev) {
1178
+ if (ev->Get ()->SourceType == NHttp::TEvHttpProxy::EvSubscribeForCancel) {
1179
+ return Cancelled ();
1180
+ }
1166
1181
NHttp::THttpIncomingRequestPtr request = Event->Get ()->Request ;
1167
- Send (Event-> Sender , new NHttp::TEvHttpProxy::TEvHttpOutgoingResponse (
1168
- request-> CreateResponseServiceUnavailable ( TStringBuilder () << " Auth actor is not available" ) ));
1182
+ ReplyWith (request-> CreateResponseServiceUnavailable (
1183
+ TStringBuilder () << " Auth actor is not available" ));
1169
1184
PassAway ();
1170
1185
}
1171
1186
@@ -1174,17 +1189,43 @@ class THttpMonAuthorizedActorRequest : public TActorBootstrapped<THttpMonAuthori
1174
1189
if (result.Status != Ydb::StatusIds::SUCCESS) {
1175
1190
return ReplyErrorAndPassAway (result);
1176
1191
}
1177
- if (IsTokenAllowed (result.UserToken .Get (), AllowedSIDs)) {
1192
+ if (IsTokenAllowed (result.UserToken .Get (), Fields. AllowedSIDs )) {
1178
1193
SendRequest (result);
1179
1194
} else {
1180
1195
return ReplyForbiddenAndPassAway (" SID is not allowed" );
1181
1196
}
1182
1197
}
1183
1198
1199
+ void Handle (NHttp::TEvHttpProxy::TEvHttpOutgoingResponse::TPtr& ev) {
1200
+ ReplyWith (ev->Get ()->Response );
1201
+ if (ev->Get ()->Response ->IsDone ()) {
1202
+ return PassAway ();
1203
+ }
1204
+ }
1205
+
1206
+ void Handle (NHttp::TEvHttpProxy::TEvHttpOutgoingDataChunk::TPtr& ev) {
1207
+ Send (Event->Sender , new NHttp::TEvHttpProxy::TEvHttpOutgoingDataChunk (ev->Get ()->DataChunk ), 0 , Event->Cookie );
1208
+ if (ev->Get ()->DataChunk && ev->Get ()->DataChunk ->IsEndOfData ()) {
1209
+ PassAway ();
1210
+ }
1211
+ }
1212
+
1213
+ void Handle (NHttp::TEvHttpProxy::TEvSubscribeForCancel::TPtr& ev) {
1214
+ CancelSubscriber = std::move (ev);
1215
+ }
1216
+
1217
+ void Handle (NHttp::TEvHttpProxy::TEvRequestCancelled::TPtr& /* ev */ ) {
1218
+ Cancelled ();
1219
+ }
1220
+
1184
1221
STATEFN (StateWork) {
1185
1222
switch (ev->GetTypeRewrite ()) {
1186
1223
hFunc (TEvents::TEvUndelivered, HandleUndelivered);
1187
1224
hFunc (NKikimr::NGRpcService::TEvRequestAuthAndCheckResult, Handle);
1225
+ hFunc (NHttp::TEvHttpProxy::TEvHttpOutgoingResponse, Handle);
1226
+ hFunc (NHttp::TEvHttpProxy::TEvHttpOutgoingDataChunk, Handle);
1227
+ hFunc (NHttp::TEvHttpProxy::TEvSubscribeForCancel, Handle);
1228
+ hFunc (NHttp::TEvHttpProxy::TEvRequestCancelled, Handle)
1188
1229
}
1189
1230
}
1190
1231
};
@@ -1276,11 +1317,7 @@ class THttpMonIndexService : public TActor<THttpMonIndexService> {
1276
1317
while (!url.empty ()) {
1277
1318
auto it = Handlers.find (TString (url));
1278
1319
if (it != Handlers.end ()) {
1279
- if (it->second .UseAuth ) {
1280
- Register (new THttpMonAuthorizedActorRequest (std::move (ev), it->second .Handler , Authorizer, it->second .AllowedSIDs ));
1281
- } else {
1282
- Forward (ev, it->second .Handler );
1283
- }
1320
+ Register (new THttpMonAuthorizedActorRequest (std::move (ev), it->second , Authorizer));
1284
1321
return ;
1285
1322
} else {
1286
1323
if (url.EndsWith (' /' )) {
0 commit comments