Home > Net >  Xilium. CefGlue CefResourceHandler how to return data to the caller
Xilium. CefGlue CefResourceHandler how to return data to the caller

Time:03-02

 
The class DumpRequestResourceHandler: CefResourceHandler
{
Private static int _requestNo;

Private byte [] responseData;
Private int pos.

Protected override void GetResponseHeaders (CefResponse response, out long responseLength, out string redirectUrl)
{
The response. The Status=200;
The response. The MimeType="text/HTML";
The response. StatusText="OK, hello from handler!" ;
Var headers=new NameValueCollection (StringComparer InvariantCultureIgnoreCase);
Headers. The Add (" cache-control ", "private");
Headers. The Add (" Access - Control - Allow - Origin ", "*");
The response. SetHeaderMap (headers);
ResponseLength=responseData=https://bbs.csdn.net/topics/=null? 0: responseData. Length;
RedirectUrl=null;
}

Protected override bool Open (CefRequest request, out bool handleRequest, CefCallback callback)
{
Thread the Thread=new Thread (()=& gt;
{
Var response=new StringBuilder ();
Try
{
Var requestNo=Interlocked. Increment (ref _requestNo);
String [] para;
If (request PostData!=null)
{
Para.=HttpUtility UrlDecode (Encoding UTF8. Get string (request) PostData) GetElements () [0]. GetBytes ())). The Split (' & amp; ');
}
The else
{
Var. Pl=HttpUtility UrlDecode (request Url). The Split (' & amp; ');
Para=new string (pl. Length - 1),
For (int I=1; i {
Para [I - 1]=pl [I];
}
}
The response. Append (" Testing!!!!!! ");
}
The catch (Exception ex)
{
The response. Append (ex. Message + ex. StackTrace);
}
The finally {
ResponseData=https://bbs.csdn.net/topics/Encoding.UTF8.GetBytes (response. The ToString ());
The callback. The Continue ();
}
});
Thread. The Start ();
HandleRequest=true;
return true;
}

Protected override bool Read (IntPtr dataOut, int bytesToRead, out int bytesRead, CefResourceReadCallback callback)
{
Var dataLen null=responseData=https://bbs.csdn.net/topics/=? 0: responseData. Length;
If (bytesToRead==0 | | pos & gt;=dataLen)
{
BytesRead=0;
return false;
}
The else
{
Pos +=bytesToRead;
BytesRead=bytesToRead;
DataOut=(IntPtr) pos;
return true;
}
}

Protected override bool Skip (long bytesToSkip, out long bytesSkipped, CefResourceSkipCallback callback)
{
BytesSkipped=bytesToSkip;
return false;
}
Protected override void the Cancel ()
{
}

}

This is the version data
 
Internal static unsafe partial class libcef
{
Public const string CEF_VERSION="88.2.9 + g5c8711a + chromium - 88.0.4324.182";
Public const int CEF_VERSION_MAJOR=88;
Public const int CEF_COMMIT_NUMBER=2301;
Public const string CEF_COMMIT_HASH="5 c8711aa6017c48688dd03915062bd5f9382ee3e";

Public const int CHROME_VERSION_MAJOR=88;
Public const int CHROME_VERSION_MINOR=2;
Public const int CHROME_VERSION_BUILD=4324;
Public const int CHROME_VERSION_PATCH=182;

Public const string CEF_API_HASH_UNIVERSAL="89715 b43c948313782d2546131f510eab1975844";

Public const string CEF_API_HASH_PLATFORM_WIN="80648 a2c5a87db1581fdb994b7154ed77d74a3c5";
Public const string CEF_API_HASH_PLATFORM_MACOS="3 af393a2bf165edd934c5a59f6e6fce8a4bb579c";
Public const string CEF_API_HASH_PLATFORM_LINUX="8049 cab9a43c1d554ccdd4dd3d5e38ecebce42af";
}

This is the complete code to realize the class, I met now the question is: how to return the data to the caller,
  • Related