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_
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"
17 @
class GCDWebServerResponse
;
19 class GCDWebServerResponse
;
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
{
29 // A data structure that encapsulated all the fields of a request.
31 Request(const GURL
& url
,
32 const std::string
& method
,
33 const std::string
& body
,
34 const net::HttpRequestHeaders
& headers
);
37 // The URL for the request.
39 // The HTTP method for the request such as "GET" or "POST".
41 // The body of the request.
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
57 static scoped_refptr
<net::HttpResponseHeaders
> GetDefaultResponseHeaders();
58 // Gets configurable response headers with a provided content type and a
60 static scoped_refptr
<net::HttpResponseHeaders
> GetResponseHeaders(
61 const std::string
& content_type
);
62 // Gets configurable response headers with a provided content type and
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
69 static scoped_refptr
<net::HttpResponseHeaders
> GetRedirectResponseHeaders(
70 const std::string
& destination
,
71 const net::HttpStatusCode
& http_status
);
74 virtual ~ResponseProvider() {};
76 DISALLOW_COPY_AND_ASSIGN(ResponseProvider
);
81 #endif // IOS_WEB_PUBLIC_TEST_RESPONSE_PROVIDERS_RESPONSE_PROVIDER_H_