Ai
3 Star 0 Fork 0

Gitee 极速下载/gitlab-workhorsesource

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://gitlab.com/gitlab-org/gitlab-workhorse
克隆/下载
headers.go 1.66 KB
一键复制 编辑 原始数据 按行查看 历史
package headers
import (
"net/http"
"strconv"
)
// Max number of bytes that http.DetectContentType needs to get the content type
// Fixme: Go back to 512 bytes once https://gitlab.com/gitlab-org/gitlab-workhorse/issues/208
// has been merged
const MaxDetectSize = 4096
// HTTP Headers
const (
ContentDispositionHeader = "Content-Disposition"
ContentTypeHeader = "Content-Type"
// Workhorse related headers
GitlabWorkhorseSendDataHeader = "Gitlab-Workhorse-Send-Data"
XSendFileHeader = "X-Sendfile"
XSendFileTypeHeader = "X-Sendfile-Type"
// Signal header that indicates Workhorse should detect and set the content headers
GitlabWorkhorseDetectContentTypeHeader = "Gitlab-Workhorse-Detect-Content-Type"
)
var ResponseHeaders = []string{
XSendFileHeader,
GitlabWorkhorseSendDataHeader,
GitlabWorkhorseDetectContentTypeHeader,
}
func IsDetectContentTypeHeaderPresent(rw http.ResponseWriter) bool {
header, err := strconv.ParseBool(rw.Header().Get(GitlabWorkhorseDetectContentTypeHeader))
if err != nil || !header {
return false
}
return true
}
// AnyResponseHeaderPresent checks in the ResponseWriter if there is any Response Header
func AnyResponseHeaderPresent(rw http.ResponseWriter) bool {
// If this header is not present means that we want the old behavior
if !IsDetectContentTypeHeaderPresent(rw) {
return false
}
for _, header := range ResponseHeaders {
if rw.Header().Get(header) != "" {
return true
}
}
return false
}
// RemoveResponseHeaders removes any ResponseHeader from the ResponseWriter
func RemoveResponseHeaders(rw http.ResponseWriter) {
for _, header := range ResponseHeaders {
rw.Header().Del(header)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/gitlab-workhorsesource.git
git@gitee.com:mirrors/gitlab-workhorsesource.git
mirrors
gitlab-workhorsesource
gitlab-workhorsesource
v8.8.1

搜索帮助