Skip to content

Commit 4ec36da

Browse files
authored
优化github上游链接404的处理
1 parent 83a1211 commit 4ec36da

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
22
.vscode
33
.DS_Store
4-
hubproxy*
4+
hubproxy*
5+
!hubproxy.service

src/handlers/github.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ func proxyGitHubWithRedirect(c *gin.Context, u string, redirectCount int) {
122122
}
123123
}()
124124

125+
// 如果Github上游404,则返回错误信息
126+
if resp.StatusCode == http.StatusNotFound {
127+
c.String(http.StatusForbidden, "无效的GitHub地址")
128+
return
129+
}
130+
125131
// 检查文件大小限制
126132
cfg := config.GetConfig()
127133
if contentLength := resp.Header.Get("Content-Length"); contentLength != "" {

0 commit comments

Comments
 (0)