Skip to content

Commit

Permalink
Fix playback service doesn't work with azure CDN with media optimization
Browse files Browse the repository at this point in the history
feature enabled.

For azure CDN with media optimization enabled, if the media file is
missing, the CDN will request a very big range. In the original
implementation, playback service doesn't honor the real content length
instead, it will return the request range. This incorrect behavior will
make the cdn return network protocol error.
  • Loading branch information
xieyubo committed Oct 11, 2023
1 parent e7a70b9 commit 39f80cf
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions tools/PlaybackService/src/Controllers/PlaybackController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,21 +425,20 @@ private async Task GetOtherFilesAsync(BlobClient blob, long contentLength)
throw new Exception($"Can't download the blob {blob.Uri}");
}

// Write the response.
if (range != null)
{
var readedLength = range.Value.Length ?? contentLength - range.Value.Offset;
Response.ContentLength = readedLength;
// Copy the http status code and response headers.
var blobServerResponse = blobStreamResponse.GetRawResponse();
Response.StatusCode = blobServerResponse.Status;

var contentRange = $"{range.Value.Offset}-{readedLength + range.Value.Offset - 1}/{contentLength}";
logger.LogDebug($"Add header Content-Range: {contentRange}");
Response.Headers.Add("Content-Range", contentRange);
}
else
// For security, we only expose the following headers:
foreach (var allowHeader in new[] { "Content-Length", "Content-Type", "Date", "Accept-Ranges", "Content-MD5", "ETag", "Last-Modified" })
{
Response.ContentLength = contentLength;
if (blobServerResponse.Headers.TryGetValue(allowHeader, out var header))
{
Response.Headers.TryAdd(allowHeader, header);
}
}

// Copy the body.
await blobStreamResponse.Value.Content.CopyToAsync(Response.Body).ConfigureAwait(false);

// All done.
Expand Down

0 comments on commit 39f80cf

Please sign in to comment.