Files
cefsharp/CefSharp.Example/FlashResourceHandler.cs
T
amaitland 12f42331dc Resolves #1592 - Expose all methods of CefResourceHandler
Previously we were passing in the frame, request wrappers which hadn't been used, so just keep things simple and remove the code.
Current users should extend ResourceHandler instead of IResourceHandler and add the override keyword
TODO: Deal with setting bytesRead property - currently using Stream.Length which won't work for every stream type
2016-02-18 16:44:51 +10:00

56 lines
1.7 KiB
C#

// Copyright © 2010-2016 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;
using System.Net;
using System.Threading.Tasks;
namespace CefSharp.Example
{
public class FlashResourceHandler : ResourceHandler
{
private MemoryStream stream;
private string mime;
public override bool ProcessRequestAsync(IRequest request, ICallback callback)
{
Task.Run(() =>
{
using (callback)
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://samples.mplayerhq.hu/SWF/zeldaADPCM5bit.swf");
var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
// Get the stream associated with the response.
var receiveStream = httpWebResponse.GetResponseStream();
mime = httpWebResponse.ContentType;
stream = new MemoryStream();
receiveStream.CopyTo(stream);
httpWebResponse.Close();
callback.Continue();
}
});
return true;
}
public override Stream GetResponse(IResponse response, out long responseLength, out string redirectUrl)
{
responseLength = stream.Length;
redirectUrl = null;
response.MimeType = mime;
response.StatusCode = (int)HttpStatusCode.OK;
//Reset the stream position to 0 so the stream can be copied into the underlying unmanaged buffer
stream.Position = 0;
return stream;
}
}
}