1 // Copyright 2014 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/response_provider.h"
7 #include "base/strings/stringprintf.h"
8 #include "net/http/http_response_headers.h"
12 ResponseProvider::Request::Request(const GURL
& url
,
13 const std::string
& method
,
14 const std::string
& body
,
15 const net::HttpRequestHeaders
& headers
)
22 ResponseProvider::Request::~Request() {
25 ResponseProvider::ResponseProvider() {
29 scoped_refptr
<net::HttpResponseHeaders
> ResponseProvider::GetResponseHeaders(
30 const std::string
& content_type
,
31 net::HttpStatusCode response_code
) {
32 scoped_refptr
<net::HttpResponseHeaders
> result(
33 new net::HttpResponseHeaders(""));
34 const std::string
reason_phrase(net::GetHttpReasonPhrase(response_code
));
35 const std::string status_line
= base::StringPrintf("HTTP/1.1 %i %s",
36 static_cast<int>(response_code
),
37 reason_phrase
.c_str());
38 result
->ReplaceStatusLine(status_line
);
39 const std::string content_type_header
=
40 base::StringPrintf("Content-type: %s", content_type
.c_str());
41 result
->AddHeader(content_type_header
);
46 scoped_refptr
<net::HttpResponseHeaders
> ResponseProvider::GetResponseHeaders(
47 const std::string
& content_type
) {
48 return GetResponseHeaders(content_type
, net::HTTP_OK
);
52 scoped_refptr
<net::HttpResponseHeaders
>
53 ResponseProvider::GetDefaultResponseHeaders() {
54 return GetResponseHeaders("text/html", net::HTTP_OK
);
58 scoped_refptr
<net::HttpResponseHeaders
>
59 ResponseProvider::GetRedirectResponseHeaders(
60 const std::string
& destination
,
61 const net::HttpStatusCode
& http_status
) {
62 scoped_refptr
<net::HttpResponseHeaders
> headers(
63 GetResponseHeaders("text/html", http_status
));
64 headers
->AddHeader("Location: " + destination
);