Fork me on GitHub

@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)
If I add another middleware after wrap-file-upload then it works as expected:
(def req-middleware
  (-> (wrap-auth-token login-token)
      (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)
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?


@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.


> 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...


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


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


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


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


@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