xref: /aosp_15_r20/external/cronet/net/http/http_response_headers_test_util.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/http/http_response_headers_test_util.h"
6 
7 #include "base/strings/strcat.h"
8 #include "net/http/http_response_headers.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 
11 namespace net::test {
12 
HttpResponseHeadersToSimpleString(const scoped_refptr<HttpResponseHeaders> & parsed)13 std::string HttpResponseHeadersToSimpleString(
14     const scoped_refptr<HttpResponseHeaders>& parsed) {
15   std::string result = parsed->GetStatusLine() + "\n";
16 
17   size_t iter = 0;
18   std::string name;
19   std::string value;
20   while (parsed->EnumerateHeaderLines(&iter, &name, &value)) {
21     EXPECT_TRUE(name.find('\n') == std::string::npos)
22         << "Newline in name is confusing";
23     EXPECT_TRUE(name.find(':') == std::string::npos)
24         << "Colon in name is ambiguous";
25     EXPECT_TRUE(value.find('\n') == std::string::npos)
26         << "Newline in value is ambiguous";
27 
28     base::StrAppend(&result, {name, ": ", value, "\n"});
29   }
30 
31   return result;
32 }
33 
34 }  // namespace net::test
35