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

feat(plugins): Introduce Goyave as middleware #203

Conversation

darkweak
Copy link
Owner

No description provided.

@darkweak darkweak added enhancement New feature or request Next release It will be in the next release labels Apr 11, 2022
@darkweak darkweak self-assigned this Apr 11, 2022
README.md Outdated Show resolved Hide resolved
plugins/goyave/examples/main.go Outdated Show resolved Hide resolved

// Write will write the response body
func (g *goyaveWriterDecorator) Write(b []byte) (int, error) {
g.goyaveResponse.WriteHeader(g.Response.StatusCode)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this line is necessary as goyave.Response already writes the header automatically.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I don't do that, there is a superfluous write header warning.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see why, you are writing directly to the http.ResponseWriter in the line just below, so the goyave.Response doesn't know something has been written and tries to write the header again. You should always write to goyave.Response.

Comment on lines +48 to +50
if g.Response.Body != nil {
b, _ = ioutil.ReadAll(g.Response.Body)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write may be called multiple times (typically when streaming a response). This may cause problems.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the response is a stream/chunked it won't be stored to avoid cache corruption at the moment. So it doesn't go through the write method.

return len(b), nil
}

func (g *goyaveWriterDecorator) PreWrite(b []byte) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PreWrite may never be called if nothing is written in the response (empty response, 204 No Content).
Close() is always called so you can add a check in there as well.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to return a no-content response and it has been triggered. 🤔

@darkweak darkweak force-pushed the feat/plugins/introduce-goyave-plugin branch from 575fab4 to 98088c3 Compare April 12, 2022 20:52
@darkweak darkweak force-pushed the feat/plugins/introduce-goyave-plugin branch 2 times, most recently from c730b22 to 0381ccd Compare April 12, 2022 22:27
@darkweak darkweak force-pushed the feat/plugins/introduce-goyave-plugin branch from 0381ccd to 0fc14c9 Compare April 13, 2022 18:05
@darkweak darkweak merged commit cd8ae43 into feat/plugins/introduce-fiber-plugin Apr 13, 2022
darkweak added a commit that referenced this pull request Apr 13, 2022
* feat(plugins): Introduce Goyave as middleware

* fix review from @System-Glitch

* Add E2E tests to the CI

* Fix config.json not found
darkweak added a commit that referenced this pull request Apr 14, 2022
* feat(plugins): Introduce Fiber as plugin

* feat(plugins): Introduce Goyave as middleware (#203)
@darkweak darkweak deleted the feat/plugins/introduce-goyave-plugin branch June 16, 2022 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Next release It will be in the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants