gofiber / fiber

⚡️ Express inspired web framework written in Go

Home Page:https://gofiber.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🤗 [Question]: How can I disable 304 responses with c.SendFile(), c.Download(), or Filesystem middleware?

xEricL opened this issue · comments

Question Description

I am using c.Download() to send files within a handler. Sometimes it responses with 304. However, I want it to always respond with 200 (assuming the file is found).

How can I do that? Is it as simple as:

return c.Status(fiber.StatusOK).Download(filepath, filename)

I believe the 304 response mechanism was implemented in response to this bug report #516

However, it appears that the solution assumes the app is sending files to a browser. In my case, requests made to my app do not come from a browser.

Code Snippet (optional)

No response

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.

@xEricL HTTP 304 Not Modified is a status code used to indicate that the requested resource has not changed since the last time it was requested, and therefore, the client can continue to use the cached version of the resource instead of re-downloading it. This status code is typically used in conjunction with HTTP headers like If-Modified-Since or If-None - Match. This ia why you see HTTP 200 for the first request, but 304 after.

@gaby yeah I understand the status code. But in my case, requests are made from a java app, not from a browser. The java app expects a 200, but instead the client is receiving a 304, which would cause the client-side code to fail if it errors out on non-200 responses.

I understand that this can be disabled if I'm using App.Static(). However, there doesn't seem to be a way to disable it for c.SendFile() responses in a regular handler.

Just realized, this is pretty much a duplicate of #2945

@xEricL Yeah, you are right it's the same issue