带有StreamContent的Web API 2 IHttpActionResult会自动启用压缩吗?

时间:2014-10-24 11:00:26

标签: azure asp.net-web-api

在下面的代码中,它将通过线路的天蓝色blob流镜像到客户端。 webapi会自动在流上启用压缩,还是需要手动将其添加到BlobResult操作结果中?

public class BlobResult : IHttpActionResult
{
    private readonly CloudBlockBlob blob;

    public BlobResult(CloudBlockBlob blob)
    {
    }

    public async Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
    {
        await blob.FetchAttributesAsync();

        var response = new HttpResponseMessage(HttpStatusCode.OK)
        {
            Content = new StreamContent(await blob.OpenReadAsync())
        };

        response.Content.Headers.LastModified = blob.Properties.LastModified;
        response.Content.Headers.ContentType = new MediaTypeHeaderValue(blob.Properties.ContentType);

        return response;
    }
}

0 个答案:

没有答案