// `wget -p --save_headers <url>`
class QuicInMemoryCache {
public:
+ enum SpecialResponseType {
+ REGULAR_RESPONSE, // Send the headers and body like a server should.
+ CLOSE_CONNECTION, // Close the connection (sending the close packet).
+ IGNORE_REQUEST, // Do nothing, expect the client to time out.
+ };
+
// Container for response header/body pairs.
class Response {
public:
- Response() {}
+ Response() : response_type_(REGULAR_RESPONSE) {}
~Response() {}
+ SpecialResponseType response_type() const { return response_type_; }
const BalsaHeaders& headers() const { return headers_; }
const base::StringPiece body() const { return base::StringPiece(body_); }
body.CopyToString(&body_);
}
+ SpecialResponseType response_type_;
BalsaHeaders headers_;
std::string body_;
static QuicInMemoryCache* GetInstance();
// Retrieve a response from this cache for a given request.
- // If no appropriate response exists, NULL is returned.
+ // If no appropriate response exists, nullptr is returned.
// Currently, responses are selected based on request URI only.
const Response* GetResponse(const BalsaHeaders& request_headers) const;
const BalsaHeaders& response_headers,
base::StringPiece response_body);
+ // Simulate a special behavior at a particular path.
+ void AddSpecialResponse(base::StringPiece method,
+ base::StringPiece path,
+ base::StringPiece version,
+ SpecialResponseType response_type);
+
private:
typedef base::hash_map<std::string, Response*> ResponseMap;
friend struct DefaultSingletonTraits<QuicInMemoryCache>;