当前位置: 首页>>代码示例>>C#>>正文


C# IHttpResponse.GetBuffer方法代码示例

本文整理汇总了C#中IHttpResponse.GetBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpResponse.GetBuffer方法的具体用法?C# IHttpResponse.GetBuffer怎么用?C# IHttpResponse.GetBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IHttpResponse的用法示例。


在下文中一共展示了IHttpResponse.GetBuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResponseHeaderAvailable

        public override void ResponseHeaderAvailable(IHttpResponse response, ISessionContext context)
        {
            ServiceLog.Logger.Verbose(() => string.Format("{0}\r\n===RESPONSE=============\r\n{1}\r\n========================\r\n", context.Id, Encoding.UTF8.GetString(response.GetBuffer())));

            context.SendClientData(response.GetBuffer());

            //// Consult the response filters to see if any are interested in the entire body.
            //// Don't build the response body unless we have to; it's expensive.
            //// If any filters can make the judgement now, before we read the body, then use their response to
            //// short-circuit the body evaluation.
            //string filterResponse;
            //if (_filter.TryEvaluateResponseFilters(response,
            //                                         context.ClientConnection.ConnectionId,
            //                                         out filterResponse))
            //{
            //    // Filter active and does not need HTTP body
            //    if (filterResponse != null)
            //    {
            //        ServiceLog.Logger.Info("{0} *** PERFORMANCE HIT *** Response filter blocking content", context.Id);

            //        // Stop listening for more data from the server. We are creating our own response.
            //        // The session will terminate once this response is sent to the client.
            //        context.ChangeState(SessionStateType.ResponseHeaderFilter);
            //        context.SendClientData(Encoding.UTF8.GetBytes(filterResponse));
            //    }
            //    else
            //    {
            //        // Normal behavior. No filter activated.
            //        context.SendClientData(response.GetBuffer());
            //    }
            //}
            //else
            //{
            //    // Prepare to receive the entire HTTP body
            //    ServiceLog.Logger.Info("{0} *** PERFORMANCE HIT *** Response filter requires entire body. Building HTTP body.", context.Id);
            //    context.ChangeState(SessionStateType.ResponseBodyFilter);
            //}
        }
开发者ID:williamoneill,项目名称:Gallatin,代码行数:38,代码来源:ConnectedState.cs

示例2: EvaluateResponseFiltersWithBody

        public byte[] EvaluateResponseFiltersWithBody( IHttpResponse args, string connectionId, byte[] body )
        {
            byte[] filteredBody = null;

            if ( body != null && body.Length > 0 )
            {
                ServiceLog.Logger.Verbose( "Evaluating body filters" );

                // The body has been re-assembled. Remove the "chunked" header.
                args.Headers.RemoveKeyValue("transfer-encoding", "chunked");

                // Decompress the body so filters don't have to repeatedly do this themselves
                body = DecompressBody(args, body);

                ServiceLog.Logger.Verbose( () => Encoding.UTF8.GetString(body));

                foreach ( Func<IHttpResponse, string, byte[], byte[]> callback in _callbackList )
                {
                    filteredBody = callback(args, connectionId, body);

                    if ( filteredBody != null )
                    {
                        break;
                    }
                }
            }

            // Update the HTTP headers by adding the content length for the new body.
            // If the body was not modified by the filters then reset this to the
            // body that was passed in, which has possibly been decompressed.
            if ( filteredBody != null )
            {
                ServiceLog.Logger.Verbose("Response body has been modified by proxy server");
                args.Headers.UpsertKeyValue( "Content-Length", filteredBody.Length.ToString() );
            }
            else
            {
                ServiceLog.Logger.Verbose("Proxy server did not modify response body");
                filteredBody = body;
            }

            byte[] header = args.GetBuffer();

            byte[] returnBuffer = new byte[header.Length + filteredBody.Length];
            Array.Copy( header, returnBuffer, header.Length );
            Array.Copy( filteredBody, 0, returnBuffer, header.Length, filteredBody.Length );

            return returnBuffer;
        }
开发者ID:williamoneill,项目名称:Gallatin,代码行数:49,代码来源:ProxyFilter.cs

示例3: ApplyResponseBodyFilter

        public byte[] ApplyResponseBodyFilter(IHttpResponse response, byte[] body, IEnumerable<Func<IHttpResponse, string, byte[], byte[]>> bodyCallbacks)
        {
            byte[] filteredBody = null;

            if (body != null && body.Length > 0)
            {
                ServiceLog.Logger.Verbose("Evaluating body filters");

                // The body has been re-assembled. Remove the "chunked" header.
                response.Headers.RemoveKeyValue("transfer-encoding", "chunked");

                // Decompress the body so filters don't have to repeatedly do this themselves
                body = DecompressBody(response, body);

                ServiceLog.Logger.Verbose(() => Encoding.UTF8.GetString(body));

                foreach (Func<IHttpResponse, string, byte[], byte[]> callback in bodyCallbacks)
                {
                    filteredBody = callback(response, _clientConnectionId, body);

                    if (filteredBody != null)
                    {
                        break;
                    }
                }
            }

            // Update the HTTP headers by adding the content length for the new body.
            // If the body was not modified by the filters then reset this to the
            // body that was passed in, which has possibly been decompressed.
            if (filteredBody != null)
            {
                _accessLog.Write(_clientConnectionId, _request, AccessLogType.AccessBlocked);

                ServiceLog.Logger.Verbose("Response body has been modified by proxy server");
                response.Headers.UpsertKeyValue("Content-Length", filteredBody.Length.ToString());
            }
            else
            {
                _accessLog.Write(_clientConnectionId, _request, AccessLogType.AccessGranted);

                ServiceLog.Logger.Verbose("Proxy server did not modify response body");
                filteredBody = body;
            }

            byte[] header = response.GetBuffer();

            byte[] returnBuffer = new byte[header.Length + filteredBody.Length];
            Array.Copy(header, returnBuffer, header.Length);
            Array.Copy(filteredBody, 0, returnBuffer, header.Length, filteredBody.Length);

            return returnBuffer;
        }
开发者ID:williamoneill,项目名称:Gallatin,代码行数:53,代码来源:HttpResponseFilter.cs


注:本文中的IHttpResponse.GetBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。