Using basicauth - 401 status after 200 status

Hi,

I'm using traefik to receive HTTPS requests with basic authentication. In the access logs I see a request come on with a 200 response, but often this is followed by 1 or more 401 responses. For example:

user [16/Sep/2022:09:36:41 +0000] "POST /api/message/test HTTP/1.1" 200 12 "-" "-" 700329 "nifi-router@file" "http://nifi:3001" 31ms
- [16/Sep/2022:09:36:41 +0000] "POST /api/message/test HTTP/1.1" 401 17 "-" "-" 700331 "nifi-router@file" "-" 0ms
- [16/Sep/2022:09:36:41 +0000] "POST /api/message/test HTTP/1.1" 401 17 "-" "-" 700332 "nifi-router@file" "-" 0ms
- [16/Sep/2022:09:36:41 +0000] "POST /api/message/test HTTP/1.1" 401 17 "-" "-" 700335 "nifi-router@file" "-" 0ms

My config looks like this:

[http.middlewares.admin.basicAuth]
        users = ["user:password", "user2:pass", ....]
  
  [http.routers.nifi-router]
    entrypoints = ["queue"]
    rule = "Host(`queue.com`) && PathPrefix(`/api/message/test`)"
    service = "nifi-3001"
    middlewares = ["admin"]
    [http.routers.nifi-router.tls]


[http.services]
  [http.services.nifi-3001]
    [[http.services.nifi-3001.loadBalancer.servers]]
      url = "http://nifi:3001"

I don't understand why these 401 responses show up after there has been a 200 response already?

Are you sure this is coming from Traefik? Is Traefik routing requests to multiple services and there are instances that do not support the route? Is your app itself returning a 401 for whatever reason?

All requests show the same nifi-router in the logs though. And the router has only 1 service in it.

I think this is a client problem after looking into it more. If I test this same endpoint myself using curl, I only get 200 responses and the 401 responses are gone.
I also tried replacing Traefik with Apache HTTPD as a test, but it shows the same behaviour with this client. First 200 response, followed by 401 response.