MCPcopy Index your code
hub / github.com/Threadfin/Threadfin / Stream

Function Stream

src/webserver.go:296–395  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

294}
295
296func Stream(w http.ResponseWriter, r *http.Request) {
297 var path = strings.Replace(r.RequestURI, "/stream/", "", 1)
298 streamInfo, err := getStreamInfo(path)
299 if err != nil {
300 ShowError(err, 1203)
301 httpStatusError(w, r, 404)
302 return
303 }
304
305 if Settings.UDPxy != "" && strings.HasPrefix(streamInfo.URL, "udp://@") {
306 streamInfo.URL = fmt.Sprintf("http://%s/udp/%s/", Settings.UDPxy, strings.TrimPrefix(streamInfo.URL, "udp://@"))
307 }
308
309 systemMutex.Lock()
310 forceHttps := Settings.ForceHttps
311 systemMutex.Unlock()
312
313 if forceHttps {
314 u, err := url.Parse(streamInfo.URL)
315 if err == nil {
316 u.Scheme = "https"
317 hostSplit := strings.Split(u.Host, ":")
318 if len(hostSplit) > 0 {
319 u.Host = hostSplit[0]
320 }
321 streamInfo.URL = fmt.Sprintf("https://%s:%d%s?%s", u.Host, Settings.HttpsPort, u.Path, u.RawQuery)
322 }
323 }
324
325 if r.Method == "HEAD" {
326 client := &http.Client{}
327 req, err := http.NewRequest("HEAD", streamInfo.URL, nil)
328 if err != nil {
329 ShowError(err, 1501)
330 httpStatusError(w, r, 405)
331 return
332 }
333 resp, err := client.Do(req)
334 if err != nil {
335 ShowError(err, 1502)
336 httpStatusError(w, r, 405)
337 return
338 }
339 defer resp.Body.Close()
340
341 for key, values := range resp.Header {
342 for _, value := range values {
343 w.Header().Add(key, value)
344 }
345 }
346 return
347 }
348
349 var playListBuffer string
350 systemMutex.Lock()
351 playListInterface := Settings.Files.M3U[streamInfo.PlaylistID]
352 if playListInterface == nil {
353 playListInterface = Settings.Files.HDHR[streamInfo.PlaylistID]

Callers

nothing calls this directly

Calls 5

getStreamInfoFunction · 0.85
ShowErrorFunction · 0.85
httpStatusErrorFunction · 0.85
showInfoFunction · 0.85
bufferingStreamFunction · 0.85

Tested by

no test coverage detected