@@ -198,7 +198,56 @@ class THttpResponse {
198198};
199199
200200template <typename HeaderType, typename BufferType>
201- class THttpParser : public HeaderType , public BufferType {
201+ class THttpBase : public HeaderType , public BufferType {
202+ public:
203+ TStringBuf GetRawData () const {
204+ return TStringBuf (BufferType::Data (), BufferType::Size ());
205+ }
206+
207+ TString GetObfuscatedData () const {
208+ THeaders headers (HeaderType::Headers);
209+ TStringBuf authorization (headers[" Authorization" ]);
210+ TStringBuf cookie (headers[" Cookie" ]);
211+ TStringBuf set_cookie (headers[" Set-Cookie" ]);
212+ TStringBuf x_ydb_auth_ticket (headers[" x-ydb-auth-ticket" ]);
213+ TStringBuf x_yacloud_subjecttoken (headers[" x-yacloud-subjecttoken" ]);
214+ TString data (GetRawData ());
215+ if (!authorization.empty ()) {
216+ auto pos = data.find (authorization);
217+ if (pos != TString::npos) {
218+ data.replace (pos, authorization.size (), TString (" <obfuscated>" ));
219+ }
220+ }
221+ if (!cookie.empty ()) {
222+ auto pos = data.find (cookie);
223+ if (pos != TString::npos) {
224+ data.replace (pos, cookie.size (), TString (" <obfuscated>" ));
225+ }
226+ }
227+ if (!set_cookie.empty ()) {
228+ auto pos = data.find (set_cookie);
229+ if (pos != TString::npos) {
230+ data.replace (pos, set_cookie.size (), TString (" <obfuscated>" ));
231+ }
232+ }
233+ if (!x_ydb_auth_ticket.empty ()) {
234+ auto pos = data.find (x_ydb_auth_ticket);
235+ if (pos != TString::npos) {
236+ data.replace (pos, x_ydb_auth_ticket.size (), TString (" <obfuscated>" ));
237+ }
238+ }
239+ if (!x_yacloud_subjecttoken.empty ()) {
240+ auto pos = data.find (x_yacloud_subjecttoken);
241+ if (pos != TString::npos) {
242+ data.replace (pos, x_yacloud_subjecttoken.size (), TString (" <obfuscated>" ));
243+ }
244+ }
245+ return data;
246+ }
247+ };
248+
249+ template <typename HeaderType, typename BufferType>
250+ class THttpParser : public THttpBase <HeaderType, BufferType> {
202251public:
203252 enum class EParseStage : ui8 {
204253 Method,
@@ -236,8 +285,7 @@ class THttpParser : public HeaderType, public BufferType {
236285 std::optional<size_t > TotalSize;
237286
238287 THttpParser (const THttpParser& src)
239- : HeaderType(src)
240- , BufferType(src)
288+ : THttpBase<HeaderType, BufferType>(src)
241289 , Stage(src.Stage)
242290 , LastSuccessStage(src.LastSuccessStage)
243291 , Line()
@@ -403,44 +451,6 @@ class THttpParser : public HeaderType, public BufferType {
403451 Advance (size);
404452 }
405453
406- TStringBuf GetRawData () const {
407- return TStringBuf (BufferType::Data (), BufferType::Size ());
408- }
409-
410- TString GetObfuscatedData () const {
411- THeaders headers (HeaderType::Headers);
412- TStringBuf authorization (headers[" Authorization" ]);
413- TStringBuf cookie (headers[" Cookie" ]);
414- TStringBuf x_ydb_auth_ticket (headers[" x-ydb-auth-ticket" ]);
415- TStringBuf x_yacloud_subjecttoken (headers[" x-yacloud-subjecttoken" ]);
416- TString data (GetRawData ());
417- if (!authorization.empty ()) {
418- auto pos = data.find (authorization);
419- if (pos != TString::npos) {
420- data.replace (pos, authorization.size (), TString (" <obfuscated>" ));
421- }
422- }
423- if (!cookie.empty ()) {
424- auto pos = data.find (cookie);
425- if (pos != TString::npos) {
426- data.replace (pos, cookie.size (), TString (" <obfuscated>" ));
427- }
428- }
429- if (!x_ydb_auth_ticket.empty ()) {
430- auto pos = data.find (x_ydb_auth_ticket);
431- if (pos != TString::npos) {
432- data.replace (pos, x_ydb_auth_ticket.size (), TString (" <obfuscated>" ));
433- }
434- }
435- if (!x_yacloud_subjecttoken.empty ()) {
436- auto pos = data.find (x_yacloud_subjecttoken);
437- if (pos != TString::npos) {
438- data.replace (pos, x_yacloud_subjecttoken.size (), TString (" <obfuscated>" ));
439- }
440- }
441- return data;
442- }
443-
444454 static EParseStage GetInitialStage ();
445455
446456 THttpParser ()
@@ -460,7 +470,7 @@ class THttpParser : public HeaderType, public BufferType {
460470};
461471
462472template <typename HeaderType, typename BufferType>
463- class THttpRenderer : public HeaderType , public BufferType {
473+ class THttpRenderer : public THttpBase < HeaderType, BufferType> {
464474public:
465475 enum class ERenderStage {
466476 Init,
@@ -654,10 +664,6 @@ class THttpRenderer : public HeaderType, public BufferType {
654664 }
655665 Y_ABORT_UNLESS (size == BufferType::Size ());
656666 }
657-
658- TStringBuf GetRawData () const {
659- return TStringBuf (BufferType::Data (), BufferType::Size ());
660- }
661667};
662668
663669template <>
0 commit comments