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

Specify Content-Type for BlockBlob upload #3119

Merged
merged 8 commits into from Feb 5, 2024
Merged

Conversation

bethanyj28
Copy link
Contributor

The default content type for BlockBlob uploads is application/octet-stream, which signals to many browsers that they should download the content. This adds the content type of text/plain to hint that the browser should open the content in a new tab.

Closes https://github.com/github/actions-results-team/issues/2137

@bethanyj28 bethanyj28 marked this pull request as ready for review January 30, 2024 21:56
@bethanyj28 bethanyj28 requested a review from a team as a code owner January 30, 2024 21:56
@@ -234,6 +234,7 @@ private async Task UploadBlockFileAsync(string url, string blobStorageType, File
if (blobStorageType == BlobStorageTypes.AzureBlobStorage)
{
request.Content.Headers.Add(Constants.AzureBlobTypeHeader, Constants.AzureBlockBlob);
request.Content.Headers.Add("Content-Type", "text/plain");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to update the SDK path? Or that's handled automatically for us? In that case, once we rollout the SDK change, does this become a none issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to the sdk case, thank you!

try
{
await blobClient.UploadAsync(file, cancellationToken);
await blobClient.UploadAsync(file, uploadOptions, cancellationToken);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need to check what is the default option is and merge with it instead of just overwrite it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great call-out - this was overwriting the headers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not quite sure i follow your new change.

my initial comment is basically try to make sure the SDK don't have any special initialized BlobUploadOptions.

Based on the source code, maybe this is what you want?

Not sure... we can chat more...

await blobClient.UploadAsync(file, new BlobUploadOptions()
                    {
                        HttpHeaders = new BlobHttpHeaders
                        {
                            ContentType = "text/plain"
                        },
                        Conditions = new BlobRequestConditions
                        {
                            IfNoneMatch = new ETag("*")
                        }
                    }, cancellationToken);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! That makes sense to me. I was thinking specifically around the HTTP headers but I do recall seeing that in the source code of the SDK when I looked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found this issue which was helpful for wrapping my head around the options: Azure/azure-sdk-for-net#9823. Thanks for calling it out!

@bethanyj28 bethanyj28 changed the title Add Content-Type to BlockBlob upload Specify Content-Type for BlockBlob upload Jan 31, 2024
@jtamsut
Copy link
Contributor

jtamsut commented Feb 1, 2024

@bethanyj28 How are we handling blob downloads that actually should have a content type of application/octet-stream? For example, we want this for downloading raw logs.

Comment on lines 219 to 242
if (extension == ".txt")
{
uploadOptions.HttpHeaders.ContentType = "text/plain";
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bethanyj28 How are we handling blob downloads that actually should have a content type of application/octet-stream? For example, we want this for downloading raw logs.

@jtamsut this is the way we chatted about earlier, let me know if you have something else in mind.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I missed this. Okay this looks good to me!

IfMatch = new ETag("*")
};
string extension = System.IO.Path.GetExtension(file.Name);
if (extension == ".txt")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this check required, since we don't have this in the non-SDK version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to support #3114 since those should be of type application/octet-stream. I didn't add it to the non-sdk version since that should be rolled out by the time the diagnostic change is out, but happy to add to both if I misunderstood! CC @yacaovsnc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not quite sure whether we use .txt in the runner, ex: are those log file ends up with .txt?

Copy link
Contributor Author

@bethanyj28 bethanyj28 Feb 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Our log files our .txt (that's the job-logs.txt). The diagnostic logs are .zip.

Also have validated the change that it does set the content-type correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chatted offline and updated to not use the runner file extension, but the blob url instead!

{
IfNoneMatch = new ETag("*")
};
if (url.Contains(".txt")) // check if blob path is .txt file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to let the caller to decide what content type to use?
Ex:

private async Task UploadBlockFileAsync(string url, string blobStorageType, FileStream file, bool plainTextContent, CancellationToken cancellationToken)

TingluoHuang
TingluoHuang previously approved these changes Feb 2, 2024
@TingluoHuang TingluoHuang enabled auto-merge (squash) February 5, 2024 18:15
@TingluoHuang TingluoHuang merged commit bf0e766 into actions:main Feb 5, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants