-
-
Notifications
You must be signed in to change notification settings - Fork 578
Frontend POST / DELETE calls cause "http: multiple response.WriteHeader calls" warning #861
Comments
I don't know the CORS package, so I can't tell you exactly what's going on, but my gut says that CORS is writing headers and then your app is writing headers, hence the multiple header writes. You should investigate why the CORS package is writing headers if it doesn't need to. |
I've found this WriteHeader:
Can It cause that warning? |
Possibly. I don't know the Cors or how Angular does it's requests, so I really can't answer the question. |
For what it's worth, I tried it locally, everything worked fine for me. It has to be your front-end // App is where all routes and middleware for buffalo
// should be defined. This is the nerve center of your
// application.
func App() *buffalo.App {
if app == nil {
app = buffalo.New(buffalo.Options{
Env: ENV,
SessionName: "_ggjs_session",
// PreWares: []buffalo.PreWare{cors.Default().Handler},
})
app.PreWares = []buffalo.PreWare{cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowedHeaders: []string{"Content-Type", "Cookie"},
AllowCredentials: true,
}).Handler}
// Automatically redirect to SSL
app.Use(ssl.ForceSSL(secure.Options{
SSLRedirect: ENV == "production",
SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"},
}))
if ENV == "development" {
app.Use(middleware.ParameterLogger)
}
// Protect against CSRF attacks. https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)
// Remove to disable this.
app.Use(csrf.New)
// Wraps each request in a transaction.
// c.Value("tx").(*pop.PopTransaction)
// Remove to disable this.
app.Use(middleware.PopTransaction(models.DB))
// Setup and use translations:
var err error
if T, err = i18n.New(packr.NewBox("../locales"), "en-US"); err != nil {
app.Stop(err)
}
app.Use(T.Middleware())
app.GET("/", HomeHandler)
// serve files from the public directory:
app.ServeFiles("/", assetsBox)
}
return app
}
|
Problems occurs on preflight request, when you send with OPTIONS method. I created test api project to reproduce warning: Test routes:
Action:
POST cURL:
DELETE cURL:
|
@markbates Can you try this |
I believe you, I don’t have the time unfortunately to try it. If the CORS package is writing headers and then passing it off to the application, that’s a problem. Once someone writes headers others can’t, so if that’s what they’re doing, that’s a problem in that package. You can probably your problem without buffalo and just using a simple net/http app. I don’t believe this to be an issue with buffalo. If you can reproduce it with a basic http app that uses cors and writes headers then the problem is definitely with the cors package. |
I talked to a friend of mine, and he dug through it, and we found the issue! You're not losing your mind. :) There's a fix in the |
@markbates Hi! Yes, fix solved problem! |
Right now the next release is scheduled for 2/12. So it’s going to be a while.
If you want to use it today you can use dep and vendor the development branch.
…-----------
Mark Bates
On Jan 19, 2018, 3:28 AM -0500, danikarik ***@***.***>, wrote:
@markbates Hi! Yes, fix solved problem!
How soon you will merge master branch? Including #866 ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I created new project with --api flag. Put CORS headers according to #609 comment using CORS Handler. After that Angular front-end sends POST request to "/session" and DELETE to "/session".
In Buffalo logs I'm getting warnings like:
2018/01/16 16:38:42 http: multiple response.WriteHeader calls
INFO[2018-01-16T16:38:42+06:00] /session content_type=application/json duration=228.922342ms form="{}" human_size="21 B" method=POST params="{}" path=/session render="93.109µs" request_id=8f03e03e99-847d6fec21 size=21 status=200
2018/01/16 16:38:55 http: multiple response.WriteHeader calls
INFO[2018-01-16T16:38:55+06:00] /session content_type=application/json duration="58.221µs" form=null human_size="21 B" method=DELETE params="{}" path=/session render="38.818µs" request_id=8f03e03e99-7192595a13 size=21 status=200
Do I have problems with Prewares and CORS or wrong implementation?
The text was updated successfully, but these errors were encountered: