Skip to content

Commit

Permalink
Forward user-agent
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com>
  • Loading branch information
pierre-emmanuelJ committed Sep 11, 2020
1 parent 49d529d commit 398ce5b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
32 changes: 29 additions & 3 deletions pkg/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ func (c *Config) stream(ctx *gin.Context, oriURL *url.URL) {
return
}

resp, err := http.Get(oriURL.String())
client := &http.Client{}

req, err := http.NewRequest("GET", oriURL.String(), nil)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
}

req.Header.Set("User-Agent", ctx.Request.UserAgent())

resp, err := client.Do(req)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
Expand All @@ -79,7 +89,15 @@ func (c *Config) hlsStream(ctx *gin.Context, oriURL *url.URL) {
},
}

resp, err := client.Get(oriURL.String())
req, err := http.NewRequest("GET", oriURL.String(), nil)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
}

req.Header.Set("User-Agent", ctx.Request.UserAgent())

resp, err := client.Do(req)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
Expand All @@ -98,7 +116,15 @@ func (c *Config) hlsStream(ctx *gin.Context, oriURL *url.URL) {
hlsChannelsRedirectURL[id] = *location
hlsChannelsRedirectURLLock.Unlock()

hlsResp, err := http.Get(location.String())
hlsReq, err := http.NewRequest("GET", location.String(), nil)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
}

hlsReq.Header.Set("User-Agent", ctx.Request.UserAgent())

hlsResp, err := client.Do(hlsReq)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/xtreamHandles.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (c *Config) xtreamPlayerAPI(ctx *gin.Context, q url.Values) {
action = q["action"][0]
}

client, err := xtreamapi.New(c.XtreamUser.String(), c.XtreamPassword.String(), c.XtreamBaseURL)
client, err := xtreamapi.New(c.XtreamUser.String(), c.XtreamPassword.String(), c.XtreamBaseURL, ctx.Request.UserAgent())
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
Expand All @@ -183,7 +183,7 @@ func (c *Config) xtreamPlayerAPI(ctx *gin.Context, q url.Values) {
}

func (c *Config) xtreamXMLTV(ctx *gin.Context) {
client, err := xtreamapi.New(c.XtreamUser.String(), c.XtreamPassword.String(), c.XtreamBaseURL)
client, err := xtreamapi.New(c.XtreamUser.String(), c.XtreamPassword.String(), c.XtreamBaseURL, ctx.Request.UserAgent())
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
Expand Down
5 changes: 3 additions & 2 deletions pkg/xtream-proxy/xtream-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package xtreamproxy

import (
"context"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -47,8 +48,8 @@ type Client struct {
}

// New new xtream client
func New(user, password, baseURL string) (*Client, error) {
cli, err := xtream.NewClient(user, password, baseURL)
func New(user, password, baseURL, userAgent string) (*Client, error) {
cli, err := xtream.NewClientWithUserAgent(context.Background(), user, password, baseURL, userAgent)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 398ce5b

Please sign in to comment.