-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support request: how to deny access gracefully #148
Comments
I need to look more into your code, but I'm pretty sure that error is thrown because you are trying to abort HTTP request with c.Abort(...) after you write something into the response, like this: fmt.Fprint(c.Writer, "Permission denied!") You must abort the HTTP request before writing anything to HTTP response. I opened a PR in your repo. xyproto/permissions#1 |
Your solution works great! I will incorporate your pull request. Thank you. |
@xyproto however I couldn't find a way to get the first error |
I think I tried using Fail instead of Abort. I can reproduce it, if you wish. |
No problem, I thought it was another handler. Just remember, Gin writes directly the response, there is no buffer in middle, because it is focused in speed and performance, so next time before writing the body of the response, write the headers such as HTTP Response Code or any other custom header. |
I see! Thank you. |
Hi,
I've written a middleware package, but I'm having trouble denying access gracefully with gin, without getting either "Error #1: Permission denied! Meta: Operation aborted" or "[GIN] WARNING. Headers were already written!".
Here is the example I'm working on for gin, which uses the permissions package:
https://github.com/xyproto/permissions/blob/master/examples/gin/main.go
Any advise is appreciated!
Best regards,
Alexander F Rødseth
The text was updated successfully, but these errors were encountered: