Skip to content
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

Closed
xyproto opened this issue Nov 14, 2014 · 6 comments
Closed

support request: how to deny access gracefully #148

xyproto opened this issue Nov 14, 2014 · 6 comments
Assignees

Comments

@xyproto
Copy link

xyproto commented Nov 14, 2014

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

@javierprovecho javierprovecho self-assigned this Nov 14, 2014
@javierprovecho
Copy link
Member

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

@xyproto
Copy link
Author

xyproto commented Nov 15, 2014

Your solution works great! I will incorporate your pull request. Thank you.

@xyproto xyproto closed this as completed Nov 15, 2014
@javierprovecho
Copy link
Member

@xyproto however I couldn't find a way to get the first error Error #1: Permission denied! Meta: Operation aborted, if you can tell me the actions to be made to get that error shown in the log, I could investigate further.

@xyproto
Copy link
Author

xyproto commented Nov 15, 2014

I think I tried using Fail instead of Abort. I can reproduce it, if you wish.

@javierprovecho
Copy link
Member

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.

@xyproto
Copy link
Author

xyproto commented Nov 15, 2014

I see! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants