diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/http/server/http_ex.cpp | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/http/server/http_ex.cpp')
-rw-r--r-- | library/cpp/http/server/http_ex.cpp | 120 |
1 files changed, 60 insertions, 60 deletions
diff --git a/library/cpp/http/server/http_ex.cpp b/library/cpp/http/server/http_ex.cpp index 2fa2ccfead..e07db22bfc 100644 --- a/library/cpp/http/server/http_ex.cpp +++ b/library/cpp/http/server/http_ex.cpp @@ -1,32 +1,32 @@ -#include "http_ex.h" - -#include <util/generic/buffer.h> -#include <util/generic/cast.h> +#include "http_ex.h" + +#include <util/generic/buffer.h> +#include <util/generic/cast.h> #include <util/stream/null.h> - + bool THttpClientRequestExtension::Parse(char* req, TBaseServerRequestData& rd) { rd.SetSocket(Socket()); - + if (!rd.Parse(req)) { - Output() << "HTTP/1.1 403 Forbidden\r\n" - "Content-Type: text/plain\r\n" - "Content-Length: 39\r\n" - "\r\n" - "The server cannot be used as a proxy.\r\n"; - - return false; - } - - return true; -} - + Output() << "HTTP/1.1 403 Forbidden\r\n" + "Content-Type: text/plain\r\n" + "Content-Length: 39\r\n" + "\r\n" + "The server cannot be used as a proxy.\r\n"; + + return false; + } + + return true; +} + bool THttpClientRequestExtension::ProcessHeaders(TBaseServerRequestData& rd, TBlob& postData) { - for (const auto& header : ParsedHeaders) { + for (const auto& header : ParsedHeaders) { rd.AddHeader(header.first, header.second); - } - + } + char* s = RequestString.begin(); - + enum EMethod { NotImplemented, Get, @@ -39,7 +39,7 @@ bool THttpClientRequestExtension::ProcessHeaders(TBaseServerRequestData& rd, TBl enum EMethod foundMethod; char* urlStart; - if (strnicmp(s, "GET ", 4) == 0) { + if (strnicmp(s, "GET ", 4) == 0) { foundMethod = Get; urlStart = s + 4; } else if (strnicmp(s, "POST ", 5) == 0) { @@ -59,49 +59,49 @@ bool THttpClientRequestExtension::ProcessHeaders(TBaseServerRequestData& rd, TBl } switch (foundMethod) { - case Get: - case Delete: - if (!Parse(urlStart, rd)) { - return false; - } - break; - - case Post: - case Put: + case Get: + case Delete: + if (!Parse(urlStart, rd)) { + return false; + } + break; + + case Post: + case Put: case Patch: - try { - ui64 contentLength = 0; - if (Input().HasExpect100Continue()) { - Output().SendContinue(); - } - - if (!Input().ContentEncoded() && Input().GetContentLength(contentLength)) { + try { + ui64 contentLength = 0; + if (Input().HasExpect100Continue()) { + Output().SendContinue(); + } + + if (!Input().ContentEncoded() && Input().GetContentLength(contentLength)) { if (contentLength > HttpServ()->Options().MaxInputContentLength) { Output() << "HTTP/1.1 413 Payload Too Large\r\nContent-Length:0\r\n\r\n"; Output().Finish(); return false; } - TBuffer buf(SafeIntegerCast<size_t>(contentLength)); - buf.Resize(Input().Load(buf.Data(), (size_t)contentLength)); - postData = TBlob::FromBuffer(buf); - } else { - postData = TBlob::FromStream(Input()); - } - } catch (...) { - Output() << "HTTP/1.1 400 Bad request\r\n\r\n"; - return false; + TBuffer buf(SafeIntegerCast<size_t>(contentLength)); + buf.Resize(Input().Load(buf.Data(), (size_t)contentLength)); + postData = TBlob::FromBuffer(buf); + } else { + postData = TBlob::FromStream(Input()); + } + } catch (...) { + Output() << "HTTP/1.1 400 Bad request\r\n\r\n"; + return false; } - if (!Parse(urlStart, rd)) { - return false; - } - break; - - case NotImplemented: - Output() << "HTTP/1.1 501 Not Implemented\r\n\r\n"; - return false; - } - - return true; -} + if (!Parse(urlStart, rd)) { + return false; + } + break; + + case NotImplemented: + Output() << "HTTP/1.1 501 Not Implemented\r\n\r\n"; + return false; + } + + return true; +} |