OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 | 1035 |
1036 EXPECT_EQ(tests[i].expected_len, parsed->GetContentLength()); | 1036 EXPECT_EQ(tests[i].expected_len, parsed->GetContentLength()); |
1037 } | 1037 } |
1038 } | 1038 } |
1039 | 1039 |
1040 TEST(HttpResponseHeadersTest, IsKeepAlive) { | 1040 TEST(HttpResponseHeadersTest, IsKeepAlive) { |
1041 const struct { | 1041 const struct { |
1042 const char* headers; | 1042 const char* headers; |
1043 bool expected_keep_alive; | 1043 bool expected_keep_alive; |
1044 } tests[] = { | 1044 } tests[] = { |
| 1045 // The status line fabricated by HttpNetworkTransaction for a 0.9 response. |
| 1046 // Treated as 0.9. |
| 1047 { "HTTP/0.9 200 OK", |
| 1048 false |
| 1049 }, |
| 1050 // This could come from a broken server. Treated as 1.0 because it has a |
| 1051 // header. |
| 1052 { "HTTP/0.9 200 OK\n" |
| 1053 "connection: keep-alive\n", |
| 1054 true |
| 1055 }, |
1045 { "HTTP/1.1 200 OK\n", | 1056 { "HTTP/1.1 200 OK\n", |
1046 true | 1057 true |
1047 }, | 1058 }, |
1048 { "HTTP/1.0 200 OK\n", | 1059 { "HTTP/1.0 200 OK\n", |
1049 false | 1060 false |
1050 }, | 1061 }, |
1051 { "HTTP/1.0 200 OK\n" | 1062 { "HTTP/1.0 200 OK\n" |
1052 "connection: close\n", | 1063 "connection: close\n", |
1053 false | 1064 false |
1054 }, | 1065 }, |
(...skipping 10 matching lines...) Expand all Loading... |
1065 false | 1076 false |
1066 }, | 1077 }, |
1067 { "HTTP/1.1 200 OK\n" | 1078 { "HTTP/1.1 200 OK\n" |
1068 "connection: close\n", | 1079 "connection: close\n", |
1069 false | 1080 false |
1070 }, | 1081 }, |
1071 { "HTTP/1.1 200 OK\n" | 1082 { "HTTP/1.1 200 OK\n" |
1072 "connection: keep-alive\n", | 1083 "connection: keep-alive\n", |
1073 true | 1084 true |
1074 }, | 1085 }, |
| 1086 { "HTTP/1.0 200 OK\n" |
| 1087 "proxy-connection: close\n", |
| 1088 false |
| 1089 }, |
| 1090 { "HTTP/1.0 200 OK\n" |
| 1091 "proxy-connection: keep-alive\n", |
| 1092 true |
| 1093 }, |
1075 { "HTTP/1.1 200 OK\n" | 1094 { "HTTP/1.1 200 OK\n" |
1076 "proxy-connection: close\n", | 1095 "proxy-connection: close\n", |
1077 false | 1096 false |
1078 }, | 1097 }, |
| 1098 { "HTTP/1.1 200 OK\n" |
| 1099 "proxy-connection: keep-alive\n", |
| 1100 true |
| 1101 }, |
1079 }; | 1102 }; |
1080 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1103 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
1081 string headers(tests[i].headers); | 1104 string headers(tests[i].headers); |
1082 HeadersToRaw(&headers); | 1105 HeadersToRaw(&headers); |
1083 scoped_refptr<HttpResponseHeaders> parsed = | 1106 scoped_refptr<HttpResponseHeaders> parsed = |
1084 new HttpResponseHeaders(headers); | 1107 new HttpResponseHeaders(headers); |
1085 | 1108 |
1086 EXPECT_EQ(tests[i].expected_keep_alive, parsed->IsKeepAlive()); | 1109 EXPECT_EQ(tests[i].expected_keep_alive, parsed->IsKeepAlive()); |
1087 } | 1110 } |
1088 } | 1111 } |
(...skipping 21 matching lines...) Expand all Loading... |
1110 } | 1133 } |
1111 | 1134 |
1112 TEST(HttpResponseHeadersTest, GetStatusBadStatusLine) { | 1135 TEST(HttpResponseHeadersTest, GetStatusBadStatusLine) { |
1113 std::string headers("Foo bar."); | 1136 std::string headers("Foo bar."); |
1114 HeadersToRaw(&headers); | 1137 HeadersToRaw(&headers); |
1115 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); | 1138 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); |
1116 // The bad status line would have gotten rewritten as | 1139 // The bad status line would have gotten rewritten as |
1117 // HTTP/1.0 200 OK. | 1140 // HTTP/1.0 200 OK. |
1118 EXPECT_EQ(std::string("OK"), parsed->GetStatusText()); | 1141 EXPECT_EQ(std::string("OK"), parsed->GetStatusText()); |
1119 } | 1142 } |
OLD | NEW |