private static ICompressor CreateCompressor(WebCompressionKind compressionKind) { switch (compressionKind) { case WebCompressionKind.GZip: // NOTE: SharpGZipCompressor() 가 압축률이 더 좋다!!! (CPU 리소스는 더 먹는다) 단 암호화등과 같이 쓰면 예외가 발생한다. // return new SharpGZipCompressor(); return(new GZipCompressor()); case WebCompressionKind.Deflate: return(new DeflateCompressor()); default: // NOTE: DummyCompressor는 압축도 하지 않고, 복사도 하지 않고, 인스턴스 메모리 참조값을 그대로 전달해준다. return(new DummyCompressor()); } }
/// <summary> /// 캐시에 저장된 정보가 있다면, 그 정보를 Client에게 보냅니다. /// </summary> private static bool WriteFromCache(HttpContext context, string cacheKey, TimeSpan cacheDuration, WebCompressionKind compressionKind) { var cacheItem = context.Cache[cacheKey] as CacheItem; if (cacheItem == null || cacheItem.Data == null || cacheItem.Data.Length == 0) { return(false); } if (IsDebugEnabled) { log.Debug("캐시에 정적 파일 데이타가 저장되어 있습니다. 캐시 정보를 이용하여 응답합니다. cackeKey=[{0}]", cacheKey); } WriteBytes(context, cacheItem, cacheDuration, compressionKind); return(true); }
private static void SetResponseHeaders(HttpResponse response, CacheItem item, TimeSpan cacheDuration, WebCompressionKind compressionKind) { response.ShouldNotBeNull("response"); response.AppendHeader("Content-Length", item.Data.Length.ToString()); response.ContentType = item.ContentType; if (item.IsCompressed) { response.AppendHeader("Content-Encoding", compressionKind.ToString().ToLower()); } var cache = response.Cache; // NOTE : HTTPS 에서도 동작하기 위해 cache.SetRevalidation(HttpCacheRevalidation.AllCaches); cache.SetCacheability(HttpCacheability.Public); // Cache Expiration 설정 cache.SetExpires(DateTime.Now.ToUniversalTime().Add(cacheDuration)); cache.SetMaxAge(cacheDuration); cache.SetAllowResponseInBrowserHistory(true); }
/// <summary> /// 요청 파일의 정보를 응답 스트림에 씁니다. /// </summary> private static void WriteBytes(HttpContext context, CacheItem item, TimeSpan cacheDuration, WebCompressionKind compressionKind) { if (item == null || item.Data == null || item.Data.Length == 0) { return; } if (IsDebugEnabled) { log.Debug("요청 파일을 응답스트림에 씁니다... isCompressed=[{0}], contentType=[{1}], cacheDuration=[{2}]", item.IsCompressed, item.ContentType, cacheDuration); } HttpResponse response = context.Response; if (response.IsClientConnected == false) { return; } response.Clear(); SetResponseHeaders(response, item, cacheDuration, compressionKind); response.OutputStream.Write(item.Data, 0, item.Data.Length); response.Flush(); }
private static void SetResponseHeaders(HttpResponse response, CacheItem item, TimeSpan cacheDuration, WebCompressionKind compressionKind) { response.ShouldNotBeNull("response"); response.AppendHeader("Content-Length", item.Data.Length.ToString()); response.ContentType = item.ContentType; if(item.IsCompressed) response.AppendHeader("Content-Encoding", compressionKind.ToString().ToLower()); var cache = response.Cache; // NOTE : HTTPS 에서도 동작하기 위해 cache.SetRevalidation(HttpCacheRevalidation.AllCaches); cache.SetCacheability(HttpCacheability.Public); // Cache Expiration 설정 cache.SetExpires(DateTime.Now.ToUniversalTime().Add(cacheDuration)); cache.SetMaxAge(cacheDuration); cache.SetAllowResponseInBrowserHistory(true); }
/// <summary> /// 요청 파일의 정보를 응답 스트림에 씁니다. /// </summary> private static void WriteBytes(HttpContext context, CacheItem item, TimeSpan cacheDuration, WebCompressionKind compressionKind) { if(item == null || item.Data == null || item.Data.Length == 0) return; if(IsDebugEnabled) log.Debug("요청 파일을 응답스트림에 씁니다... isCompressed=[{0}], contentType=[{1}], cacheDuration=[{2}]", item.IsCompressed, item.ContentType, cacheDuration); HttpResponse response = context.Response; if(response.IsClientConnected == false) return; response.Clear(); SetResponseHeaders(response, item, cacheDuration, compressionKind); response.OutputStream.Write(item.Data, 0, item.Data.Length); response.Flush(); }
/// <summary> /// 캐시에 저장된 정보가 있다면, 그 정보를 Client에게 보냅니다. /// </summary> private static bool WriteFromCache(HttpContext context, string cacheKey, TimeSpan cacheDuration, WebCompressionKind compressionKind) { var cacheItem = context.Cache[cacheKey] as CacheItem; if(cacheItem == null || cacheItem.Data == null || cacheItem.Data.Length == 0) return false; if(IsDebugEnabled) log.Debug("캐시에 정적 파일 데이타가 저장되어 있습니다. 캐시 정보를 이용하여 응답합니다. cackeKey=[{0}]", cacheKey); WriteBytes(context, cacheItem, cacheDuration, compressionKind); return true; }
private static ICompressor CreateCompressor(WebCompressionKind compressionKind) { switch(compressionKind) { case WebCompressionKind.GZip: // NOTE: SharpGZipCompressor() 가 압축률이 더 좋다!!! (CPU 리소스는 더 먹는다) 단 암호화등과 같이 쓰면 예외가 발생한다. // return new SharpGZipCompressor(); return new GZipCompressor(); case WebCompressionKind.Deflate: return new DeflateCompressor(); default: // NOTE: DummyCompressor는 압축도 하지 않고, 복사도 하지 않고, 인스턴스 메모리 참조값을 그대로 전달해준다. return new DummyCompressor(); } }