-
Notifications
You must be signed in to change notification settings - Fork 615
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
Add support for multipart downloads for module-format Worker scripts #1040
Add support for multipart downloads for module-format Worker scripts #1040
Conversation
changelog detected ✅ |
Codecov Report
@@ Coverage Diff @@
## master #1040 +/- ##
==========================================
+ Coverage 49.94% 50.04% +0.09%
==========================================
Files 115 116 +1
Lines 10991 11047 +56
==========================================
+ Hits 5490 5528 +38
- Misses 4338 4350 +12
- Partials 1163 1169 +6
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
5bc33ed
to
dc88839
Compare
@jacobbednarz thanks for quickly merging the two test fixits that I pulled out of this PR into #1048 and #1049. I wrote a massive update to the OP with examples and problems of implied content-type. Looking forward to your comments! |
9c37630
to
81f7353
Compare
this PR has become quite significantly larger than the intended scope and i'm afraid, i won't be merging it as is with such a large refactor of the core methods. leading into your next question, the experimental client (see https://github.com/cloudflare/cloudflare-go/blob/master/docs/experimental.md) will focus on these larger, sweeping improvements for the next major release. we'll be intentionally shaking away alot of the older library functionality that we have now which would be a better place for type of changes you're proposing here. i wouldn't recommend opening PRs for it at this stage, but, just be aware that it exists. for now, if you want this functionality, we need to do it within the confines of the library API as it stands todya. |
Ok, thanks for that feedback. I've adjusted the scope of changes to be a lot narrower, please take another look and let me know. |
7cbdae5
to
5fb7388
Compare
98d3596
to
b0f5893
Compare
i've gone ahead and updated |
} | ||
|
||
// Use this method if an API response can have different Content-Type headers and different body formats. | ||
func (api *API) makeRequestContextWithHeadersComplete(ctx context.Context, method, uri string, params interface{}, headers http.Header) (*APIResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't love the name here however, i suspect this will be cleaned up in the experimental client so i'm not too phase but will want to keep it's usage extremely limited until then.
b0f5893
to
e1a08e9
Compare
Looks great! I've rebased and squashed down to three commits: the core change I arrived at, your edits thereupon, and worker test script whitespace changes. You might need to repush your last commit with your own signing key (I see an "Unverified" note) -- or I could squash your final commit into mine with a Co-authored-by? |
done! thanks for the PR and getting it over the line. i've made some notes internally around the issues here with headers and the request methods not exposing everything which hopefully we can address nicely in the experimental client later on. |
This functionality has been released in v0.49.0. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
Description
Since #1010 allows uploading a Worker script in module format, calling DownloadWorker on the same script will return a multipart/form-data response.
Asks
makeRequest...
et al should return a content-type header not just the body.Guidance on a workaround:makeRequest...
et al continue to just return the response body, so consumers assume the format, or detect the format with a heuristic. For example,DownloadWorker
can check the first two bytes and if they are--
then assume the rest of that line is the multipart boundary string and parse the body accordingly. This is so gross.Details
This approach digs into the
makeRequest...
family (makeRequestWithAuthTypeAndHeaders
is the full implementation) and adds support to return the first body of a multipart response.makeRequest
, et al, does not return the mime-type of the response. Consuming functions mostly assume it is application/json, except DownloadWorker which implicitly assumes it's application/javascript.While I've solved the initial problem with #1010 that you can upload a module-format worker but if you try to download it, the DownloadWorker method return raw multipart/form-data, I'm stuck on the next problem: the Module true/false status is implied by whether the download script API returns a javascript content-type or a multipart content-type.
There's no further clue because the Cloudflare API for downloading a worker only gives a Content-Disposition header on its response for a module worker:
vs. non-module format:
This isn't consistent with uploading a module worker, where the Content-Type of the mime-part must be set to
application/javascript+module
like this:Sidenote: why was the method
UploadWorkerWithBindings
added? The bindings are in a param structure, isn't the point to add new params without creating a new method? And in fact if you call UploadWorker with Module-format worker, it shunts to UploadWorkerWithBindings! The salient difference is whether the upload is in multipart format or a direct script. The code path I can see that isn't in multipart format is a non-module worker without bindings (the original product, so probably also the most common case). Per manual testing, the Cloudflare API will accept a multipart/form-data with a plain script as its body -- that is, UploadWorker is sufficient for all cases and UploadWorkerWithBindings is duplicative.Has your change been tested?
Works but creates an awkward roundtrip problem in the current iteration:
UploadWorker
with Module: true because it's a module script.DownloadWorker
with the script name and returns the script body. But what format is it?UploadWorker
... with Module true or false? There's no indication from DownloadWorker which to use.Screenshots (if appropriate):
Types of changes
What sort of change does your code introduce/modify?
Checklist: