HttpMockProvider

A pseudo-cache to provide a mock server. Construct one of these, populate it with test responses, and pass it to HttpClient to do a network-free test.

You should populate it with the populate method. Any request not pre-populated will return a "server refused connection" response.

Members

Functions

cacheResponse
bool cacheResponse(HttpRequestParameters request, HttpResponse response)

Implementation of the ICache interface. We never actually cache anything here since it is all about mock responses, not actually caching real data.

getCachedResponse
const(HttpResponse)* getCachedResponse(HttpRequestParameters request)

Implementation of the ICache interface. Hijacks all requests to return a pre-populated response or "server disconnected".

populate
void populate(string request, int responseCode, string response)

Convenience method to populate simple responses. For more complex work, use one of the other overloads where you build complete objects yourself.

Inherited Members

From ICache

getCachedResponse
const(HttpResponse)* getCachedResponse(HttpRequestParameters request)

The client is about to make the given request. It will ALWAYS pass it to the cache object first so you can decide if you want to and can provide a response. You should probably check the appropriate headers to see if you should even attempt to look up on the cache (HttpClient does NOT do this to give maximum flexibility to the cache implementor).

cacheResponse
bool cacheResponse(HttpRequestParameters request, HttpResponse response)

The given request has received the given response. The implementing class needs to decide if it wants to cache or not. Return true if it was added, false if you chose not to.

Meta