Skip to content

Commit

Permalink
Core - Add StreamResponseFilter
Browse files Browse the repository at this point in the history
- Moved from the Cefsharp.Example.Filters.StreamResponseFilter
- Added CanWrite checks in InitFilter
- Updated example to reflect namespace change.
  • Loading branch information
amaitland committed Dec 10, 2019
1 parent 1e88322 commit a9d39d7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
1 change: 0 additions & 1 deletion CefSharp.Example/CefSharp.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
<Compile Include="Filters\FindReplaceMultiResponseFilter.cs" />
<Compile Include="Filters\FindReplaceResponseFilter.cs" />
<Compile Include="Filters\ExperimentalStreamResponseFilter.cs" />
<Compile Include="Filters\StreamResponseFilter.cs" />
<Compile Include="FlashResourceHandler.cs" />
<Compile Include="Filters\PassThruResponseFilter.cs" />
<Compile Include="Handlers\BrowserProcessHandler.cs" />
Expand Down
1 change: 1 addition & 0 deletions CefSharp.Example/Handlers/ExampleResourceRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using CefSharp.Example.Filters;
using CefSharp.Handler;
using CefSharp.ResponseFilter;

namespace CefSharp.Example.Handlers
{
Expand Down
1 change: 1 addition & 0 deletions CefSharp/CefSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
<Compile Include="RenderProcess\IV8Context.cs" />
<Compile Include="RenderProcess\V8Exception.cs" />
<Compile Include="RequestContextExtensions.cs" />
<Compile Include="ResponseFilter\StreamResponseFilter.cs" />
<Compile Include="Structs\TouchEvent.cs" />
<Compile Include="V8Extension.cs" />
<Compile Include="CefLibraryHandle.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,29 @@
using System;
using System.IO;

namespace CefSharp.Example.Filters
namespace CefSharp.ResponseFilter
{
/// <summary>
/// StreamResponseFilter - copies all data from IResponseFilter.Filter
/// to the provided Stream. This is provided as an example to get you started and has not been
/// production tested. If you experience problems you should refer to the CEF documentation
/// and ask any questions you have on http://magpcss.org/ceforum/index.php
/// Make sure to ask your question in the context of the CEF API (remember that CefSharp is just a wrapper).
/// https://magpcss.org/ceforum/apidocs3/projects/(default)/CefResponseFilter.html#Filter(void*,size_t,size_t&,void*,size_t,size_t&)
/// to the provided Stream. The <see cref="Stream"/> must be writable, no data will be copied otherwise.
/// The StreamResponseFilter will release it's reference (set to null) to the <see cref="Stream"/> when it's Disposed.
/// </summary>
public class StreamResponseFilter : IResponseFilter
{
private Stream responseStream;

/// <summary>
/// StreamResponseFilter constructor
/// </summary>
/// <param name="stream">a writable stream</param>
public StreamResponseFilter(Stream stream)
{
responseStream = stream;
}

bool IResponseFilter.InitFilter()
{
//Will only be called a single time.
//The filter will not be installed if this method returns false.
return true;
return responseStream != null && responseStream.CanWrite;
}

FilterStatus IResponseFilter.Filter(Stream dataIn, out long dataInRead, Stream dataOut, out long dataOutWritten)
Expand Down

0 comments on commit a9d39d7

Please sign in to comment.