Closed Kumhy closed 3 years ago
@Kumhy
Setting referrer is not a straightforward thing to do.
I have 2 approaches that could help.
public class CustomRequestHandler : DefaultRequestHandler
{
public CustomRequestHandler(IChromelyConfiguration config, IChromelyCommandTaskRunner commandTaskRunner, IChromelyWindow window)
: base(config, commandTaskRunner, window)
{
}
protected override CefResourceRequestHandler GetResourceRequestHandler(CefBrowser browser, CefFrame frame, CefRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
{
return new CustomResourceRequestHandler();
}
}
public class CustomResourceRequestHandler : CefResourceRequestHandler
{
protected override CefCookieAccessFilter GetCookieAccessFilter(CefBrowser browser, CefFrame frame, CefRequest request)
{
return null;
}
protected override CefReturnValue OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request, CefRequestCallback callback)
{
request.SetReferrer("http://google.com", CefReferrerPolicy.Default);
return CefReturnValue.Continue;
}
}
public class DemoApp : ChromelyBasicApp
{
public override void ConfigureServices(IServiceCollection services)
{
base.ConfigureServices(services);
-----
services.AddSingleton<CefRequestHandler, CustomRequestHandler>();
}
}
I made it a bit simpler with what is in the master branch. a. Create a custom CefResourceRequestHandler
public class CustomResourceRequestHandler : CefResourceRequestHandler
{
protected override CefCookieAccessFilter GetCookieAccessFilter(CefBrowser browser, CefFrame frame, CefRequest request)
{
return null;
}
protected override CefReturnValue OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request, CefRequestCallback callback)
{
request.SetReferrer("http://google.com", CefReferrerPolicy.Default);
return CefReturnValue.Continue;
}
}
b. Register the custom CefResourceRequestHandler
public class DemoApp : ChromelyBasicApp
{
public override void ConfigureServices(IServiceCollection services)
{
base.ConfigureServices(services);
-----
services.AddSingleton<CefResourceRequestHandler, CustomResourceRequestHandler>();
}
}
c. Access the referrer in the controller
private IChromelyResponse GetResource(IChromelyRequest request)
{
string referrer = request.Parameters[RequestConstants.Referrer];
}
Thank you for helping me!
<img src="https://www.xxx.com/aaa.jpg"/>
This picture link verifies Referer, I want to add Referer to the request header when loading this image. What should I do?