HLS: rename path into dir

This commit is contained in:
aler9 2021-07-04 16:03:24 +02:00
parent b48f65c1a4
commit bf92496af0
2 changed files with 21 additions and 21 deletions

View File

@ -104,11 +104,11 @@ func ipEqualOrInRange(ip net.IP, ips []interface{}) bool {
// Request is an HTTP request received by an HLS server.
type Request struct {
Path string
FileName string
Req *http.Request
W http.ResponseWriter
Res chan io.Reader
Dir string
File string
Req *http.Request
W http.ResponseWriter
Res chan io.Reader
}
type trackIDPayloadPair struct {
@ -592,7 +592,7 @@ func (c *Converter) runRequestHandler(terminate chan struct{}, done chan struct{
}
switch {
case req.FileName == "stream.m3u8":
case req.File == "stream.m3u8":
func() {
c.tsMutex.RLock()
defer c.tsMutex.RUnlock()
@ -633,8 +633,8 @@ func (c *Converter) runRequestHandler(terminate chan struct{}, done chan struct{
req.Res <- bytes.NewReader([]byte(cnt))
}()
case strings.HasSuffix(req.FileName, ".ts"):
base := strings.TrimSuffix(req.FileName, ".ts")
case strings.HasSuffix(req.File, ".ts"):
base := strings.TrimSuffix(req.File, ".ts")
c.tsMutex.RLock()
f, ok := c.tsByName[base]
@ -649,7 +649,7 @@ func (c *Converter) runRequestHandler(terminate chan struct{}, done chan struct{
req.W.Header().Set("Content-Type", `video/MP2T`)
req.Res <- f.buf.NewReader()
case req.FileName == "":
case req.File == "":
req.Res <- bytes.NewReader([]byte(index))
default:

View File

@ -106,7 +106,7 @@ outer:
for {
select {
case req := <-s.request:
c, ok := s.converters[req.Path]
c, ok := s.converters[req.Dir]
if !ok {
c = hlsconverter.New(
s.ctx,
@ -115,10 +115,10 @@ outer:
s.readBufferCount,
&s.wg,
s.stats,
req.Path,
req.Dir,
s.pathMan,
s)
s.converters[req.Path] = c
s.converters[req.Dir] = c
}
c.OnRequest(req)
@ -164,28 +164,28 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
pa, fname := func() (string, string) {
dir, fname := func() (string, string) {
if strings.HasSuffix(pa, ".ts") || strings.HasSuffix(pa, ".m3u8") {
return path.Dir(pa), path.Base(pa)
}
return pa, ""
}()
if fname == "" && !strings.HasSuffix(pa, "/") {
w.Header().Add("Location", "/"+pa+"/")
if fname == "" && !strings.HasSuffix(dir, "/") {
w.Header().Add("Location", "/"+dir+"/")
w.WriteHeader(http.StatusMovedPermanently)
return
}
pa = strings.TrimSuffix(pa, "/")
dir = strings.TrimSuffix(dir, "/")
cres := make(chan io.Reader)
hreq := hlsconverter.Request{
Path: pa,
FileName: fname,
Req: r,
W: w,
Res: cres,
Dir: dir,
File: fname,
Req: r,
W: w,
Res: cres,
}
select {