// Copyright © 2010-2015 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System.IO;
namespace CefSharp
{
///
/// Class used to implement a custom resource handler. The methods of this class will always be called on the CEF IO thread.
/// Blocking the CEF IO thread will adversely affect browser performance. We suggest you execute your code in a Task (or similar).
/// To implement async handling, spawn a new Task (or similar), keep a reference to the callback. When you have a
/// fully populated stream, execute the callback. Once the callback Executes, GetResponse will be called where you
/// can modify the response including headers, or even redirect to a new Url. Typically you would set the responseLength
/// and return your fully populated Stream
///
public interface IResourceHandler
{
///
/// Processes request asynchronously.
///
/// The request object.
/// The callback used to Continue or Cancel the request (async).
/// true if the request is handled, false otherwise.
bool ProcessRequestAsync(IRequest request, ICallback callback);
///
/// Populate the response stream, response length. When this method is called
/// the response should be fully populated with data
/// It is possible to redirect to another url at this point in time
///
/// The response object used to set Headers, StatusCode, etc
/// length of the response
/// If set the request will be redirect to specified Url
/// The response stream
Stream GetResponse(IResponse response, out long responseLength, out string redirectUrl);
}
}