QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / ios / web / public / test / response_providers / response_provider.h
blobdbf73ac47bd3aa9ff441b1c9aad21deadbe5a8af
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 #ifndef IOS_WEB_PUBLIC_TEST_RESPONSE_PROVIDERS_RESPONSE_PROVIDER_H_
6 #define IOS_WEB_PUBLIC_TEST_RESPONSE_PROVIDERS_RESPONSE_PROVIDER_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "net/http/http_request_headers.h"
12 #include "net/http/http_response_headers.h"
13 #include "net/http/http_status_code.h"
14 #include "url/gurl.h"
16 #ifdef __OBJC__
17 @class GCDWebServerResponse;
18 #else
19 class GCDWebServerResponse;
20 #endif
22 namespace web {
24 // An abstract class for a provider that services a request and returns a
25 // GCDWebServerResponse.
26 // Note: The ResponseProviders can be called from any arbitrary GCD thread.
27 class ResponseProvider {
28 public:
29 // A data structure that encapsulated all the fields of a request.
30 struct Request {
31 Request(const GURL& url,
32 const std::string& method,
33 const std::string& body,
34 const net::HttpRequestHeaders& headers);
35 virtual ~Request();
37 // The URL for the request.
38 GURL url;
39 // The HTTP method for the request such as "GET" or "POST".
40 std::string method;
41 // The body of the request.
42 std::string body;
43 // The HTTP headers for the request.
44 net::HttpRequestHeaders headers;
47 // Returns true if the request is handled by the provider.
48 virtual bool CanHandleRequest(const Request& request) = 0;
50 // Returns the GCDWebServerResponse as a reply to the request. Will only be
51 // called if the provider can handle the request.
52 virtual GCDWebServerResponse* GetGCDWebServerResponse(
53 const Request& request) = 0;
55 // Gets default response headers with a text/html content type and a 200
56 // response code.
57 static scoped_refptr<net::HttpResponseHeaders> GetDefaultResponseHeaders();
58 // Gets configurable response headers with a provided content type and a
59 // 200 response code.
60 static scoped_refptr<net::HttpResponseHeaders> GetResponseHeaders(
61 const std::string& content_type);
62 // Gets configurable response headers with a provided content type and
63 // response code.
64 static scoped_refptr<net::HttpResponseHeaders> GetResponseHeaders(
65 const std::string& content_type,
66 net::HttpStatusCode response_code);
67 // Gets configurable response based on |http_status| headers for redirecting
68 // to |destination|.
69 static scoped_refptr<net::HttpResponseHeaders> GetRedirectResponseHeaders(
70 const std::string& destination,
71 const net::HttpStatusCode& http_status);
73 ResponseProvider();
74 virtual ~ResponseProvider() {};
75 private:
76 DISALLOW_COPY_AND_ASSIGN(ResponseProvider);
79 } // namspace web
81 #endif // IOS_WEB_PUBLIC_TEST_RESPONSE_PROVIDERS_RESPONSE_PROVIDER_H_