Skip to content

Commit

Permalink
m3u8: handle content-type case insensitively
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinB committed Sep 9, 2024
1 parent 91c4b85 commit 21847ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 2 additions & 3 deletions internal/pkg/crawl/extractor/m3u8.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package extractor
import (
"net/http"
"net/url"
"strings"

"github.com/grafov/m3u8"
)

func IsM3U8(resp *http.Response) bool {
return strings.Contains(resp.Header.Get("Content-Type"), "application/vnd.apple.mpegurl") ||
strings.Contains(resp.Header.Get("Content-Type"), "application/x-mpegURL")
return isContentType(resp.Header.Get("Content-Type"), "application/vnd.apple.mpegurl") ||
isContentType(resp.Header.Get("Content-Type"), "application/x-mpegURL")
}

func M3U8(resp *http.Response) (URLs []*url.URL, err error) {
Expand Down
9 changes: 9 additions & 0 deletions internal/pkg/crawl/extractor/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ package extractor
import (
"net/url"
"sort"
"strings"
)

func isContentType(header, targetContentType string) bool {
// Lowercase the header and target content type for case-insensitive comparison
header = strings.ToLower(header)
targetContentType = strings.ToLower(targetContentType)

return strings.Contains(header, targetContentType)
}

// compareURLs compares two slices of *url.URL
func compareURLs(a, b []*url.URL) bool {
if len(a) != len(b) {
Expand Down

0 comments on commit 21847ce

Please sign in to comment.