Skip to content

Commit 385690d

Browse files
authored
improve code a little, get rid of templates and contexts (#12687)
1 parent dffc12a commit 385690d

File tree

9 files changed

+472
-463
lines changed

9 files changed

+472
-463
lines changed

ydb/core/mon/mon.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -696,12 +696,12 @@ class THttpMonServiceNodeRequest : public TActorBootstrapped<THttpMonServiceNode
696696
}
697697

698698
TString RewriteWithForwardedFromNode(const TString& response) {
699-
NHttp::THttpParser<NHttp::THttpRequest, NHttp::TSocketBuffer> parser(response);
699+
NHttp::THttpRequestParser parser(response);
700700

701701
NHttp::THeadersBuilder headers(parser.Headers);
702702
headers.Set("X-Forwarded-From-Node", TStringBuilder() << Event->Sender.NodeId());
703703

704-
NHttp::THttpRenderer<NHttp::THttpRequest, NHttp::TSocketBuffer> renderer;
704+
NHttp::THttpRequestRenderer renderer;
705705
renderer.InitRequest(parser.Method, parser.URL, parser.Protocol, parser.Version);
706706
renderer.Set(headers);
707707
if (parser.HaveBody()) {
@@ -730,12 +730,12 @@ class THttpMonServiceNodeRequest : public TActorBootstrapped<THttpMonServiceNode
730730
}
731731

732732
TString RewriteLocationWithNode(const TString& response) {
733-
NHttp::THttpParser<NHttp::THttpResponse, NHttp::TSocketBuffer> parser(response);
733+
NHttp::THttpResponseParser parser(response);
734734

735735
NHttp::THeadersBuilder headers(parser.Headers);
736736
headers.Set("Location", TStringBuilder() << "/node/" << TActivationContext::ActorSystem()->NodeId << headers["Location"]);
737737

738-
NHttp::THttpRenderer<NHttp::THttpResponse, NHttp::TSocketBuffer> renderer;
738+
NHttp::THttpResponseRenderer renderer;
739739
renderer.InitResponse(parser.Protocol, parser.Version, parser.Status, parser.Message);
740740
renderer.Set(headers);
741741
if (parser.HaveBody()) {
@@ -839,7 +839,7 @@ class THttpMonServiceMonRequest : public TActorBootstrapped<THttpMonServiceMonRe
839839
TString responseTxt = ev->Get()->Record.GetHttpResponse();
840840
NHttp::THttpOutgoingResponsePtr responseObj = Event->Get()->Request->CreateResponseString(responseTxt);
841841
if (responseObj->Status == "301" || responseObj->Status == "302") {
842-
NHttp::THttpParser<NHttp::THttpResponse, NHttp::TSocketBuffer> parser(responseTxt);
842+
NHttp::THttpResponseParser parser(responseTxt);
843843
NHttp::THeadersBuilder headers(parser.Headers);
844844
if (headers["Location"].starts_with('/')) {
845845
NHttp::THttpOutgoingResponsePtr response = new NHttp::THttpOutgoingResponse(Event->Get()->Request);

ydb/library/actors/http/http.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ TUrlParameters THttpRequest::GetParameters() const {
8181
}
8282

8383
template <>
84-
bool THttpParser<THttpRequest, TSocketBuffer>::HasBody() const {
84+
bool THttpParser<THttpRequest>::HasBody() const {
8585
if (!Body.empty()) {
8686
return true;
8787
}
8888
return !ContentLength.empty() || !TransferEncoding.empty();
8989
}
9090

9191
template <>
92-
void THttpParser<THttpRequest, TSocketBuffer>::Advance(size_t len) {
92+
void THttpParser<THttpRequest>::Advance(size_t len) {
9393
TStringBuf data(Pos(), len);
9494
while (!data.empty()) {
9595
if (Stage != EParseStage::Error) {
@@ -224,25 +224,25 @@ void THttpParser<THttpRequest, TSocketBuffer>::Advance(size_t len) {
224224
}
225225

226226
template <>
227-
THttpParser<THttpRequest, TSocketBuffer>::EParseStage THttpParser<THttpRequest, TSocketBuffer>::GetInitialStage() {
227+
THttpParser<THttpRequest>::EParseStage THttpParser<THttpRequest>::GetInitialStage() {
228228
return EParseStage::Method;
229229
}
230230

231231
template <>
232-
bool THttpParser<THttpResponse, TSocketBuffer>::ExpectedBody() const {
232+
bool THttpParser<THttpResponse>::ExpectedBody() const {
233233
return !Status.starts_with("1") && Status != "204" && Status != "304";
234234
}
235235

236236
template <>
237-
bool THttpParser<THttpResponse, TSocketBuffer>::HasBody() const {
237+
bool THttpParser<THttpResponse>::HasBody() const {
238238
if (!Body.empty()) {
239239
return true;
240240
}
241241
return ExpectedBody() && (!ContentType.empty() || !ContentLength.empty() || !TransferEncoding.empty());
242242
}
243243

244244
template <>
245-
THttpParser<THttpResponse, TSocketBuffer>::EParseStage THttpParser<THttpResponse, TSocketBuffer>::GetInitialStage() {
245+
THttpParser<THttpResponse>::EParseStage THttpParser<THttpResponse>::GetInitialStage() {
246246
return EParseStage::Protocol;
247247
}
248248

@@ -253,7 +253,7 @@ void THttpResponse::Clear() {
253253
}
254254

255255
template <>
256-
void THttpParser<THttpResponse, TSocketBuffer>::Advance(size_t len) {
256+
void THttpParser<THttpResponse>::Advance(size_t len) {
257257
TStringBuf data(Pos(), len);
258258
while (!data.empty()) {
259259
if (Stage != EParseStage::Error) {
@@ -398,7 +398,7 @@ void THttpParser<THttpResponse, TSocketBuffer>::Advance(size_t len) {
398398
}
399399

400400
template <>
401-
void THttpParser<THttpResponse, TSocketBuffer>::ConnectionClosed() {
401+
void THttpParser<THttpResponse>::ConnectionClosed() {
402402
if (Stage == EParseStage::Done) {
403403
return;
404404
}
@@ -412,7 +412,7 @@ void THttpParser<THttpResponse, TSocketBuffer>::ConnectionClosed() {
412412
}
413413

414414
THttpOutgoingResponsePtr THttpIncomingRequest::CreateResponseString(TStringBuf data) {
415-
THttpParser<THttpResponse, TSocketBuffer> parser(data);
415+
THttpParser<THttpResponse> parser(data);
416416
THeadersBuilder headers(parser.Headers);
417417
if (!Endpoint->WorkerName.empty()) {
418418
headers.Set("X-Worker-Name", Endpoint->WorkerName);
@@ -654,7 +654,7 @@ void THttpOutgoingResponse::AddDataChunk(THttpOutgoingDataChunkPtr dataChunk) {
654654
}
655655

656656
THttpOutgoingDataChunk::THttpOutgoingDataChunk(THttpOutgoingResponsePtr response, TStringBuf data)
657-
: THttpDataChunk<TSocketBuffer>(data)
657+
: THttpDataChunk(data)
658658
, Response(std::move(response))
659659
{}
660660

0 commit comments

Comments
 (0)