public void ProcessMessage( IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, out ITransportHeaders responseHeaders, out Stream responseStream) { // If the request stream length is greater than the threshold // and message is not exempt from compression, compress the stream. if (_compressionThreshold > 0 && requestStream.Length > _compressionThreshold && !IsCompressionExempt(msg)) { // Process the message and compress it. requestStream = CompressHelper.Compress(requestStream); // Send the compression flag to the server. requestHeaders[CommonHeaders.CompressionEnabled] = true; } // Send the compression supported flag to the server. requestHeaders[CommonHeaders.CompressionSupported] = true; // Send the request to the server. _next.ProcessMessage( msg, requestHeaders, requestStream, out responseHeaders, out responseStream); // If the response has the compression flag, decompress the stream. if (responseHeaders[CommonHeaders.CompressionEnabled] != null) { // Process the message and decompress it. responseStream = CompressHelper.Decompress(responseStream); } }
public ServerProcessing ProcessMessage( IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream) { // Push this onto the sink stack sinkStack.Push(this, null); // If the request has the compression flag, decompress the stream. if (requestHeaders[CommonHeaders.CompressionEnabled] != null) { // Process the message and decompress it. requestStream = CompressHelper.Decompress(requestStream); } // Retrieve the response from the server. ServerProcessing processingResult = _next.ProcessMessage(sinkStack, requestMsg, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream); // If the response stream length is greater than the threshold, // message is not exempt from compression, and client supports compression, // compress the stream. if (processingResult == ServerProcessing.Complete && _compressionThreshold > 0 && responseStream.Length > _compressionThreshold && !IsCompressionExempt(responseMsg) && requestHeaders[CommonHeaders.CompressionSupported] != null) { // Process the message and compress it. responseStream = CompressHelper.Compress(responseStream); // Send the compression flag to the client. responseHeaders[CommonHeaders.CompressionEnabled] = true; } // Take off the stack and return the result. sinkStack.Pop(this); return(processingResult); }