Fork me on GitHub
#fulcro
<
2022-03-31
>
aratare08:03:52

@tony.kay Sorry for the direct ping. I'm working on file uploading at the moment and have had everything setup according to the book. In my application there's a custom middleware associated with a remote to handle auth (which is a simple Bearer token header in the request) and apparently when file-upload/wrap-file-upload is used, the auth header is somehow removed from the final request sent to the server. This is what I have at the moment:

(def req-middleware
  (-> (wrap-auth-token login-token)
      http/wrap-fulcro-request
      fu/wrap-file-upload
If I add another middleware after wrap-file-upload then it works as expected:
(def req-middleware
  (-> (wrap-auth-token login-token)
      http/wrap-fulcro-request
      fu/wrap-file-upload
      (wrap-auth-token login-token)))
If I remove wrap-file-upload then it also works as per before:
(def req-middleware
  (-> (wrap-auth-token login-token)
      http/wrap-fulcro-request
I'm wondering if this is a bug?

Jakub Holý (HolyJak)10:03:39

Looking at the code, the wrap-file-upload should have no effect if there is no upload. So is it broken only when you actually do an upload? The only thing the middleware does to the request is this

(-> req
  (assoc :body form :method :post :response-type response-type)
  (update :headers dissoc "Content-Type"))
so I do not see how it would remove another header. Could you add some log statements to the middleware to check the incoming req has the token and the outgoing does not?

aratare11:03:16

@U0522TWDA Yep I've sprinkled various print statements around, and as suspected regardless of whether the incoming req has the token or not, the outgoing req will always not have it. I'll do some debugging to see what's actually going on, but as you've mentioned the code doesn't really touch the headers aside from the content-type, which is why I'm surprised to see this behaviour.

aratare11:03:02

> So is it broken only when you actually do an upload? Nope it's broken regardless of whether I have a file or not

Jakub Holý (HolyJak)12:03:44

that is very strange. Perhaps the root cause of the problem is somewhere else then?

Jakub Holý (HolyJak)12:03:41

You could also copy the middleware into your code and see whether it still breaks. What if you replace it with identity ? Then play between those two to find when it breaks...

tony.kay18:04:02

order matters. The file upload middleware takes control of an upload request and doesn’t let anything else handle things. Your wrap-auth-token should be at the “bottom” of your threading, so that it runs first

tony.kay18:04:59

so the relative order of w-f-u and w-f-r is correct…you don’t want w-f-r handling a file upload transaction, but your auth mw won’t be reached in your current config. That is not a bug, though the docs could be clearer

tony.kay18:04:18

actually, the docstring on the w-f-u clearly states this in the NOTE, so perhaps the docs are fine 😄

tony.kay18:04:38

are you using an IDE that shows you docstrings easily? I really recommend having a kb shortcut for that.

aratare07:04:15

@tony.kay Ah silly me then. I read the docstring multiple times and somehow I managed to miss that crucial part 😅 I've moved my mw to the bottom and thus it's working properly now. Thank you and @U0522TWDA for the help 🙂

🎉 1