OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // HTTP file system request handler | 5 // HTTP file system request handler |
6 | 6 |
7 package http | 7 package http |
8 | 8 |
9 import ( | 9 import ( |
10 "fmt" | 10 "fmt" |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 // parseRange parses a Range header string as per RFC 2616. | 252 // parseRange parses a Range header string as per RFC 2616. |
253 func parseRange(s string, size int64) ([]httpRange, os.Error) { | 253 func parseRange(s string, size int64) ([]httpRange, os.Error) { |
254 if s == "" { | 254 if s == "" { |
255 return nil, nil // header not present | 255 return nil, nil // header not present |
256 } | 256 } |
257 const b = "bytes=" | 257 const b = "bytes=" |
258 if !strings.HasPrefix(s, b) { | 258 if !strings.HasPrefix(s, b) { |
259 return nil, os.NewError("invalid range") | 259 return nil, os.NewError("invalid range") |
260 } | 260 } |
261 var ranges []httpRange | 261 var ranges []httpRange |
262 » for _, ra := range strings.Split(s[len(b):], ",", -1) { | 262 » for _, ra := range strings.Split(s[len(b):], ",") { |
263 i := strings.Index(ra, "-") | 263 i := strings.Index(ra, "-") |
264 if i < 0 { | 264 if i < 0 { |
265 return nil, os.NewError("invalid range") | 265 return nil, os.NewError("invalid range") |
266 } | 266 } |
267 start, end := ra[:i], ra[i+1:] | 267 start, end := ra[:i], ra[i+1:] |
268 var r httpRange | 268 var r httpRange |
269 if start == "" { | 269 if start == "" { |
270 // If no start is specified, end specifies the | 270 // If no start is specified, end specifies the |
271 // range start relative to the end of the file. | 271 // range start relative to the end of the file. |
272 i, err := strconv.Atoi64(end) | 272 i, err := strconv.Atoi64(end) |
(...skipping 22 matching lines...) Expand all Loading... |
295 if i >= size { | 295 if i >= size { |
296 i = size - 1 | 296 i = size - 1 |
297 } | 297 } |
298 r.length = i - r.start + 1 | 298 r.length = i - r.start + 1 |
299 } | 299 } |
300 } | 300 } |
301 ranges = append(ranges, r) | 301 ranges = append(ranges, r) |
302 } | 302 } |
303 return ranges, nil | 303 return ranges, nil |
304 } | 304 } |
OLD | NEW |