@@ -175,6 +175,11 @@ func getContentHandler(ctx *context.Context) {
175
175
statusCode = 206
176
176
fromByte , _ = strconv .ParseInt (match [1 ], 10 , 32 )
177
177
178
+ if fromByte >= meta .Size {
179
+ writeStatus (ctx , http .StatusRequestedRangeNotSatisfiable )
180
+ return
181
+ }
182
+
178
183
if match [2 ] != "" {
179
184
_toByte , _ := strconv .ParseInt (match [2 ], 10 , 32 )
180
185
if _toByte >= fromByte && _toByte < toByte {
@@ -188,18 +193,24 @@ func getContentHandler(ctx *context.Context) {
188
193
}
189
194
190
195
contentStore := & ContentStore {ObjectStorage : storage .LFS }
191
- content , err := contentStore .Get (meta , fromByte )
196
+ content , err := contentStore .Get (meta )
192
197
if err != nil {
193
- if IsErrRangeNotSatisfiable (err ) {
194
- writeStatus (ctx , http .StatusRequestedRangeNotSatisfiable )
195
- } else {
196
- // Errors are logged in contentStore.Get
197
- writeStatus (ctx , 404 )
198
- }
198
+ // Errors are logged in contentStore.Get
199
+ writeStatus (ctx , http .StatusNotFound )
199
200
return
200
201
}
201
202
defer content .Close ()
202
203
204
+ if fromByte > 0 {
205
+ _ , err = content .Seek (fromByte , io .SeekStart )
206
+ if err != nil {
207
+ log .Error ("Whilst trying to read LFS OID[%s]: Unable to seek to %d Error: %v" , meta .Oid , fromByte , err )
208
+
209
+ writeStatus (ctx , http .StatusInternalServerError )
210
+ return
211
+ }
212
+ }
213
+
203
214
contentLength := toByte + 1 - fromByte
204
215
ctx .Resp .Header ().Set ("Content-Length" , strconv .FormatInt (contentLength , 10 ))
205
216
ctx .Resp .Header ().Set ("Content-Type" , "application/octet-stream" )
0 commit comments