From b8e0146a3c3de594f150356f42cfdb95064d62d3 Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 16 Jun 2025 15:48:58 +0100 Subject: [PATCH] Network: Make Linux networking code robust against user headers that already end with CRLF --- modules/juce_core/native/juce_Network_linux.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/juce_core/native/juce_Network_linux.cpp b/modules/juce_core/native/juce_Network_linux.cpp index bdfe150a2a..71d1983fce 100644 --- a/modules/juce_core/native/juce_Network_linux.cpp +++ b/modules/juce_core/native/juce_Network_linux.cpp @@ -537,7 +537,16 @@ private: if (userHeaders.isNotEmpty()) header << "\r\n" << userHeaders; - header << "\r\n\r\n"; + const auto headerHasCompleteSuffix = [&header] + { + const auto actualEnd = static_cast (header.getData()) + header.getDataSize(); + const auto actualBegin = actualEnd - jmin (header.getDataSize(), (size_t) 4); + const char expected[] { '\r', '\n', '\r', '\n' }; + return std::equal (actualBegin, actualEnd, std::begin (expected), std::end (expected)); + }; + + while (! headerHasCompleteSuffix()) + header << "\r\n"; if (hasPostData) header << postData;