| 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 const Value* const value = command_response.GetValue(); | 155 Value* 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 const Value* const value = command_response.GetValue(); | 176 Value* value = command_response.GetValue(); |
| 177 if (!value->IsType(Value::TYPE_LIST)) { | 177 ListValue* list_value = value->AsList(); |
| 178 if (!list_value) { |
| 178 // This should never happen. | 179 // This should never happen. |
| 179 http_response->set_status(HttpResponse::kInternalServerError); | 180 http_response->set_status(HttpResponse::kInternalServerError); |
| 180 http_response->SetBody( | 181 http_response->SetBody( |
| 181 "Unable to set 'Allow' header: response value was " | 182 "Unable to set 'Allow' header: response value was " |
| 182 "not a list of strings: " + command_response.ToJSON()); | 183 "not a list of strings: " + command_response.ToJSON()); |
| 183 return; | 184 return; |
| 184 } | 185 } |
| 185 | 186 |
| 186 const ListValue* const list_value = | |
| 187 static_cast<const ListValue* const>(value); | |
| 188 std::vector<std::string> allowed_methods; | 187 std::vector<std::string> allowed_methods; |
| 189 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 188 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
| 190 std::string method; | 189 std::string method; |
| 191 if (list_value->GetString(i, &method)) { | 190 if (list_value->GetString(i, &method)) { |
| 192 allowed_methods.push_back(method); | 191 allowed_methods.push_back(method); |
| 193 } else { | 192 } else { |
| 194 // This should never happen. | 193 // This should never happen. |
| 195 http_response->set_status(HttpResponse::kInternalServerError); | 194 http_response->set_status(HttpResponse::kInternalServerError); |
| 196 http_response->SetBody( | 195 http_response->SetBody( |
| 197 "Unable to set 'Allow' header: response value was " | 196 "Unable to set 'Allow' header: response value was " |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 void Dispatcher::SetNotImplemented(const std::string& pattern) { | 331 void Dispatcher::SetNotImplemented(const std::string& pattern) { |
| 333 mg_set_uri_callback(context_, (root_ + pattern).c_str(), | 332 mg_set_uri_callback(context_, (root_ + pattern).c_str(), |
| 334 &SendNotImplementedError, NULL); | 333 &SendNotImplementedError, NULL); |
| 335 } | 334 } |
| 336 | 335 |
| 337 void Dispatcher::ForbidAllOtherRequests() { | 336 void Dispatcher::ForbidAllOtherRequests() { |
| 338 mg_set_uri_callback(context_, "*", &SendForbidden, NULL); | 337 mg_set_uri_callback(context_, "*", &SendForbidden, NULL); |
| 339 } | 338 } |
| 340 | 339 |
| 341 } // namespace webdriver | 340 } // namespace webdriver |
| OLD | NEW |