Skip to content

Commit 578ff7e

Browse files
committed
Add ErrorCode to ResourceHandler - can now set the IResponse.ErrorCode without having to manually implement IResourceHandler
1 parent 1bfd7d5 commit 578ff7e

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

CefSharp/ResourceHandler.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ public class ResourceHandler : IResourceHandler
7474
/// </summary>
7575
public bool AutoDisposeStream { get; set; }
7676

77+
/// <summary>
78+
/// If the ErrorCode is set then the response will be ignored and
79+
/// the errorCode returned.
80+
/// </summary>
81+
public CefErrorCode? ErrorCode { get; set; }
82+
7783
/// <summary>
7884
/// Default Constructor
7985
/// </summary>
@@ -172,12 +178,21 @@ bool IResourceHandler.ProcessRequest(IRequest request, ICallback callback)
172178

173179
void IResourceHandler.GetResponseHeaders(IResponse response, out long responseLength, out string redirectUrl)
174180
{
175-
Stream = GetResponse(response, out responseLength, out redirectUrl);
176-
177-
if(Stream != null && Stream.CanSeek)
181+
if (ErrorCode.HasValue)
178182
{
179-
//Reset the stream position to 0
180-
Stream.Position = 0;
183+
responseLength = 0;
184+
redirectUrl = null;
185+
response.ErrorCode = ErrorCode.Value;
186+
}
187+
else
188+
{
189+
Stream = GetResponse(response, out responseLength, out redirectUrl);
190+
191+
if(Stream != null && Stream.CanSeek)
192+
{
193+
//Reset the stream position to 0
194+
Stream.Position = 0;
195+
}
181196
}
182197
}
183198

0 commit comments

Comments
 (0)