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

fix(gitlab): don't set Content-Type header when uploading release assets #1183

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

rjw57
Copy link
Contributor

@rjw57 rjw57 commented Dec 9, 2024

As noted in a comment on #1172, switching to the use of the native fetch API broke uploading release assets to GitLab by hard-coding the Content-Type header to "text/plain". The recommended approach is to avoid setting the Content-Type header at all and let the fetch API implementation set it so as to ensure that the correct boundary expression is included.

Add a flag to the request function to allow explicitly disabling setting the Content-Type header. Update the request function to avoid setting the Content-Type header if the body is an instance of FormData. The default behaviour is to set the header as before but we disable setting the header only in the uploadAsset function.

The bug is blocking a feature in our product and I've checked that the change in this PR fixes our observed issue with GitLab release asset uploads. Using the branch from this PR, I am able to create a release with the expected assets in a test project.

Closes #1172

Copy link
Collaborator

@webpro webpro left a comment

Choose a reason for hiding this comment

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

Thanks @rjw57, much appreciated! Happy to merge, but I do have a question.

lib/plugin/gitlab/GitLab.js Outdated Show resolved Hide resolved
As noted in [a comment on release-it#1172][1], switching to the use of the native
fetch API broken uploading release assets to GitLab by hard-coding the
Content-Type header to "text/plain". The [recommended approach][2] is to
avoid setting the Content-Type header at all and let the fetch API
implementation set it so as to ensure that the correct boundary
expression is included.

Update the `request` function to only set the Content-Type header when
body is not an instance of FormData. The default behaviour is to set the
header as before.

[1]: release-it#1172 (comment)
[2]: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest_API/Using_FormData_Objects#sending_files_using_a_formdata_object

Closes release-it#1172
@rjw57 rjw57 force-pushed the fix-release-assets-gitlab branch from 856d375 to b474bc3 Compare December 10, 2024 12:17
Copy link

pkg-pr-new bot commented Dec 10, 2024

Open in Stackblitz

npm i https://pkg.pr.new/release-it@1183

commit: b474bc3

@webpro webpro merged commit 04a36d2 into release-it:main Dec 10, 2024
13 checks passed
@webpro
Copy link
Collaborator

webpro commented Dec 23, 2024

🚀 This pull request is included in v18.0.0-next.4. See Release 18.0.0-next.4 for release notes.

@webpro
Copy link
Collaborator

webpro commented Dec 23, 2024

🚀 This pull request is included in v17.11.0. See Release 17.11.0 for release notes.

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.

gitlab release fails to upload
2 participants