Detects and partially HTTP content range requests. If the request _can_ accept ranges, sets the "Accept-Ranges" response header to "bytes". If there is no Range: request header, or if its valid is invalid, returns a status of 200, meaning that the caller should return the entire response as usual.
(contentLength uint64)
| 1726 | // It is then the _caller's_ responsibility to set it as the response status code (by calling |
| 1727 | // h.response.WriteHeader(status)), and then write the indicated subrange of the response data. |
| 1728 | func (h *handler) handleRange(contentLength uint64) (status int, start uint64, end uint64) { |
| 1729 | status = http.StatusOK |
| 1730 | if h.rq.Method == "GET" || h.rq.Method == "HEAD" { |
| 1731 | h.setHeader("Accept-Ranges", "bytes") |
| 1732 | status, start, end = parseHTTPRangeHeader(h.rq.Header.Get("Range"), contentLength) |
| 1733 | if status == http.StatusPartialContent { |
| 1734 | h.setHeader("Content-Range", fmt.Sprintf("bytes %d-%d/%d", start, end, contentLength)) |
| 1735 | h.setStatus(http.StatusPartialContent, "Partial Content") |
| 1736 | end += 1 // make end non-inclusive, as in Go slices |
| 1737 | } |
| 1738 | } |
| 1739 | return |
| 1740 | } |
| 1741 | |
| 1742 | // Given an HTTP "Range:" header value, parses it and returns the approppriate HTTP status code, |
| 1743 | // and the numeric byte range if appropriate: |
no test coverage detected