MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / handleRange

Method handleRange

rest/handler.go:1728–1740  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
1728func (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:

Callers 1

handleGetAttachmentMethod · 0.95

Calls 4

setHeaderMethod · 0.95
setStatusMethod · 0.95
parseHTTPRangeHeaderFunction · 0.85
GetMethod · 0.45

Tested by

no test coverage detected