@@ -67,7 +67,8 @@ func (m *ManagerCtx) ServePlaylist(w http.ResponseWriter, r *http.Request) {
6767 defer resp .Body .Close ()
6868
6969 if resp .StatusCode < 200 && resp .StatusCode >= 300 {
70- defer resp .Body .Close ()
70+ // read all response body
71+ io .Copy (io .Discard , resp .Body )
7172
7273 m .logger .Err (err ).Int ("code" , resp .StatusCode ).Msg ("invalid HTTP response" )
7374 http .Error (w , http .StatusText (http .StatusBadGateway ), http .StatusBadGateway )
@@ -84,7 +85,7 @@ func (m *ManagerCtx) ServePlaylist(w http.ResponseWriter, r *http.Request) {
8485 var re = regexp .MustCompile (`(?m:^(https?\:\/\/[^\/]+)?\/)` )
8586 text := re .ReplaceAllString (string (buf ), m .prefix )
8687
87- cache = m .saveToCache (url , strings .NewReader (text ), playlistExpiration )
88+ cache = m .saveToCache (url , strings .NewReader (data ), time . Now (). Add ( playlistExpiration ) )
8889 }
8990
9091 w .Header ().Set ("Content-Type" , "application/vnd.apple.mpegurl" )
@@ -106,14 +107,16 @@ func (m *ManagerCtx) ServeMedia(w http.ResponseWriter, r *http.Request) {
106107 }
107108
108109 if resp .StatusCode < 200 && resp .StatusCode >= 300 {
109- defer resp .Body .Close ()
110+ // read all response body
111+ io .Copy (io .Discard , resp .Body )
112+ resp .Body .Close ()
110113
111114 m .logger .Err (err ).Int ("code" , resp .StatusCode ).Msg ("invalid HTTP response" )
112115 http .Error (w , http .StatusText (http .StatusBadGateway ), http .StatusBadGateway )
113116 return
114117 }
115118
116- cache = m .saveToCache (url , resp .Body , segmentExpiration )
119+ cache = m .saveToCache (url , resp .Body , time . Now (). Add ( segmentExpiration ) )
117120 }
118121
119122 w .Header ().Set ("Content-Type" , "video/MP2T" )
0 commit comments