Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: net/tools/quic/test_tools/http_message.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/tools/quic/test_tools/http_message.h" 5 #include "net/tools/quic/test_tools/http_message.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 12
13 using base::StringPiece; 13 using base::StringPiece;
14 using std::string; 14 using std::string;
15 using std::vector; 15 using std::vector;
16 16
17 namespace net { 17 namespace net {
18 namespace tools { 18 namespace tools {
19 namespace test { 19 namespace test {
20 20
21 namespace { 21 namespace {
22 22
23 //const char* kContentEncoding = "content-encoding"; 23 // const char* kContentEncoding = "content-encoding";
24 const char* kContentLength = "content-length"; 24 const char* kContentLength = "content-length";
25 const char* kTransferCoding = "transfer-encoding"; 25 const char* kTransferCoding = "transfer-encoding";
26 26
27 // Both kHTTPVersionString and kMethodString arrays are constructed to match 27 // Both kHTTPVersionString and kMethodString arrays are constructed to match
28 // the enum values defined in Version and Method of HTTPMessage. 28 // the enum values defined in Version and Method of HTTPMessage.
29 const char* kHTTPVersionString[] = { 29 const char* kHTTPVersionString[] = {"", "HTTP/0.9", "HTTP/1.0", "HTTP/1.1"};
30 "",
31 "HTTP/0.9",
32 "HTTP/1.0",
33 "HTTP/1.1"
34 };
35 30
36 const char* kMethodString[] = { 31 const char* kMethodString[] = {
37 "", 32 "", "OPTIONS", "GET", "HEAD", "POST", "PUT",
38 "OPTIONS", 33 "DELETE", "TRACE", "CONNECT", "MKCOL", "UNLOCK",
39 "GET",
40 "HEAD",
41 "POST",
42 "PUT",
43 "DELETE",
44 "TRACE",
45 "CONNECT",
46 "MKCOL",
47 "UNLOCK",
48 }; 34 };
49 35
50 // Returns true if the message represents a complete request or response. 36 // Returns true if the message represents a complete request or response.
51 // Messages are considered complete if: 37 // Messages are considered complete if:
52 // - Transfer-Encoding: chunked is present and message has a final chunk. 38 // - Transfer-Encoding: chunked is present and message has a final chunk.
53 // - Content-Length header is present and matches the message body length. 39 // - Content-Length header is present and matches the message body length.
54 // - Neither Transfer-Encoding nor Content-Length is present and message 40 // - Neither Transfer-Encoding nor Content-Length is present and message
55 // is tagged as complete. 41 // is tagged as complete.
56 bool IsCompleteMessage(const HTTPMessage& message) { 42 bool IsCompleteMessage(const HTTPMessage& message) {
57 const BalsaHeaders* headers = message.headers(); 43 const BalsaHeaders* headers = message.headers();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 const char* HTTPMessage::MethodToString(Method method) { 80 const char* HTTPMessage::MethodToString(Method method) {
95 CHECK_LT(static_cast<size_t>(method), arraysize(kMethodString)); 81 CHECK_LT(static_cast<size_t>(method), arraysize(kMethodString));
96 return kMethodString[method]; 82 return kMethodString[method];
97 } 83 }
98 84
99 const char* HTTPMessage::VersionToString(Version version) { 85 const char* HTTPMessage::VersionToString(Version version) {
100 CHECK_LT(static_cast<size_t>(version), arraysize(kHTTPVersionString)); 86 CHECK_LT(static_cast<size_t>(version), arraysize(kHTTPVersionString));
101 return kHTTPVersionString[version]; 87 return kHTTPVersionString[version];
102 } 88 }
103 89
104 HTTPMessage::HTTPMessage() 90 HTTPMessage::HTTPMessage() : is_request_(true) {
105 : is_request_(true) {
106 InitializeFields(); 91 InitializeFields();
107 } 92 }
108 93
109 HTTPMessage::HTTPMessage(Version ver, Method request, const string& path) 94 HTTPMessage::HTTPMessage(Version ver, Method request, const string& path)
110 : is_request_(true) { 95 : is_request_(true) {
111 InitializeFields(); 96 InitializeFields();
112 if (ver != HttpConstants::HTTP_0_9) { 97 if (ver != HttpConstants::HTTP_0_9) {
113 headers()->SetRequestVersion(VersionToString(ver)); 98 headers()->SetRequestVersion(VersionToString(ver));
114 } 99 }
115 headers()->SetRequestMethod(MethodToString(request)); 100 headers()->SetRequestMethod(MethodToString(request));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 return; 137 return;
153 } 138 }
154 139
155 vector<StringPiece> transfer_encodings; 140 vector<StringPiece> transfer_encodings;
156 headers()->GetAllOfHeader(kTransferCoding, &transfer_encodings); 141 headers()->GetAllOfHeader(kTransferCoding, &transfer_encodings);
157 CHECK_GE(1ul, transfer_encodings.size()); 142 CHECK_GE(1ul, transfer_encodings.size());
158 for (vector<StringPiece>::iterator it = transfer_encodings.begin(); 143 for (vector<StringPiece>::iterator it = transfer_encodings.begin();
159 it != transfer_encodings.end(); 144 it != transfer_encodings.end();
160 ++it) { 145 ++it) {
161 CHECK(StringPieceUtils::EqualIgnoreCase("identity", *it) || 146 CHECK(StringPieceUtils::EqualIgnoreCase("identity", *it) ||
162 StringPieceUtils::EqualIgnoreCase("chunked", *it)) << *it; 147 StringPieceUtils::EqualIgnoreCase("chunked", *it))
148 << *it;
163 } 149 }
164 150
165 vector<StringPiece> content_lengths; 151 vector<StringPiece> content_lengths;
166 headers()->GetAllOfHeader(kContentLength, &content_lengths); 152 headers()->GetAllOfHeader(kContentLength, &content_lengths);
167 CHECK_GE(1ul, content_lengths.size()); 153 CHECK_GE(1ul, content_lengths.size());
168 154
169 CHECK_EQ(has_complete_message_, IsCompleteMessage(*this)); 155 CHECK_EQ(has_complete_message_, IsCompleteMessage(*this));
170 } 156 }
171 157
172 } // namespace test 158 } // namespace test
173 } // namespace tools 159 } // namespace tools
174 } // namespace net 160 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698