Middlware to generate and set ETag header #2392
Replies: 4 comments 8 replies
-
Lines 76 to 78 in 82a964c |
Beta Was this translation helpful? Give feedback.
-
I have the same question.
The etagResponseWriter is just a copy of bodyDumpResponseWriter from body_dump middleware. Somebody have any idea of how to fix this? |
Beta Was this translation helpful? Give feedback.
-
Thanks to @aldas suggestions and hints I came up with a solution that may be useful for somebody looking to write etags, the solution is working good so far but you must know that the response will be buffered before is sent to the client (This is obvious since there is no way to calculate the etag in dynamic responses without knowing the content of the response) Here is the middleware code
|
Beta Was this translation helpful? Give feedback.
-
If somebody hits this problem, I've just published this solution as a package so it's easy to use in other projects: to install:
ps: I'm not sure if this is a good place to publish this, @aldas feel free to modify or delete this post if something is wrong or I should not publish something I've done (and is not maintained by echo maintainers/colaborators) in your repo |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm trying to create a middleware that will generate an ETag from the request body and set the header.
I was looking at the Before function to let me write the header, but the problem I'm facing is how to access the request body bytes?
My http handlers return
return c.JSON(http.StatusOK, data)
Is there anyway to access data before it gets marshalled and written ?
Beta Was this translation helpful? Give feedback.
All reactions