private void OnEngineHttpMessageEnd([In][MarshalAs(UnmanagedType.LPStr)] string requestHeaders, uint requestHeadersLength, [In] IntPtr requestBody, uint requestBodyLength, [In][MarshalAs(UnmanagedType.LPStr)] string responseHeaders, uint responseHeadersLength, [In] IntPtr responseBody, uint responseBodyLength, ref bool shouldBlock, NativeCustomResponseStreamWriter customBlockResponseStreamWriter) { byte[] requestBodyManaged = null; byte[] responseBodyManaged = null; if (requestBody != IntPtr.Zero) { requestBodyManaged = new byte[requestBodyLength]; Marshal.Copy(requestBody, requestBodyManaged, 0, requestBodyManaged.Length); } if (responseBody != IntPtr.Zero) { responseBodyManaged = new byte[requestBodyLength]; Marshal.Copy(responseBody, responseBodyManaged, 0, responseBodyManaged.Length); } ResponseWriter thisWriter = (byte[] responseData) => { var myNativeWriter = customBlockResponseStreamWriter; if (myNativeWriter == null) { OnWarning?.Invoke("Native response writers exhausted."); } myNativeWriter?.Invoke(responseData, (uint)responseData.Length); GC.KeepAlive(myNativeWriter); }; var shouldBlockManaged = false; HttpMessageEndCallback?.Invoke(requestHeaders, requestBodyManaged, responseHeaders, responseBodyManaged, out shouldBlockManaged, thisWriter); shouldBlock = shouldBlockManaged; }
private void OnEngineHttpMessageBegin([In][MarshalAs(UnmanagedType.LPStr)] string requestHeaders, uint requestHeadersLength, [In] IntPtr requestBody, uint requestBodyLength, [In][MarshalAs(UnmanagedType.LPStr)] string responseHeaders, uint responseHeadersLength, [In] IntPtr responseBody, uint responseBodyLength, ref uint nextAction, NativeCustomResponseStreamWriter customBlockResponseStreamWriter) { byte[] requestBodyManaged = null; byte[] responseBodyManaged = null; if (requestBody != IntPtr.Zero) { requestBodyManaged = new byte[requestBodyLength]; Marshal.Copy(requestBody, requestBodyManaged, 0, requestBodyManaged.Length); } if (responseBody != IntPtr.Zero) { responseBodyManaged = new byte[requestBodyLength]; Marshal.Copy(responseBody, responseBodyManaged, 0, responseBodyManaged.Length); } ResponseWriter thisWriter = (byte[] responseData) => { var myNativeWriter = customBlockResponseStreamWriter; if (myNativeWriter == null) { OnWarning?.Invoke("Native response writers exhausted."); } myNativeWriter?.Invoke(responseData, (uint)responseData.Length); GC.KeepAlive(myNativeWriter); }; var managedNextAction = ProxyNextAction.AllowAndIgnoreContentAndResponse; HttpMessageBeginCallback?.Invoke(requestHeaders, requestBodyManaged, responseHeaders, responseBodyManaged, out managedNextAction, thisWriter); nextAction = (uint)managedNextAction; }