octokit / octokit.net

A GitHub API client library for .NET
https://octokitnet.readthedocs.io/en/latest/
MIT License
2.62k stars 1.07k forks source link

[BUG]: Download Artifact - Content Stores Differing Content-Types Cause Errors #2898

Closed jack0x539 closed 1 month ago

jack0x539 commented 1 month ago

What happened?

Afternoon!

When calling ActionsArtifactClient.DownloadArtifact, the download is often, or always, redirected to another server that holds the actual artifact.

In my experience, if the artifact happens to sit on https://pipelinesghubeus10.actions.githubusercontent.com, then the Content-Type returned is application/zip and all is well, but if the artifact happens to reside on https://productionresultssa10.blob.core.windows.net, then the Content-Type is zip and it all starts to go wrong.

There's a check in HttpClientAdapter.BuildResponse for the content type, which fails, then the response is read as a string, not a stream, and Connection.GetRawStream attempts to cast the string as a stream, understandably gets null, and returns null to the caller.

Easy to fix badly; perhaps harder to fix well.

Versions

Octokit 10.0.0

Relevant log output

No response

Code of Conduct

thomhurst commented 1 month ago

I think this is happening to me as I'm getting a null stream back sometimes.

Is that not an issue with blob storage though? zip isn't a valid MIME type is it?

jack0x539 commented 1 month ago

I think this is happening to me as I'm getting a null stream back sometimes.

Is that not an issue with blob storage though? zip isn't a valid MIME type is it?

I agree, it's not a valid MIME type, but I'm assuming that those storage servers are way out of the remit of this repository, so there's not a lot that can be done about it from that side.

On this side, however, we could relax the restriction on MIMEs, or we could add a special case for zip, allowing it to be treated as if it was application/zip ?

thomhurst commented 1 month ago

I think this is happening to me as I'm getting a null stream back sometimes. Is that not an issue with blob storage though? zip isn't a valid MIME type is it?

I agree, it's not a valid MIME type, but I'm assuming that those storage servers are way out of the remit of this repository, so there's not a lot that can be done about it from that side.

On this side, however, we could relax the restriction on MIMEs, or we could add a special case for zip, allowing it to be treated as if it was application/zip ?

Yeah agreed. Adding zip would be easy, I don't see any downside to it. Currently my pipelines are broken because of this issue.

But it's up to the maintainers. Hoping resolution doesn't take ages.

thomhurst commented 1 month ago

Sorry I need to re-open this - The content type is flowing through as null even though it's there:

It's on the headers object: image

But then the ContentType property to easily access it returns null: image

thomhurst commented 1 month ago

I'm guessing because it's not a "Standard" format that it doesn't parse it

jack0x539 commented 1 month ago

Yeah, sorry I was going to reopen as well, but I just fixed on a fork for now! https://github.com/octokit/octokit.net/compare/main...jack0x539:octokit.net:main

On Sat, 13 Apr 2024, 13:21 Tom Longhurst, @.***> wrote:

I'm guessing because it's not a "Standard" format that it doesn't parse it

— Reply to this email directly, view it on GitHub https://github.com/octokit/octokit.net/issues/2898#issuecomment-2053631285, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJIDOZGIZGTDXLEXZ7NJELY5EPMHAVCNFSM6AAAAABFVR62BWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJTGYZTCMRYGU . You are receiving this because you authored the thread.Message ID: @.***>

thomhurst commented 1 month ago

Oh have you - I've just raised a PR too! Didn't know you were working on it

jack0x539 commented 1 month ago

Not really, not a contributior, but just needed a quick fix locally!

On Sat, 13 Apr 2024, 13:42 Tom Longhurst, @.***> wrote:

Oh have you - I've just raised a PR too! Didn't know you were working on it

— Reply to this email directly, view it on GitHub https://github.com/octokit/octokit.net/issues/2898#issuecomment-2053636192, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJIDO2DGANFDTDACVU2WJDY5ER33AVCNFSM6AAAAABFVR62BWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJTGYZTMMJZGI . You are receiving this because you authored the thread.Message ID: @.***>