Documentation ¶
Index ¶
- func CopyN(dst io.Writer, src io.Reader, n int64) (written int64, err error)
- func Error(w http.ResponseWriter, error string, code int)
- func PlayURI(uri string, w http.ResponseWriter, req *http.Request) error
- func ServeContent(w http.ResponseWriter, req *http.Request, name string, modtime time.Time, ...)
- type Metrics
- type Player
- type PlayerService
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyN ¶
CopyN copies n bytes (or until an error) from src to dst. It returns the number of bytes copied and the earliest error encountered while copying. On return, written == n if and only if err == nil.
If dst implements the ReaderFrom interface, the copy is implemented using it.
func Error ¶
func Error(w http.ResponseWriter, error string, code int)
Error replies to the request with the specified error message and HTTP code. It does not otherwise end the request; the caller should ensure no further writes are done to w. The error message should be plain text.
func PlayURI ¶
PlayURI downloads and streams LBRY video content located at uri and delimited by rangeHeader (use rangeHeader := request.Header.Get("Range")). Streaming works like this: 1. Resolve stream hash through lbrynet daemon (see resolve) 2. Retrieve stream details (list of blob hashes and lengths, etc) by the SD hash from the reflector (see fetchData) 3. Implement io.ReadSeeker interface for http.ServeContent: - Seek simply implements io.Seeker - Read calculates boundaries and finds blobs that contain the requested stream range, then calls streamBlobs, which sequentially downloads and decrypts requested blobs
func ServeContent ¶
func ServeContent(w http.ResponseWriter, req *http.Request, name string, modtime time.Time, content io.ReadSeeker)
ServeContent replies to the request using the content in the provided ReadSeeker. The main benefit of ServeContent over io.Copy is that it handles Range requests properly, sets the MIME type, and handles If-Match, If-Unmodified-Since, If-None-Match, If-Modified-Since, and If-Range requests.
If the response's Content-Type header is not set, ServeContent first tries to deduce the type from name's file extension and, if that fails, falls back to reading the first block of the content and passing it to DetectContentType. The name is otherwise unused; in particular it can be empty and is never sent in the response.
If modtime is not the zero time or Unix epoch, ServeContent includes it in a Last-Modified header in the response. If the request includes an If-Modified-Since header, ServeContent uses modtime to decide whether the content needs to be sent at all.
The content's Seek method must work: ServeContent uses a seek to the end of the content to determine its size.
If the caller has set w's ETag header formatted per RFC 7232, section 2.3, ServeContent uses it to handle requests using If-Match, If-None-Match, or If-Range.
Note that *os.File implements the io.ReadSeeker interface.
Types ¶
type Player ¶ added in v0.7.0
type Player struct { URI string // contains filtered or unexported fields }
type PlayerService ¶ added in v0.7.0
type PlayerService struct {
Metrics *Metrics
}
func (*PlayerService) NewPlayer ¶ added in v0.7.0
func (ps *PlayerService) NewPlayer(uri string) *Player