Ai
2 Star 16 Fork 8

Zoker/go-git-protocols

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
smart-utils.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
Zoker 提交于 2020-12-26 16:29 +08:00 . add ssh server and optimize codes
// TODO: check user agent only contains *git* can access info/refs|git-upload-pack|git-receive-pack
// TODO: git protocol version 2 support
// TODO: gzip support
package main
import (
"fmt"
"net/http"
)
func operationIsForbidden(w *http.ResponseWriter, service string) (b bool) {
if service != "git-upload-pack" && service != "git-receive-pack" {
statusCodeWithMessage(w, 403, "Operation not permitted")
return true
}
return false
}
func statusCodeWithMessage(w *http.ResponseWriter, code int, message string) {
(*w).WriteHeader(code)
_, _ = (*w).Write([]byte(message))
}
func handleRefsHeader(w *http.ResponseWriter, service string) {
cType := fmt.Sprintf("application/x-%s-advertisement", service)
(*w).Header().Add("Content-Type", cType)
(*w).Header().Set("Expires", "Fri, 01 Jan 1980 00:00:00 GMT")
(*w).Header().Set("Pragma", "no-cache")
(*w).Header().Set("Cache-Control", "no-cache, max-age=0, must-revalidate")
}
func handlePackHeader(w *http.ResponseWriter, service string) {
(*w).Header().Set("Content-Type", fmt.Sprintf("application/x-%s-result", service))
(*w).Header().Set("Connection", "Keep-Alive")
(*w).Header().Set("Transfer-Encoding", "chunked")
(*w).Header().Set("X-Content-Type-Options", "nosniff")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kesin/go-git-protocols.git
git@gitee.com:kesin/go-git-protocols.git
kesin
go-git-protocols
go-git-protocols
master

搜索帮助