aurelia-auth
aurelia-auth copied to clipboard
Support aurelia-http-client in addition to fetch client
In our project we have a use case for file upload using multipart-form data, and this simply will not work using the aurelia Fetch client. I won't go into a detailed explanation, but Fetch will not work correctly with borowsers to send mulipart-form data, because it doesn't set the content-type and boundary value in the request. As a result, this makes it necessary for us to use the aurelia-http-client for this specific call for file upload.
The aurelia-authentication package provides a FetchConfig class for automatically configuring the aurelia-fetch-client with the appropriate token interceptor. We need similar support for the aurelia-http-client, so that the token interceptor can be attached and the auth token injected.
How can we get this support in http-client?
Thanks, Don
Hi Don, Yeah sorry about that, I was indeed a bit too enthousiast about Fetch when completetly replacing aurelia-http client :( Just wondering, isn't Fetch working correctly when you set content-type and boundary value? Or is Fetch simply unable to work with multi-part form data? Warm regards paul.
Paul -
Regarding your question:
-
Technically, you are not supposed to set the content-type on a FetchPOST with FormData, because it is supposed to send it using the correct format. However, this is not really the case.
-
It is possible to set the content-type, but this won't be a solution, because for multipart form data we need a boundary value, which is dynamically generated and set by the browser, to correspond with the form data parts. So, the content type value should look something like this:
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryqSQQKo8Bw6dtofBP
. We can't manually do this. -
In general, it seems that no, Fetch is not really up to the task of working properly with multipart form data. This is a pretty widely held conclusion, if you search.
So, what would it take to get a similar level of support for http-client? Meaning, just adding the token interceptor to http-client, so that the JWT token is auto-injected in the request made by http-client?
Thanks, Don
I guess someone else was asking for this also, back in September:
https://github.com/paulvanbladel/aurelia-auth/issues/154
Also fetch client in current implementations does not deal with timeouts. It would be nice that plugin also with aurelia-http-client that does deal with http timeouts.
I can't think of a single use case in which fetch is functionally superior to XHR. Unfortunately I can think of numerous cases in which it is less functional.