Skip to content

Commit a88c67f

Browse files
authored
Implement IRequestContextBase::GetPeer() for HTTP requests (#4418)
1 parent 4a3bdbe commit a88c67f

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

ydb/core/public_http/grpc_request_context_wrapper.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,9 @@ namespace NKikimr::NPublicHttp {
7777
google::protobuf::Arena* TGrpcRequestContextWrapper::GetArena() {
7878
return &Arena;
7979
}
80+
81+
TString TGrpcRequestContextWrapper::GetPeer() const {
82+
return RequestContext.GetPeer();
83+
}
84+
8085
} // namespace NKikimr::NPublicHttp

ydb/core/public_http/grpc_request_context_wrapper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class TGrpcRequestContextWrapper : public NYdbGrpc::IRequestContextBase {
4646
virtual void FinishStreamingOk() {}
4747
virtual TAsyncFinishResult GetFinishFuture() { return {}; }
4848
virtual bool IsClientLost() const { return false; }
49-
virtual TString GetPeer() const { return {}; }
49+
virtual TString GetPeer() const;
5050
virtual bool SslServer() const { return false; }
5151
virtual bool IsStreamCall() const { return false; }
5252
};

ydb/core/public_http/http_req.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ namespace NKikimr::NPublicHttp {
170170
return IdempotencyKey;
171171
}
172172

173+
TString THttpRequestContext::GetPeer() const {
174+
return !ForwardedFor.empty() ? TString(ForwardedFor) : TString(Request->Host);
175+
}
176+
173177
void THttpRequestContext::ResponseBadRequest(Ydb::StatusIds::StatusCode status, const TString& errorText) const {
174178
DoResponseBadRequest(status, errorText);
175179
}

ydb/core/public_http/http_req.h

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class THttpRequestContext {
3535
NHttp::THttpIncomingRequestPtr GetHttpRequest() const;
3636
TString GetContentType() const;
3737
TString GetIdempotencyKey() const;
38+
TString GetPeer() const;
3839

3940
private:
4041
void ParseHeaders(TStringBuf headers);

0 commit comments

Comments
 (0)