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"
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();
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);
30 [data_response setValue:base::SysUTF8ToNSString(value)
31 forAdditionalHeader:base::SysUTF8ToNSString(name)];