Commit Diff


commit - 28505793ba79d2fb98b0b505e82e75d7d3b77eae
commit + 33be863885ab69ec32799c7d6844609fa6a5e039
blob - a99927eecbfa09bd8a7e7ed7903d4d3205a28c69
blob + b5b7f57ed4ca0a2f5dd7b6298a98b2c28431e105
--- vostok/gemini.cc
+++ vostok/gemini.cc
@@ -8,17 +8,16 @@ namespace gemini
 {
 
 
-const std::array<char, 2> CRLF{'\r', '\n'};
+const std::array<const char, 2> CRLF{'\r', '\n'};
+const std::array<const char, 1> SPACE{' '};
 
-const std::array<char, 1> SPACE{' '};
+const Status STATUS_20_SUCCESS{'2', '0'};
+const Status STATUS_40_TEMPORARY_FAILURE{'4', '0'};
+const Status STATUS_50_PERMANENT_FAILURE{'5', '0'};
+const Status STATUS_51_NOT_FOUND{'5', '1'};
+const Status STATUS_53_PROXY_REQUEST_REFUSED{'5', '3'};
+const Status STATUS_59_BAD_REQUEST{'5', '9'};
 
-const status_t STATUS_20_SUCCESS{'2', '0'};
-const status_t STATUS_40_TEMPORARY_FAILURE{'4', '0'};
-const status_t STATUS_50_PERMANENT_FAILURE{'5', '0'};
-const status_t STATUS_51_NOT_FOUND{'5', '1'};
-const status_t STATUS_53_PROXY_REQUEST_REFUSED{'5', '3'};
-const status_t STATUS_59_BAD_REQUEST{'5', '9'};
 
-
 }   // namespace gemini
 }   // namespace vostok
blob - 3b9b02c570f7adc25dcbcbb98661afa9c95160af
blob + b2961666037e48305f30dad7d0e7aec54c6ab38f
--- vostok/gemini.h
+++ vostok/gemini.h
@@ -14,16 +14,16 @@ namespace gemini
 constexpr auto MAX_URL_LENGTH = 1024;
 constexpr auto MAX_META_LENGTH = 1024;
 
-extern const std::array<char, 2> CRLF;
-extern const std::array<char, 1> SPACE;
+extern const std::array<const char, 2> CRLF;
+extern const std::array<const char, 1> SPACE;
 
-using status_t = std::array<char, 2>;
-extern const status_t STATUS_20_SUCCESS;
-extern const status_t STATUS_40_TEMPORARY_FAILURE;
-extern const status_t STATUS_50_PERMANENT_FAILURE;
-extern const status_t STATUS_51_NOT_FOUND;
-extern const status_t STATUS_53_PROXY_REQUEST_REFUSED;
-extern const status_t STATUS_59_BAD_REQUEST;
+using Status = std::array<const char, 2>;
+extern const Status STATUS_20_SUCCESS;
+extern const Status STATUS_40_TEMPORARY_FAILURE;
+extern const Status STATUS_50_PERMANENT_FAILURE;
+extern const Status STATUS_51_NOT_FOUND;
+extern const Status STATUS_53_PROXY_REQUEST_REFUSED;
+extern const Status STATUS_59_BAD_REQUEST;
 
 constexpr auto MAX_REQUEST_LENGTH = MAX_URL_LENGTH + CRLF.size();
 
blob - 2aaa254c5a3bfa60d5b3f39508e1eac1210709e8
blob + 3febc5c0529b541c35b077e06a481ff91dc8033a
--- vostok/transport.cc
+++ vostok/transport.cc
@@ -180,18 +180,19 @@ bool read_request(NotNull<struct tls *> ctx, std::vect
 }
 
 
-bool send_response(NotNull<struct tls *> ctx, gemini::status_t status, Span<const char> meta)
+bool send_response(NotNull<struct tls *> ctx, gemini::Status status, Span<const char> meta)
 {
-    // > <STATUS><SPACE><META><CR><LF>
-    std::array<char, status.size() + gemini::SPACE.size() + gemini::MAX_META_LENGTH + gemini::CRLF.size()> buff;
-    auto current = buff.begin();
-    current = std::copy(status.cbegin(), status.cend(), current);
-    current = std::copy(gemini::SPACE.cbegin(), gemini::SPACE.cend(), current);
-    assert(meta.size() <= gemini::MAX_META_LENGTH);
-    current = std::copy(meta.begin(), meta.end(), current);
-    current = std::copy(gemini::CRLF.cbegin(), gemini::CRLF.cend(), current);
-
-    return send(ctx, Span<char const>{&buff[0], static_cast<size_t>(current - buff.begin())});
+    // <STATUS><SPACE><META><CR><LF>
+    if (!send(ctx, status))
+        return false;
+    if (!send(ctx, gemini::SPACE))
+        return false;
+    if (meta.size())
+        if (!send(ctx, meta))
+            return false;
+    if (!send(ctx, gemini::CRLF))
+        return false;
+    return true;
 }
 
 
blob - 4f66289ff2a7033b98164f09f8534ffe59199dba
blob + 102e54212f998f9aaa530cede0eef43433d2b84b
--- vostok/transport.h
+++ vostok/transport.h
@@ -54,7 +54,7 @@ bool read_request(NotNull<struct tls *> ctx, std::vect
 
 
 /** Write gemini response */
-bool send_response(NotNull<struct tls *> ctx, gemini::status_t status, Span<const char> meta);
+bool send_response(NotNull<struct tls *> ctx, gemini::Status status, Span<const char> meta);
 
 
 /** Send raw bytes */
blob - fece1ef2319fa1e4f2a37f7d1bf7542634df0c27
blob + bfc80dc82debb13758a5c46e0f023349e7870537
--- vostok/utils.h
+++ vostok/utils.h
@@ -71,7 +71,7 @@ class Span (public)
     template <std::size_t N>
     constexpr Span(element_type (&arr)[N]) : m_p{arr}, m_count{N} {}
     template <std::size_t N>
-    constexpr Span(std::array<element_type, N> &arr) : m_p{arr.data()}, m_count{N} {}
+    constexpr Span(const std::array<element_type, N> &arr) : m_p{arr.data()}, m_count{N} {}
 
     constexpr std::size_t size() const {return m_count;}