本文整理汇总了C#中HttpResponseHeader.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseHeader.ContainsKey方法的具体用法?C# HttpResponseHeader.ContainsKey怎么用?C# HttpResponseHeader.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponseHeader
的用法示例。
在下文中一共展示了HttpResponseHeader.ContainsKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public object Process(IHttpServer server, IHttpRequest req, HttpResponseHeader header)
{
string accept_encodings;
if (!req.Headers.TryGetValue (HttpHeaderNames.AcceptEncoding, out accept_encodings))
accept_encodings = "";
bool enableGzip = accept_encodings.Contains ("gzip");
bool enableDeflate = accept_encodings.Contains ("deflate");
if (enableDeflate) enableGzip = false;
if (enableGzip) enableDeflate = false;
object result = _app.Process (server, req, header);
if (header.Status != HttpStatusCode.OK || !(enableGzip || enableDeflate) || header.ContainsKey (HttpHeaderNames.ContentEncoding)) {
return result;
} else {
byte[] ret;
int original_size = -1;
using (MemoryStream ms = new MemoryStream ())
using (Stream strm = (enableGzip ? (Stream)new GZipStream (ms, CompressionMode.Compress) : (Stream)new DeflateStream (ms, CompressionMode.Compress))) {
if (result is string) {
byte[] raw = header.Encoding.GetBytes ((string)result);
original_size = raw.Length;
strm.Write (raw, 0, raw.Length);
} else if (result is byte[]) {
byte[] raw = (byte[])result;
original_size = raw.Length;
strm.Write (raw, 0, raw.Length);
} else {
return result;
}
strm.Flush ();
strm.Close ();
ms.Close ();
ret = ms.ToArray ();
}
if (ret.Length >= original_size) {
_logger.Trace ("Bypass compress middleware ({0} is larger than {1})", ret.Length, original_size);
return result;
}
header[HttpHeaderNames.ContentLength] = ret.Length.ToString ();
header[HttpHeaderNames.ContentEncoding] = enableGzip ? "gzip" : "deflate";
_logger.Trace ("Enable {0} compression, size is {1} to {2}",
header[HttpHeaderNames.ContentEncoding], original_size, ret.Length);
return ret;
}
}