cefsharp / cefsharp/CefSharp.OutOfProcess

RequestHandler to set Proxy Auth not working

Aperta
#29 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C#
Stelle
13
Fork
5
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

for the classes:
```
public class CustomRequestContext : RequestContextHandler
{

public WebProxy CurrentProxy { get; set; }
public bool blockWebRTC { get; set; } = true;
public CustomRequestContext(bool blockRTC) : base()
{
blockWebRTC = blockRTC;


}
protected override async void OnRequestContextInitialized(IRequestContext requestContext)
{
requestContext.SetPreference("credentials_enable_service", true, out _);
if (CurrentProxy != null)
{
requestContext.SetPreference("webrtc.multiple_routes_enabled", false, out _);
requestContext.SetPreference("webrtc.nonproxied_udp_enabled", false, out _);
if (blockWebRTC)
requestContext.SetPreference("webrtc.ip_handling_policy", "disable_non_proxied_udp", out _);

requestContext.SetProxy(CurrentProxy.Address.Scheme, CurrentProxy.Address.Host, CurrentProxy.Address.Port, out string error);
requestContext.SetPreference("intl.accept_languages", "en-US,en;q=0.9,en", out string error2);
}
}

protected override IResourceRequestHandler GetResourceRequestHandler(IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
{
return base.GetResourceRequestHandler(browser, frame, request, isNavigation, isDownload, requestInitiator, ref disableDefaultHandling);
}

}

public class ProxyAuthRequestHandler : CefSharp.Handler.RequestHandler
{
public NetworkCredential Credentials { get; set; }
protected override bool GetAuthCredentials(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback)
{
File.WriteAllText(@$"D:\html\{DateTime.Now.Ticks}.json", $@"{new { originUrl , isProxy , host , port, realm , scheme }}");

if (Credentials != null && isProxy == true)
{
callback.Continue(Credentials.UserName, Credentials.Password);
return true;
}
return false;
}
}
```

and calling in file ` BrowserProcessHandler.cs.cs` in the method `CreateBrowser`

```
Task IOutOfProcessClientRpc.CreateBrowser(IntPtr parentHwnd, string url, int id)
{
//Debugger.Break();

return CefThread.ExecuteOnUiThread(() =>
{
var requestContextSettings = new RequestContext(new CustomRequestContext( false) { CurrentProxy = this.Proxy });
var browser = new OutOfProcessChromiumWebBrowser(_outOfProcessServer, id, url, requestContextSettings);
browser.RequestHandler = new ProxyAuthRequestHandler() { Credentials = (NetworkCredential)Proxy.Credentials };
var windowInfo = new WindowInfo();
windowInfo.WindowName = "BrowserProcess";
windowInfo.SetAsChild(parentHwnd);
//Disable Window activation by default
//https://bitbucket.org/chromiumembedded/cef/issues/1856/branch-2526-cef-activates-browser-window
windowInfo.ExStyle |= OutOfProcessChromiumWebBrowser.WS_EX_NOACTIVATE;
browser.CreateBrowser(windowInfo);
_browsers.TryAdd(id, browser);

return true;
});
}

```
CustomRequestContext is set and the proxy is done but it promps as is show in the image for a proxy credentials the GetAuthCredentials method is never called. on non auth proxies it works all fine cause CustomRequestContext sets correctly the proxy.
Image

probably I'm missing something on my understanding of the project but I'm unable to make the Request Handler to work.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Esaminare CreateBrowser in BrowserProcessHandler.cs.cs insieme a CustomRequestContext e ProxyAuthRequestHandler per tracciare come vengono collegati il RequestHandler del browser e il proxy. Riprodurre il problema con un proxy autenticato, verificare se GetAuthCredentials viene invocato e verificare che la richiesta del proxy venga sostituita dalle credenziali fornite.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
desktop
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.