@@ -49,6 +49,17 @@ func (rc *requestContext) VerifyLink(oid string) string {
49
49
return setting .AppURL + path .Join (rc .User , rc .Repo + ".git" , "info/lfs/verify" , oid )
50
50
}
51
51
52
+ // CheckAcceptMediaType checks if the client accepts the LFS media type.
53
+ func CheckAcceptMediaType (ctx * context.Context ) {
54
+ mediaParts := strings .Split (r .Header .Get ("Accept" ), ";" )
55
+
56
+ if mediaParts [0 ] != lfs_module .MediaType {
57
+ log .Info ("Calling a LFS method without accepting the correct media type: %s" , lfs_module .MediaType )
58
+ writeStatus (ctx , http .StatusBadRequest )
59
+ return
60
+ }
61
+ }
62
+
52
63
func getAuthenticatedRepoAndMeta (ctx * context.Context , rc * requestContext , p lfs_module.Pointer , requireWrite bool ) (* models.LFSMetaObject , * models.Repository ) {
53
64
if ! p .IsValid () {
54
65
log .Info ("Attempt to access invalid LFS OID[%s] in %s/%s" , p .Oid , rc .User , rc .Repo )
@@ -157,12 +168,6 @@ func DownloadHandler(ctx *context.Context) {
157
168
158
169
// LegacyMetaHandler retrieves metadata about the object
159
170
func LegacyMetaHandler (ctx * context.Context ) {
160
- if ! isValidAccept (ctx .Req ) {
161
- log .Info ("Attempt to call without accepting the correct media type: %s" , lfs_module .MediaType )
162
- writeStatus (ctx , http .StatusBadRequest )
163
- return
164
- }
165
-
166
171
rc , p := unpack (ctx )
167
172
168
173
meta , _ := getAuthenticatedRepoAndMeta (ctx , rc , p , false )
@@ -186,12 +191,6 @@ func LegacyMetaHandler(ctx *context.Context) {
186
191
187
192
// LegacyPostHandler instructs the client how to upload data
188
193
func LegacyPostHandler (ctx * context.Context ) {
189
- if ! isValidAccept (ctx .Req ) {
190
- log .Info ("Attempt to POST without accepting the correct media type: %s" , lfs_module .MediaType )
191
- writeStatus (ctx , http .StatusBadRequest )
192
- return
193
- }
194
-
195
194
rc , p := unpack (ctx )
196
195
197
196
repository , err := models .GetRepositoryByOwnerAndName (rc .User , rc .Repo )
@@ -250,12 +249,6 @@ func LegacyPostHandler(ctx *context.Context) {
250
249
251
250
// BatchHandler provides the batch api
252
251
func BatchHandler (ctx * context.Context ) {
253
- if ! isValidAccept (ctx .Req ) {
254
- log .Info ("Attempt to BATCH without accepting the correct media type: %s" , lfs_module .MediaType )
255
- writeStatus (ctx , http .StatusBadRequest )
256
- return
257
- }
258
-
259
252
bv := unpackbatch (ctx )
260
253
261
254
var isUpload bool
@@ -383,12 +376,6 @@ func UploadHandler(ctx *context.Context) {
383
376
384
377
// VerifyHandler verify oid and its size from the content store
385
378
func VerifyHandler (ctx * context.Context ) {
386
- if ! isValidAccept (ctx .Req ) {
387
- log .Info ("Attempt to VERIFY without accepting the correct media type: %s" , lfs_module .MediaType )
388
- writeStatus (ctx , http .StatusBadRequest )
389
- return
390
- }
391
-
392
379
rc , p := unpack (ctx )
393
380
394
381
meta , _ := getAuthenticatedRepoAndMeta (ctx , rc , p , true )
@@ -449,14 +436,6 @@ func buildObjectResponse(rc *requestContext, pointer lfs_module.Pointer, downloa
449
436
return rep
450
437
}
451
438
452
- // isValidAccept provides a mux.MatcherFunc that only allows requests that contain
453
- // an Accept header with the lfs_module.MediaType
454
- func isValidAccept (r * http.Request ) bool {
455
- mediaParts := strings .Split (r .Header .Get ("Accept" ), ";" )
456
- mt := mediaParts [0 ]
457
- return mt == lfs_module .MediaType
458
- }
459
-
460
439
func unpack (ctx * context.Context ) (* requestContext , lfs_module.Pointer ) {
461
440
rc := getRequestContext (ctx )
462
441
p := lfs_module.Pointer {Oid : ctx .Params ("oid" )}
0 commit comments