Skip to content

Commit c51ac32

Browse files
committed
Let router decide if LFS is enabled.
1 parent 7d0e8d8 commit c51ac32

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

routers/routes/web.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,13 @@ func RegisterRoutes(m *web.Route) {
331331
}
332332
}
333333

334+
lfsServerEnabled := func(ctx *context.Context) {
335+
if !setting.LFS.StartServer {
336+
ctx.Error(http.StatusForbidden)
337+
return
338+
}
339+
}
340+
334341
// FIXME: not all routes need go through same middleware.
335342
// Especially some AJAX requests, we can reduce middleware number to improve performance.
336343
// Routers.
@@ -1108,7 +1115,7 @@ func RegisterRoutes(m *web.Route) {
11081115
m.Any("/*", func(ctx *context.Context) {
11091116
ctx.NotFound("", nil)
11101117
})
1111-
}, ignSignInAndCsrf)
1118+
}, ignSignInAndCsrf, lfsServerEnabled)
11121119

11131120
m.Group("", func() {
11141121
m.Post("/git-upload-pack", repo.ServiceUploadPack)

services/lfs/server.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ func (rc *requestContext) VerifyLink(oid string) string {
5151

5252
// ObjectOidHandler is the main request routing entry point into LFS server functions
5353
func ObjectOidHandler(ctx *context.Context) {
54-
if !setting.LFS.StartServer {
55-
log.Debug("Attempt to access LFS server but LFS server is disabled")
56-
writeStatus(ctx, http.StatusNotFound)
57-
return
58-
}
59-
6054
if ctx.Req.Method == "GET" || ctx.Req.Method == "HEAD" {
6155
if isValidAccept(ctx.Req) {
6256
getMetaHandler(ctx)
@@ -205,12 +199,6 @@ func getMetaHandler(ctx *context.Context) {
205199

206200
// PostHandler instructs the client how to upload data
207201
func PostHandler(ctx *context.Context) {
208-
if !setting.LFS.StartServer {
209-
log.Debug("Attempt to access LFS server but LFS server is disabled")
210-
writeStatus(ctx, http.StatusNotFound)
211-
return
212-
}
213-
214202
if !isValidAccept(ctx.Req) {
215203
log.Info("Attempt to POST without accepting the correct media type: %s", lfs_module.MediaType)
216204
writeStatus(ctx, http.StatusBadRequest)
@@ -275,12 +263,6 @@ func PostHandler(ctx *context.Context) {
275263

276264
// BatchHandler provides the batch api
277265
func BatchHandler(ctx *context.Context) {
278-
if !setting.LFS.StartServer {
279-
log.Debug("Attempt to access LFS server but LFS server is disabled")
280-
writeStatus(ctx, http.StatusNotFound)
281-
return
282-
}
283-
284266
if !isValidAccept(ctx.Req) {
285267
log.Info("Attempt to BATCH without accepting the correct media type: %s", lfs_module.MediaType)
286268
writeStatus(ctx, http.StatusBadRequest)
@@ -418,12 +400,6 @@ func PutHandler(ctx *context.Context) {
418400

419401
// VerifyHandler verify oid and its size from the content store
420402
func VerifyHandler(ctx *context.Context) {
421-
if !setting.LFS.StartServer {
422-
log.Debug("Attempt to access LFS server but LFS server is disabled")
423-
writeStatus(ctx, http.StatusNotFound)
424-
return
425-
}
426-
427403
if !isValidAccept(ctx.Req) {
428404
log.Info("Attempt to VERIFY without accepting the correct media type: %s", lfs_module.MediaType)
429405
writeStatus(ctx, http.StatusBadRequest)

0 commit comments

Comments
 (0)