2018-09-10 02:41:13 +02:00
|
|
|
// Copyright © 2016 The CefSharp Authors. All rights reserved.
|
2016-01-18 18:32:44 +10:00
|
|
|
//
|
|
|
|
|
// 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
|
|
|
|
|
{
|
2016-02-18 15:02:26 +10:00
|
|
|
public class FlashResourceHandler : ResourceHandler
|
2016-01-18 18:32:44 +10:00
|
|
|
{
|
2019-06-21 12:07:52 +10:00
|
|
|
public override CefReturnValue ProcessRequestAsync(IRequest request, ICallback callback)
|
2016-01-18 18:32:44 +10:00
|
|
|
{
|
|
|
|
|
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();
|
2016-04-15 16:25:06 +10:00
|
|
|
var mime = httpWebResponse.ContentType;
|
2016-01-18 18:32:44 +10:00
|
|
|
|
2016-04-15 16:25:06 +10:00
|
|
|
var stream = new MemoryStream();
|
2016-01-18 18:32:44 +10:00
|
|
|
receiveStream.CopyTo(stream);
|
|
|
|
|
httpWebResponse.Close();
|
2016-04-15 16:25:06 +10:00
|
|
|
|
|
|
|
|
//Reset the stream position to 0 so the stream can be copied into the underlying unmanaged buffer
|
|
|
|
|
stream.Position = 0;
|
|
|
|
|
|
|
|
|
|
//Populate the response values - No longer need to implement GetResponseHeaders (unless you need to perform a redirect)
|
|
|
|
|
ResponseLength = stream.Length;
|
|
|
|
|
MimeType = mime;
|
|
|
|
|
StatusCode = (int)HttpStatusCode.OK;
|
2018-09-10 02:41:13 +02:00
|
|
|
Stream = stream;
|
|
|
|
|
|
2016-01-18 18:32:44 +10:00
|
|
|
callback.Continue();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2019-06-21 12:07:52 +10:00
|
|
|
return CefReturnValue.ContinueAsync;
|
2016-01-18 18:32:44 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|