Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webrtc, hls: use absolute paths in Location header (#3195) (#3177) #3240

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 0 additions & 22 deletions internal/protocols/httpp/location_with_trailing_slash.go

This file was deleted.

43 changes: 0 additions & 43 deletions internal/protocols/httpp/location_with_trailing_slash_test.go

This file was deleted.

44 changes: 20 additions & 24 deletions internal/protocols/webrtc/whip_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
videoTrack format.Format,
audioTrack format.Format,
) ([]*OutgoingTrack, error) {
iceServers, err := c.optionsICEServers(ctx, c.URL.String())
iceServers, err := c.optionsICEServers(ctx)

Check warning on line 34 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L34

Added line #L34 was not covered by tests
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -67,7 +67,7 @@
return nil, err
}

res, err := c.postOffer(ctx, c.URL.String(), offer)
res, err := c.postOffer(ctx, offer)

Check warning on line 70 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L70

Added line #L70 was not covered by tests
if err != nil {
c.pc.Close()
return nil, err
Expand All @@ -81,7 +81,7 @@

err = c.pc.SetAnswer(res.Answer)
if err != nil {
c.deleteSession(context.Background(), c.URL.String()) //nolint:errcheck
c.deleteSession(context.Background()) //nolint:errcheck

Check warning on line 84 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L84

Added line #L84 was not covered by tests
c.pc.Close()
return nil, err
}
Expand All @@ -93,9 +93,9 @@
for {
select {
case ca := <-c.pc.NewLocalCandidate():
err := c.patchCandidate(ctx, c.URL.String(), offer, res.ETag, ca)
err := c.patchCandidate(ctx, offer, res.ETag, ca)

Check warning on line 96 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L96

Added line #L96 was not covered by tests
if err != nil {
c.deleteSession(context.Background(), c.URL.String()) //nolint:errcheck
c.deleteSession(context.Background()) //nolint:errcheck

Check warning on line 98 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L98

Added line #L98 was not covered by tests
c.pc.Close()
return nil, err
}
Expand All @@ -106,7 +106,7 @@
break outer

case <-t.C:
c.deleteSession(context.Background(), c.URL.String()) //nolint:errcheck
c.deleteSession(context.Background()) //nolint:errcheck

Check warning on line 109 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L109

Added line #L109 was not covered by tests
c.pc.Close()
return nil, fmt.Errorf("deadline exceeded while waiting connection")
}
Expand All @@ -117,7 +117,7 @@

// Read reads tracks.
func (c *WHIPClient) Read(ctx context.Context) ([]*IncomingTrack, error) {
iceServers, err := c.optionsICEServers(ctx, c.URL.String())
iceServers, err := c.optionsICEServers(ctx)

Check warning on line 120 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L120

Added line #L120 was not covered by tests
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -147,7 +147,7 @@
return nil, err
}

res, err := c.postOffer(ctx, c.URL.String(), offer)
res, err := c.postOffer(ctx, offer)

Check warning on line 150 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L150

Added line #L150 was not covered by tests
if err != nil {
c.pc.Close()
return nil, err
Expand All @@ -162,22 +162,22 @@
var sdp sdp.SessionDescription
err = sdp.Unmarshal([]byte(res.Answer.SDP))
if err != nil {
c.deleteSession(context.Background(), c.URL.String()) //nolint:errcheck
c.deleteSession(context.Background()) //nolint:errcheck

Check warning on line 165 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L165

Added line #L165 was not covered by tests
c.pc.Close()
return nil, err
}

// check that there are at most two tracks
_, err = TrackCount(sdp.MediaDescriptions)
if err != nil {
c.deleteSession(context.Background(), c.URL.String()) //nolint:errcheck
c.deleteSession(context.Background()) //nolint:errcheck

Check warning on line 173 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L173

Added line #L173 was not covered by tests
c.pc.Close()
return nil, err
}

err = c.pc.SetAnswer(res.Answer)
if err != nil {
c.deleteSession(context.Background(), c.URL.String()) //nolint:errcheck
c.deleteSession(context.Background()) //nolint:errcheck

Check warning on line 180 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L180

Added line #L180 was not covered by tests
c.pc.Close()
return nil, err
}
Expand All @@ -189,9 +189,9 @@
for {
select {
case ca := <-c.pc.NewLocalCandidate():
err := c.patchCandidate(ctx, c.URL.String(), offer, res.ETag, ca)
err := c.patchCandidate(ctx, offer, res.ETag, ca)

Check warning on line 192 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L192

Added line #L192 was not covered by tests
if err != nil {
c.deleteSession(context.Background(), c.URL.String()) //nolint:errcheck
c.deleteSession(context.Background()) //nolint:errcheck

Check warning on line 194 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L194

Added line #L194 was not covered by tests
c.pc.Close()
return nil, err
}
Expand All @@ -202,15 +202,15 @@
break outer

case <-t.C:
c.deleteSession(context.Background(), c.URL.String()) //nolint:errcheck
c.deleteSession(context.Background()) //nolint:errcheck

Check warning on line 205 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L205

Added line #L205 was not covered by tests
c.pc.Close()
return nil, fmt.Errorf("deadline exceeded while waiting connection")
}
}

tracks, err := c.pc.GatherIncomingTracks(ctx, 0)
if err != nil {
c.deleteSession(context.Background(), c.URL.String()) //nolint:errcheck
c.deleteSession(context.Background()) //nolint:errcheck

Check warning on line 213 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L213

Added line #L213 was not covered by tests
c.pc.Close()
return nil, err
}
Expand All @@ -220,7 +220,7 @@

// Close closes the client.
func (c *WHIPClient) Close() error {
err := c.deleteSession(context.Background(), c.URL.String())
err := c.deleteSession(context.Background())

Check warning on line 223 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L223

Added line #L223 was not covered by tests
c.pc.Close()
return err
}
Expand All @@ -238,9 +238,8 @@

func (c *WHIPClient) optionsICEServers(
ctx context.Context,
ur string,
) ([]webrtc.ICEServer, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodOptions, ur, nil)
req, err := http.NewRequestWithContext(ctx, http.MethodOptions, c.URL.String(), nil)

Check warning on line 242 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L242

Added line #L242 was not covered by tests
if err != nil {
return nil, err
}
Expand All @@ -266,10 +265,9 @@

func (c *WHIPClient) postOffer(
ctx context.Context,
ur string,
offer *webrtc.SessionDescription,
) (*whipPostOfferResponse, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodPost, ur, bytes.NewReader([]byte(offer.SDP)))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.URL.String(), bytes.NewReader([]byte(offer.SDP)))

Check warning on line 270 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L270

Added line #L270 was not covered by tests
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -322,7 +320,6 @@

func (c *WHIPClient) patchCandidate(
ctx context.Context,
ur string,
offer *webrtc.SessionDescription,
etag string,
candidate *webrtc.ICECandidateInit,
Expand All @@ -332,7 +329,7 @@
return err
}

req, err := http.NewRequestWithContext(ctx, http.MethodPatch, ur, bytes.NewReader(frag))
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, c.URL.String(), bytes.NewReader(frag))

Check warning on line 332 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L332

Added line #L332 was not covered by tests
if err != nil {
return err
}
Expand All @@ -355,9 +352,8 @@

func (c *WHIPClient) deleteSession(
ctx context.Context,
ur string,
) error {
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, ur, nil)
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, c.URL.String(), nil)

Check warning on line 356 in internal/protocols/webrtc/whip_client.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/webrtc/whip_client.go#L356

Added line #L356 was not covered by tests
if err != nil {
return err
}
Expand Down
10 changes: 9 additions & 1 deletion internal/servers/hls/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
//go:embed hls.min.js
var hlsMinJS []byte

func mergePathAndQuery(path string, rawQuery string) string {
res := path
if rawQuery != "" {
res += "?" + rawQuery
}
return res

Check warning on line 37 in internal/servers/hls/http_server.go

View check run for this annotation

Codecov / codecov/patch

internal/servers/hls/http_server.go#L32-L37

Added lines #L32 - L37 were not covered by tests
}

type httpServer struct {
address string
encryption bool
Expand Down Expand Up @@ -134,7 +142,7 @@
dir, fname = pa, ""

if !strings.HasSuffix(dir, "/") {
ctx.Writer.Header().Set("Location", httpp.LocationWithTrailingSlash(ctx.Request.URL))
ctx.Writer.Header().Set("Location", mergePathAndQuery(ctx.Request.URL.Path+"/", ctx.Request.URL.RawQuery))

Check warning on line 145 in internal/servers/hls/http_server.go

View check run for this annotation

Codecov / codecov/patch

internal/servers/hls/http_server.go#L145

Added line #L145 was not covered by tests
ctx.Writer.WriteHeader(http.StatusMovedPermanently)
return
}
Expand Down