QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / ios / web / public / test / response_providers / data_response_provider.mm
blobae04b8f2131bde2c4d211b5abcccfe06c1b0c6da
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ios/web/public/test/response_providers/data_response_provider.h"
7 #include "base/strings/sys_string_conversions.h"
8 #import "ios/third_party/gcdwebserver/src/GCDWebServer/Responses/GCDWebServerDataResponse.h"
10 namespace web {
12 GCDWebServerResponse* DataResponseProvider::GetGCDWebServerResponse(
13     const Request& request) {
14   std::string response_body;
15   scoped_refptr<net::HttpResponseHeaders> response_headers;
16   GetResponseHeadersAndBody(request, &response_headers, &response_body);
17   GCDWebServerDataResponse* data_response = [GCDWebServerDataResponse
18       responseWithHTML:base::SysUTF8ToNSString(response_body)];
19   data_response.statusCode = response_headers->response_code();
20   void* iter = nullptr;
21   std::string name;
22   std::string value;
23   while (response_headers->EnumerateHeaderLines(&iter, &name, &value)) {
24     // TODO(shreyasv): Extract out other names that can't be set by using the
25     // |setValue:forAdditionalHeader:| API such as "ETag" etc. crbug.com/435350
26     if (name == "Content-type") {
27       data_response.contentType = base::SysUTF8ToNSString(value);
28       continue;
29     }
30     [data_response setValue:base::SysUTF8ToNSString(value)
31         forAdditionalHeader:base::SysUTF8ToNSString(name)];
32   }
33   return data_response;
36 }  // namespace web