Thanks Dimitry, Thats exactly what i want. I have implemented my own resourcehandler and registered with the RegisterSchemeHandlerFactory. Below the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xilium.CefGlue;
using System.Windows.Forms;
using System.IO;
namespace Reader
{
class ReaderResourceHandler : CefResourceHandler
{
private bool _completed;
private string _url;
private string _resourceFolder = "res";
private Utils _objUtils = new Utils();
private long _pos,_resLength;
private byte[] _content;
protected override bool ProcessRequest(CefRequest request, CefCallback callback)
{
_url = request.Url;
callback.Continue();
return true;
}
protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
{
//response.SetHeaderMap();
response.Status = 200;
response.MimeType = getMimeType();
response.StatusText = "OK";
responseLength = -1; // unknown content-length
redirectUrl = null; // no-redirect
}
protected override bool ReadResponse(System.IO.Stream response, int bytesToRead, out int bytesRead, CefCallback callback)
{
if (_completed)
{
bytesRead = 0;
return false;
}
else
{
var content = ReadFromFile();
response.Write(content, 0, content.Length);
bytesRead = content.Length;
_completed = true;
return true;
}
}
protected override bool CanGetCookie(CefCookie cookie)
{
return true;
}
protected override bool CanSetCookie(CefCookie cookie)
{
return true;
}
protected override void Cancel()
{
}
private Byte[] ReadFromFile()
{
var _fileName = getFileName();
if (!String.IsNullOrEmpty(_fileName))
{
var _filePath = Application.StartupPath + "\\" + _resourceFolder + "\\" + getFileName();
return File.ReadAllBytes(_filePath);
}
else
{
return null;
}
}
private string getFileName()
{
return (_url_splitted.Length > 0) ? _url_splitted[1] : null;
}
private string getMimeType()
{
var _url_splitted = _url.Split('.');
return _objUtils.GetMimeType(_url_splitted[_url_splitted.Length-1]);
}
}
}
All assets are started serving fine. Except one big js file. I got the exception NotSupportedException : {"Unable to expand length of this stream beyond its capacity."} at
response.Write(content, 0, content.Length);
Any idea how to fix this?
Cheers
Ramesh