github.com/zhongdalu/gf@v1.0.0/g/net/ghttp/ghttp_response_gzip.go (about) 1 // Copyright 2017 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/zhongdalu/gf. 6 // 7 8 package ghttp 9 10 // 默认的gzip压缩文件类型 11 var defaultGzipContentTypes = []string{ 12 "application/atom+xml", 13 "application/font-sfnt", 14 "application/javascript", 15 "application/json", 16 "application/ld+json", 17 "application/manifest+json", 18 "application/rdf+xml", 19 "application/rss+xml", 20 "application/schema+json", 21 "application/vnd.geo+json", 22 "application/vnd.ms-fontobject", 23 "application/x-font-ttf", 24 "application/x-javascript", 25 "application/x-web-app-manifest+json", 26 "application/xhtml+xml", 27 "application/xml", 28 "font/eot", 29 "font/opentype", 30 "image/bmp", 31 "image/svg+xml", 32 "image/vnd.microsoft.icon", 33 "image/x-icon", 34 "text/cache-manifest", 35 "text/css", 36 "text/html", 37 "text/javascript", 38 "text/plain", 39 "text/vcard", 40 "text/vnd.rim.location.xloc", 41 "text/vtt", 42 "text/x-component", 43 "text/x-cross-domain-policy", 44 "text/xml", 45 } 46 47 //// 返回内容gzip检查处理 48 //func (r *Response) handleGzip() { 49 // // 如果客户端支持gzip压缩,并且服务端设置开启gzip压缩特性,那么执行压缩 50 // encoding := r.request.Header.Get("Accept-Encoding") 51 // if encoding != "" && strings.Contains(encoding, "gzip") { 52 // mimeType := "" 53 // ext := gfile.Ext(r.request.URL.Path) 54 // if ext != "" { 55 // mimeType = strings.Split(mime.TypeByExtension(ext), ";")[0] 56 // } 57 // if mimeType == "" { 58 // contentType := r.Header().Get("Content-Type") 59 // if contentType != "" { 60 // mimeType = strings.Split(contentType, ";")[0] 61 // } 62 // } 63 // 64 // if _, ok := r.Server.gzipMimesMap[mimeType]; ok { 65 // r.SetBuffer(gcompress.Gzip(r.buffer)) 66 // r.Header().Set("Content-Length", gconv.String(len(r.buffer))) 67 // r.Header().Set("Content-Encoding", "gzip") 68 // } 69 // } 70 //}