-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathIResourceHandler.cs
More file actions
85 lines (78 loc) · 5 KB
/
IResourceHandler.cs
File metadata and controls
85 lines (78 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright © 2014 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;
using System.IO;
namespace CefSharp
{
/// <summary>
/// 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, GetResponseHeaders will be called where you
/// can modify the response including headers, or even redirect to a new Url. Set your responseLength and headers
/// Populate the dataOut stream in ReadResponse. For those looking for a sample implementation or upgrading from
/// a previous version <see cref="ResourceHandler"/>. For those upgrading, inherit from ResourceHandler instead of IResourceHandler
/// add the override keywoard to existing methods e.g. ProcessRequestAsync.
/// </summary>
public interface IResourceHandler : IDisposable
{
/// <summary>
/// Begin processing the request.
/// </summary>
/// <param name="request">The request object.</param>
/// <param name="callback">The callback used to Continue or Cancel the request (async).</param>
/// <returns>To handle the request return true and call
/// <see cref="ICallback.Continue"/> once the response header information is available
/// <see cref="ICallback.Continue"/> can also be called from inside this method if
/// header information is available immediately).
/// To cancel the request return false.</returns>
bool ProcessRequest(IRequest request, ICallback callback);
/// <summary>
/// Retrieve response header information. If the response length is not known
/// set responseLength to -1 and ReadResponse() will be called until it
/// returns false. If the response length is known set responseLength
/// to a positive value and ReadResponse() will be called until it returns
/// false or the specified number of bytes have been read.
/// If an error occured while setting up the request you can set <see cref="IResponse.ErrorCode"/>
/// to indicate the error condition.
/// </summary>
/// <param name="response">Use the response object to set the mime type, http status code and other optional header values.</param>
/// <param name="responseLength">If the response length is not known set responseLength to -1</param>
/// <param name="redirectUrl">To redirect the request to a new URL set redirectUrl to the new Url.</param>
void GetResponseHeaders(IResponse response, out long responseLength, out string redirectUrl);
/// <summary>
/// Read response data. If data is available immediately copy to
/// dataOut, set bytesRead to the number of bytes copied, and return true.
/// To read the data at a later time set bytesRead to 0, return true and call ICallback.Continue() when the
/// data is available. To indicate response completion return false.
/// </summary>
/// <param name="dataOut">Stream to write to</param>
/// <param name="bytesRead">Number of bytes copied to the stream</param>
/// <param name="callback">The callback used to Continue or Cancel the request (async).</param>
/// <returns>If data is available immediately copy to dataOut, set bytesRead to the number of bytes copied,
/// and return true.To indicate response completion return false.</returns>
/// <remarks>Depending on this size of your response this method may be called multiple times</remarks>
bool ReadResponse(Stream dataOut, out int bytesRead, ICallback callback);
/// <summary>
/// Return true if the specified cookie can be sent with the request or false
/// otherwise. If false is returned for any cookie then no cookies will be sent
/// with the request.
/// </summary>
/// <param name="cookie">cookie</param>
/// <returns>Return true if the specified cookie can be sent with the request or false
/// otherwise. If false is returned for any cookie then no cookies will be sent
/// with the request.</returns>
bool CanGetCookie(Cookie cookie);
/// <summary>
/// Return true if the specified cookie returned with the response can be set or false otherwise.
/// </summary>
/// <param name="cookie">cookie</param>
/// <returns>Return true if the specified cookie returned with the response can be set or false otherwise.</returns>
bool CanSetCookie(Cookie cookie);
/// <summary>
/// Request processing has been canceled.
/// </summary>
void Cancel();
}
}