Browse Source

Restoring authorship annotation for <ishfb@yandex-team.ru>. Commit 2 of 2.

ishfb 3 years ago
parent
commit
069c69f58f

+ 6 - 6
contrib/libs/pire/pire/encoding.cpp

@@ -118,17 +118,17 @@ namespace {
 namespace Encodings {
 
 	const Encoding& Utf8()
-	{ 
-		static const Pire::Utf8 utf8; 
+	{
+		static const Pire::Utf8 utf8;
 		return utf8;
-	} 
+	}
 
 	const Encoding& Latin1()
-	{ 
+	{
 		static const Pire::Latin1 latin1;
 		return latin1;
-	} 
- 
+	}
+
 }
 
 }

+ 16 - 16
contrib/libs/pire/pire/platform.h

@@ -42,22 +42,22 @@
 #define PIRE_HOT_FUNCTION
 #endif
 
-#ifndef PIRE_LIKELY 
-#ifdef __GNUC__ 
-#define PIRE_LIKELY(x) (__builtin_expect((x), 1)) 
-#else 
-#define PIRE_LIKELY(x) (x) 
-#endif 
-#endif 
- 
-#ifndef PIRE_UNLIKELY 
-#ifdef __GNUC__ 
-#define PIRE_UNLIKELY(x) (__builtin_expect((x), 0)) 
-#else 
-#define PIRE_UNLIKELY(x) (x) 
-#endif 
-#endif 
- 
+#ifndef PIRE_LIKELY
+#ifdef __GNUC__
+#define PIRE_LIKELY(x) (__builtin_expect((x), 1))
+#else
+#define PIRE_LIKELY(x) (x)
+#endif
+#endif
+
+#ifndef PIRE_UNLIKELY
+#ifdef __GNUC__
+#define PIRE_UNLIKELY(x) (__builtin_expect((x), 0))
+#else
+#define PIRE_UNLIKELY(x) (x)
+#endif
+#endif
+
 #ifdef _MSC_VER
 #include <stdio.h>
 #include <stdarg.h>

+ 1 - 1
contrib/libs/pire/pire/run.h

@@ -139,7 +139,7 @@ namespace Impl {
 
 		if (PIRE_UNLIKELY(size == 0))
 			return Continue;
- 
+
 		size_t chunk = Impl::ToLittleEndian(*p) >> 8*pos;
 		const char* ptr = (const char*) p + pos + size + 1;
 

+ 9 - 9
library/cpp/cgiparam/cgiparam.h

@@ -46,11 +46,11 @@ public:
     void ScanAddAllUnescaped(const TStringBuf cgiParStr);
     void ScanAddAll(const TStringBuf cgiParStr);
 
-    /// Returns the string representation of all the stored parameters 
-    /** 
-     * @note The returned string has format <name1>=<value1>&<name2>=<value2>&... 
-     * @note Names and values in the returned string are CGI-escaped. 
-     */ 
+    /// Returns the string representation of all the stored parameters
+    /**
+     * @note The returned string has format <name1>=<value1>&<name2>=<value2>&...
+     * @note Names and values in the returned string are CGI-escaped.
+     */
     TString Print() const;
     char* Print(char* res) const;
 
@@ -78,10 +78,10 @@ public:
         const auto pair = equal_range(name);
         return pair.first != pair.second;
     }
-    /// Returns value by name 
-    /** 
-     * @note The returned value is CGI-unescaped. 
-     */ 
+    /// Returns value by name
+    /**
+     * @note The returned value is CGI-unescaped.
+     */
     Y_PURE_FUNCTION
     const TString& Get(const TStringBuf name, size_t numOfValue = 0) const noexcept;
 

+ 14 - 14
library/cpp/http/server/http.cpp

@@ -771,7 +771,7 @@ THttpServer* TClientRequest::HttpServ() const noexcept {
 const TSocket& TClientRequest::Socket() const noexcept {
     return Conn_->Socket_;
 }
- 
+
 NAddr::IRemoteAddrRef TClientRequest::GetListenerSockAddrRef() const noexcept {
     return Conn_->ListenerSockAddrRef_;
 }
@@ -780,21 +780,21 @@ TInstant TClientRequest::AcceptMoment() const noexcept {
     return Conn_->AcceptMoment;
 }
 
-/* 
- * TRequestReplier 
- */ 
-TRequestReplier::TRequestReplier() { 
-} 
- 
-TRequestReplier::~TRequestReplier() { 
-} 
- 
-bool TRequestReplier::Reply(void* threadSpecificResource) { 
-    const TReplyParams params = { 
+/*
+ * TRequestReplier
+ */
+TRequestReplier::TRequestReplier() {
+}
+
+TRequestReplier::~TRequestReplier() {
+}
+
+bool TRequestReplier::Reply(void* threadSpecificResource) {
+    const TReplyParams params = {
         threadSpecificResource, Input(), Output()};
 
-    return DoReply(params); 
-} 
+    return DoReply(params);
+}
 
 bool TryToBindAddresses(const THttpServerOptions& options, const std::function<void(TSocket)>* callbackOnBoundAddress) {
     THttpServerOptions::TBindAddresses addrs;

+ 24 - 24
library/cpp/http/server/http.h

@@ -99,9 +99,9 @@ private:
     THolder<TImpl> Impl_;
 };
 
-/** 
- * @deprecated Use TRequestReplier instead 
- */ 
+/**
+ * @deprecated Use TRequestReplier instead
+ */
 class TClientRequest: public IObjectInQueue {
     friend class THttpServer::TImpl;
 
@@ -149,28 +149,28 @@ private:
 };
 
 class TRequestReplier: public TClientRequest {
-public: 
-    TRequestReplier(); 
+public:
+    TRequestReplier();
     ~TRequestReplier() override;
- 
-    struct TReplyParams { 
-        void* ThreadSpecificResource; 
-        THttpInput& Input; 
-        THttpOutput& Output; 
-    }; 
- 
-    /* 
-     * Processes the request after 'connection' been created and 'Headers' been read 
-     * Returns 'false' if the processing must be continued by the next handler, 
-     * 'true' otherwise ('this' will be deleted) 
-     */ 
-    virtual bool DoReply(const TReplyParams& params) = 0; 
- 
-private: 
+
+    struct TReplyParams {
+        void* ThreadSpecificResource;
+        THttpInput& Input;
+        THttpOutput& Output;
+    };
+
+    /*
+     * Processes the request after 'connection' been created and 'Headers' been read
+     * Returns 'false' if the processing must be continued by the next handler,
+     * 'true' otherwise ('this' will be deleted)
+     */
+    virtual bool DoReply(const TReplyParams& params) = 0;
+
+private:
     bool Reply(void* threadSpecificResource) final;
- 
-    using TClientRequest::Input; 
-    using TClientRequest::Output; 
-}; 
+
+    using TClientRequest::Input;
+    using TClientRequest::Output;
+};
 
 bool TryToBindAddresses(const THttpServerOptions& options, const std::function<void(TSocket)>* callbackOnBoundAddress = nullptr);

+ 28 - 28
library/cpp/http/server/response.cpp

@@ -1,65 +1,65 @@
-#include "response.h" 
+#include "response.h"
 
-#include <util/stream/output.h> 
+#include <util/stream/output.h>
 #include <util/stream/mem.h>
 #include <util/string/cast.h>
- 
-THttpResponse& THttpResponse::AddMultipleHeaders(const THttpHeaders& headers) { 
-    for (THttpHeaders::TConstIterator i = headers.Begin(); i != headers.End(); ++i) { 
-        this->Headers.AddHeader(*i); 
-    } 
-    return *this; 
-} 
- 
+
+THttpResponse& THttpResponse::AddMultipleHeaders(const THttpHeaders& headers) {
+    for (THttpHeaders::TConstIterator i = headers.Begin(); i != headers.End(); ++i) {
+        this->Headers.AddHeader(*i);
+    }
+    return *this;
+}
+
 THttpResponse& THttpResponse::SetContentType(const TStringBuf& contentType) {
     Headers.AddOrReplaceHeader(THttpInputHeader("Content-Type", ToString(contentType)));
 
     return *this;
-} 
- 
+}
+
 void THttpResponse::OutTo(IOutputStream& os) const {
     TVector<IOutputStream::TPart> parts;
-    const size_t FIRST_LINE_PARTS = 3; 
+    const size_t FIRST_LINE_PARTS = 3;
     const size_t HEADERS_PARTS = Headers.Count() * 4;
-    const size_t CONTENT_PARTS = 5; 
-    parts.reserve(FIRST_LINE_PARTS + HEADERS_PARTS + CONTENT_PARTS); 
- 
-    // first line 
+    const size_t CONTENT_PARTS = 5;
+    parts.reserve(FIRST_LINE_PARTS + HEADERS_PARTS + CONTENT_PARTS);
+
+    // first line
     parts.push_back(IOutputStream::TPart(TStringBuf("HTTP/1.1 ")));
     parts.push_back(IOutputStream::TPart(HttpCodeStrEx(Code)));
     parts.push_back(IOutputStream::TPart::CrLf());
- 
-    // headers 
+
+    // headers
     for (THttpHeaders::TConstIterator i = Headers.Begin(); i != Headers.End(); ++i) {
         parts.push_back(IOutputStream::TPart(i->Name()));
         parts.push_back(IOutputStream::TPart(TStringBuf(": ")));
         parts.push_back(IOutputStream::TPart(i->Value()));
         parts.push_back(IOutputStream::TPart::CrLf());
-    } 
- 
+    }
+
     char buf[50];
 
     if (!Content.empty()) {
         TMemoryOutput mo(buf, sizeof(buf));
- 
+
         mo << Content.size();
 
         parts.push_back(IOutputStream::TPart(TStringBuf("Content-Length: ")));
         parts.push_back(IOutputStream::TPart(buf, mo.Buf() - buf));
         parts.push_back(IOutputStream::TPart::CrLf());
-    } 
- 
-    // content 
+    }
+
+    // content
     parts.push_back(IOutputStream::TPart::CrLf());
 
     if (!Content.empty()) {
         parts.push_back(IOutputStream::TPart(Content));
-    } 
- 
+    }
+
     os.Write(parts.data(), parts.size());
 }
 
 template <>
 void Out<THttpResponse>(IOutputStream& os, const THttpResponse& resp) {
     resp.OutTo(os);
-} 
+}

+ 38 - 38
library/cpp/http/server/response.h

@@ -1,69 +1,69 @@
-#pragma once 
+#pragma once
 
 #include <library/cpp/http/misc/httpcodes.h>
 #include <library/cpp/http/io/stream.h>
 
-#include <util/generic/strbuf.h> 
-#include <util/string/cast.h> 
- 
-class THttpHeaders; 
+#include <util/generic/strbuf.h>
+#include <util/string/cast.h>
+
+class THttpHeaders;
 class IOutputStream;
- 
-class THttpResponse { 
-public: 
+
+class THttpResponse {
+public:
     THttpResponse() noexcept
         : Code(HTTP_OK)
     {
     }
 
     explicit THttpResponse(HttpCodes code) noexcept
-        : Code(code) 
-    { 
-    } 
- 
+        : Code(code)
+    {
+    }
+
     template <typename ValueType>
     THttpResponse& AddHeader(const TString& name, const ValueType& value) {
-        return AddHeader(THttpInputHeader(name, ToString(value))); 
-    } 
- 
-    THttpResponse& AddHeader(const THttpInputHeader& header) { 
-        Headers.AddHeader(header); 
-
-        return *this; 
-    } 
- 
-    THttpResponse& AddMultipleHeaders(const THttpHeaders& headers); 
- 
+        return AddHeader(THttpInputHeader(name, ToString(value)));
+    }
+
+    THttpResponse& AddHeader(const THttpInputHeader& header) {
+        Headers.AddHeader(header);
+
+        return *this;
+    }
+
+    THttpResponse& AddMultipleHeaders(const THttpHeaders& headers);
+
     const THttpHeaders& GetHeaders() const {
         return Headers;
     }
 
     THttpResponse& SetContentType(const TStringBuf& contentType);
 
-    /** 
-     * @note If @arg content isn't empty its size is automatically added as a 
+    /**
+     * @note If @arg content isn't empty its size is automatically added as a
      * "Content-Length" header during output to IOutputStream.
      * @see IOutputStream& operator << (IOutputStream&, const THttpResponse&)
-     */ 
+     */
     THttpResponse& SetContent(const TString& content) {
-        Content = content; 
+        Content = content;
+
+        return *this;
+    }
 
-        return *this; 
-    } 
- 
     TString GetContent() const {
         return Content;
     }
 
-    /** 
-     * @note If @arg content isn't empty its size is automatically added as a 
+    /**
+     * @note If @arg content isn't empty its size is automatically added as a
      * "Content-Length" header during output to IOutputStream.
      * @see IOutputStream& operator << (IOutputStream&, const THttpResponse&)
-     */ 
+     */
     THttpResponse& SetContent(const TString& content, const TStringBuf& contentType) {
         return SetContent(content).SetContentType(contentType);
     }
- 
+
     HttpCodes HttpCode() const {
         return Code;
     }
@@ -75,8 +75,8 @@ public:
 
     void OutTo(IOutputStream& out) const;
 
-private: 
-    HttpCodes Code; 
-    THttpHeaders Headers; 
+private:
+    HttpCodes Code;
+    THttpHeaders Headers;
     TString Content;
-}; 
+};

+ 85 - 85
library/cpp/http/server/response_ut.cpp

@@ -1,51 +1,51 @@
-#include "response.h" 
- 
+#include "response.h"
+
 #include <library/cpp/testing/unittest/registar.h>
- 
+
 #include <util/string/cast.h>
 
 Y_UNIT_TEST_SUITE(TestHttpResponse) {
     Y_UNIT_TEST(TestCodeOnly) {
         UNIT_ASSERT_STRINGS_EQUAL(ToString(THttpResponse()), "HTTP/1.1 200 Ok\r\n\r\n");
-        UNIT_ASSERT_STRINGS_EQUAL(ToString(THttpResponse(HTTP_NOT_FOUND)), "HTTP/1.1 404 Not found\r\n\r\n"); 
-    } 
- 
+        UNIT_ASSERT_STRINGS_EQUAL(ToString(THttpResponse(HTTP_NOT_FOUND)), "HTTP/1.1 404 Not found\r\n\r\n");
+    }
+
     Y_UNIT_TEST(TestRedirect) {
-        THttpResponse resp = THttpResponse(HTTP_FOUND).AddHeader("Location", "yandex.ru"); 
-        UNIT_ASSERT_STRINGS_EQUAL(ToString(resp), "HTTP/1.1 302 Moved temporarily\r\n" 
-                                                  "Location: yandex.ru\r\n" 
-                                                  "\r\n"); 
-    } 
- 
+        THttpResponse resp = THttpResponse(HTTP_FOUND).AddHeader("Location", "yandex.ru");
+        UNIT_ASSERT_STRINGS_EQUAL(ToString(resp), "HTTP/1.1 302 Moved temporarily\r\n"
+                                                  "Location: yandex.ru\r\n"
+                                                  "\r\n");
+    }
+
     Y_UNIT_TEST(TestAddHeader) {
-        THttpResponse resp(HTTP_FORBIDDEN); 
-        resp.AddHeader(THttpInputHeader("X-Header-1", "ValueOne")); 
-        resp.AddHeader("X-Header-2", 10); 
-        resp.AddHeader("X-Header-3", true); 
- 
-        const char* EXPECTED = "HTTP/1.1 403 Forbidden\r\n" 
-                               "X-Header-1: ValueOne\r\n" 
-                               "X-Header-2: 10\r\n" 
-                               "X-Header-3: 1\r\n" 
-                               "\r\n"; 
-        UNIT_ASSERT_STRINGS_EQUAL(ToString(resp), EXPECTED); 
-    } 
- 
+        THttpResponse resp(HTTP_FORBIDDEN);
+        resp.AddHeader(THttpInputHeader("X-Header-1", "ValueOne"));
+        resp.AddHeader("X-Header-2", 10);
+        resp.AddHeader("X-Header-3", true);
+
+        const char* EXPECTED = "HTTP/1.1 403 Forbidden\r\n"
+                               "X-Header-1: ValueOne\r\n"
+                               "X-Header-2: 10\r\n"
+                               "X-Header-3: 1\r\n"
+                               "\r\n";
+        UNIT_ASSERT_STRINGS_EQUAL(ToString(resp), EXPECTED);
+    }
+
     Y_UNIT_TEST(TestAddMultipleHeaders) {
-        THttpHeaders headers; 
-        headers.AddHeader(THttpInputHeader("X-Header-1", "ValueOne")); 
-        headers.AddHeader(THttpInputHeader("X-Header-2", "ValueTwo")); 
-        headers.AddHeader(THttpInputHeader("X-Header-3", "ValueThree")); 
- 
-        const char* EXPECTED = "HTTP/1.1 403 Forbidden\r\n" 
-                               "X-Header-1: ValueOne\r\n" 
-                               "X-Header-2: ValueTwo\r\n" 
-                               "X-Header-3: ValueThree\r\n" 
-                               "\r\n"; 
-        UNIT_ASSERT_STRINGS_EQUAL(ToString(THttpResponse(HTTP_FORBIDDEN).AddMultipleHeaders(headers)), 
-                                  EXPECTED); 
-    } 
- 
+        THttpHeaders headers;
+        headers.AddHeader(THttpInputHeader("X-Header-1", "ValueOne"));
+        headers.AddHeader(THttpInputHeader("X-Header-2", "ValueTwo"));
+        headers.AddHeader(THttpInputHeader("X-Header-3", "ValueThree"));
+
+        const char* EXPECTED = "HTTP/1.1 403 Forbidden\r\n"
+                               "X-Header-1: ValueOne\r\n"
+                               "X-Header-2: ValueTwo\r\n"
+                               "X-Header-3: ValueThree\r\n"
+                               "\r\n";
+        UNIT_ASSERT_STRINGS_EQUAL(ToString(THttpResponse(HTTP_FORBIDDEN).AddMultipleHeaders(headers)),
+                                  EXPECTED);
+    }
+
     Y_UNIT_TEST(TestGetHeaders) {
         THttpResponse resp(HTTP_FORBIDDEN);
 
@@ -66,66 +66,66 @@ Y_UNIT_TEST_SUITE(TestHttpResponse) {
 
 
     Y_UNIT_TEST(TestSetContent) {
-        const char* EXPECTED = "HTTP/1.1 200 Ok\r\n" 
-                               "Content-Length: 10\r\n" 
-                               "\r\n" 
-                               "0123456789"; 
+        const char* EXPECTED = "HTTP/1.1 200 Ok\r\n"
+                               "Content-Length: 10\r\n"
+                               "\r\n"
+                               "0123456789";
         UNIT_ASSERT_STRINGS_EQUAL(ToString(THttpResponse().SetContent("0123456789")),
-                                  EXPECTED); 
-    } 
- 
+                                  EXPECTED);
+    }
+
     Y_UNIT_TEST(TestSetContentWithContentType) {
-        const char* EXPECTED = "HTTP/1.1 200 Ok\r\n" 
-                               "Content-Type: text/xml\r\n" 
-                               "Content-Length: 28\r\n" 
-                               "\r\n" 
-                               "<xml><tag value=\"1\" /></xml>"; 
+        const char* EXPECTED = "HTTP/1.1 200 Ok\r\n"
+                               "Content-Type: text/xml\r\n"
+                               "Content-Length: 28\r\n"
+                               "\r\n"
+                               "<xml><tag value=\"1\" /></xml>";
         THttpResponse resp;
         resp.SetContent("<xml><tag value=\"1\" /></xml>").SetContentType("text/xml");
-        UNIT_ASSERT_STRINGS_EQUAL(ToString(resp), EXPECTED); 
-    } 
- 
+        UNIT_ASSERT_STRINGS_EQUAL(ToString(resp), EXPECTED);
+    }
+
     Y_UNIT_TEST(TestCopyConstructor) {
-        THttpResponse resp(HTTP_FORBIDDEN); 
-        resp.AddHeader(THttpInputHeader("X-Header-1", "ValueOne")) 
-            .AddHeader("X-Header-2", "ValueTwo") 
-            .AddHeader(THttpInputHeader("X-Header-3", "ValueThree")) 
+        THttpResponse resp(HTTP_FORBIDDEN);
+        resp.AddHeader(THttpInputHeader("X-Header-1", "ValueOne"))
+            .AddHeader("X-Header-2", "ValueTwo")
+            .AddHeader(THttpInputHeader("X-Header-3", "ValueThree"))
             .SetContent("Some stuff")
             .SetContentType("text/plain");
- 
-        THttpResponse copy = resp; 
-        UNIT_ASSERT_STRINGS_EQUAL(ToString(copy), ToString(resp)); 
-    } 
- 
+
+        THttpResponse copy = resp;
+        UNIT_ASSERT_STRINGS_EQUAL(ToString(copy), ToString(resp));
+    }
+
     Y_UNIT_TEST(TestAssignment) {
-        THttpResponse resp(HTTP_FORBIDDEN); 
-        resp.AddHeader(THttpInputHeader("X-Header-1", "ValueOne")); 
-        resp.AddHeader(THttpInputHeader("X-Header-2", "ValueTwo")); 
-        resp.AddHeader(THttpInputHeader("X-Header-3", "ValueThree")); 
+        THttpResponse resp(HTTP_FORBIDDEN);
+        resp.AddHeader(THttpInputHeader("X-Header-1", "ValueOne"));
+        resp.AddHeader(THttpInputHeader("X-Header-2", "ValueTwo"));
+        resp.AddHeader(THttpInputHeader("X-Header-3", "ValueThree"));
         resp.SetContent("Some stuff").SetContentType("text/plain");
- 
+
         THttpResponse copy;
-        copy = resp; 
-        UNIT_ASSERT_STRINGS_EQUAL(ToString(copy), ToString(resp)); 
-    } 
- 
+        copy = resp;
+        UNIT_ASSERT_STRINGS_EQUAL(ToString(copy), ToString(resp));
+    }
+
     Y_UNIT_TEST(TestEmptyContent) {
         UNIT_ASSERT_STRINGS_EQUAL(ToString(THttpResponse().SetContent("")), "HTTP/1.1 200 Ok\r\n\r\n");
-    } 
- 
+    }
+
     Y_UNIT_TEST(TestReturnReference) {
         THttpResponse resp;
-        UNIT_ASSERT_EQUAL(&resp, &resp.AddHeader("Header1", 1)); 
-        UNIT_ASSERT_EQUAL(&resp, &resp.AddHeader(THttpInputHeader("Header2", "2"))); 
- 
-        THttpHeaders headers; 
-        headers.AddHeader(THttpInputHeader("Header3", "3")); 
-        headers.AddHeader(THttpInputHeader("Header4", "4")); 
-        UNIT_ASSERT_EQUAL(&resp, &resp.AddMultipleHeaders(headers)); 
- 
-        UNIT_ASSERT_EQUAL(&resp, &resp.SetContent("some stuff")); 
+        UNIT_ASSERT_EQUAL(&resp, &resp.AddHeader("Header1", 1));
+        UNIT_ASSERT_EQUAL(&resp, &resp.AddHeader(THttpInputHeader("Header2", "2")));
+
+        THttpHeaders headers;
+        headers.AddHeader(THttpInputHeader("Header3", "3"));
+        headers.AddHeader(THttpInputHeader("Header4", "4"));
+        UNIT_ASSERT_EQUAL(&resp, &resp.AddMultipleHeaders(headers));
+
+        UNIT_ASSERT_EQUAL(&resp, &resp.SetContent("some stuff"));
         UNIT_ASSERT_EQUAL(&resp, &resp.SetContent("some other stuff").SetContentType("text/plain"));
-    } 
+    }
 
     Y_UNIT_TEST(TestSetContentType) {
         const char* EXPECTED = "HTTP/1.1 200 Ok\r\n"
@@ -139,4 +139,4 @@ Y_UNIT_TEST_SUITE(TestHttpResponse) {
             .SetContentType("text/xml");
         UNIT_ASSERT_STRINGS_EQUAL(ToString(resp), EXPECTED);
     }
-} 
+}

+ 1 - 1
library/cpp/http/server/ya.make

@@ -13,7 +13,7 @@ SRCS(
     http.cpp
     http_ex.cpp
     options.cpp
-    response.cpp 
+    response.cpp
 )
 
 PEERDIR(

Some files were not shown because too many files changed in this diff