OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/test/webdriver/webdriver_dispatch.h" | 5 #include "chrome/test/webdriver/webdriver_dispatch.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 ErrorCode status = command_response.GetStatus(); | 145 ErrorCode status = command_response.GetStatus(); |
146 switch (status) { | 146 switch (status) { |
147 case kSuccess: | 147 case kSuccess: |
148 http_response->set_status(HttpResponse::kOk); | 148 http_response->set_status(HttpResponse::kOk); |
149 break; | 149 break; |
150 | 150 |
151 // TODO(jleyba): kSeeOther, kBadRequest, kSessionNotFound, | 151 // TODO(jleyba): kSeeOther, kBadRequest, kSessionNotFound, |
152 // and kMethodNotAllowed should be detected before creating | 152 // and kMethodNotAllowed should be detected before creating |
153 // a command_response, and should thus not need conversion. | 153 // a command_response, and should thus not need conversion. |
154 case kSeeOther: { | 154 case kSeeOther: { |
155 Value* value = command_response.GetValue(); | 155 const Value* const value = command_response.GetValue(); |
156 std::string location; | 156 std::string location; |
157 if (!value->GetAsString(&location)) { | 157 if (!value->GetAsString(&location)) { |
158 // This should never happen. | 158 // This should never happen. |
159 http_response->set_status(HttpResponse::kInternalServerError); | 159 http_response->set_status(HttpResponse::kInternalServerError); |
160 http_response->SetBody("Unable to set 'Location' header: response " | 160 http_response->SetBody("Unable to set 'Location' header: response " |
161 "value is not a string: " + | 161 "value is not a string: " + |
162 command_response.ToJSON()); | 162 command_response.ToJSON()); |
163 return; | 163 return; |
164 } | 164 } |
165 http_response->AddHeader("Location", location); | 165 http_response->AddHeader("Location", location); |
166 http_response->set_status(HttpResponse::kSeeOther); | 166 http_response->set_status(HttpResponse::kSeeOther); |
167 break; | 167 break; |
168 } | 168 } |
169 | 169 |
170 case kBadRequest: | 170 case kBadRequest: |
171 case kSessionNotFound: | 171 case kSessionNotFound: |
172 http_response->set_status(status); | 172 http_response->set_status(status); |
173 break; | 173 break; |
174 | 174 |
175 case kMethodNotAllowed: { | 175 case kMethodNotAllowed: { |
176 Value* value = command_response.GetValue(); | 176 const Value* const value = command_response.GetValue(); |
177 ListValue* list_value = value->AsList(); | 177 if (!value->IsType(Value::TYPE_LIST)) { |
178 if (!list_value) { | |
179 // This should never happen. | 178 // This should never happen. |
180 http_response->set_status(HttpResponse::kInternalServerError); | 179 http_response->set_status(HttpResponse::kInternalServerError); |
181 http_response->SetBody( | 180 http_response->SetBody( |
182 "Unable to set 'Allow' header: response value was " | 181 "Unable to set 'Allow' header: response value was " |
183 "not a list of strings: " + command_response.ToJSON()); | 182 "not a list of strings: " + command_response.ToJSON()); |
184 return; | 183 return; |
185 } | 184 } |
186 | 185 |
| 186 const ListValue* const list_value = |
| 187 static_cast<const ListValue* const>(value); |
187 std::vector<std::string> allowed_methods; | 188 std::vector<std::string> allowed_methods; |
188 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 189 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
189 std::string method; | 190 std::string method; |
190 if (list_value->GetString(i, &method)) { | 191 if (list_value->GetString(i, &method)) { |
191 allowed_methods.push_back(method); | 192 allowed_methods.push_back(method); |
192 } else { | 193 } else { |
193 // This should never happen. | 194 // This should never happen. |
194 http_response->set_status(HttpResponse::kInternalServerError); | 195 http_response->set_status(HttpResponse::kInternalServerError); |
195 http_response->SetBody( | 196 http_response->SetBody( |
196 "Unable to set 'Allow' header: response value was " | 197 "Unable to set 'Allow' header: response value was " |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 void Dispatcher::SetNotImplemented(const std::string& pattern) { | 332 void Dispatcher::SetNotImplemented(const std::string& pattern) { |
332 mg_set_uri_callback(context_, (root_ + pattern).c_str(), | 333 mg_set_uri_callback(context_, (root_ + pattern).c_str(), |
333 &SendNotImplementedError, NULL); | 334 &SendNotImplementedError, NULL); |
334 } | 335 } |
335 | 336 |
336 void Dispatcher::ForbidAllOtherRequests() { | 337 void Dispatcher::ForbidAllOtherRequests() { |
337 mg_set_uri_callback(context_, "*", &SendForbidden, NULL); | 338 mg_set_uri_callback(context_, "*", &SendForbidden, NULL); |
338 } | 339 } |
339 | 340 |
340 } // namespace webdriver | 341 } // namespace webdriver |
OLD | NEW |