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

glogrus does not implement http.Flusher even if the underlying http.ResponseWriter does #1

Open
bsdlp opened this issue Sep 20, 2016 · 0 comments

Comments

@bsdlp
Copy link

bsdlp commented Sep 20, 2016

consider the following test code (mostly copied from this repo's README)

package main

import (
    "fmt"
    "log"
    "net/http"

    "goji.io/pat"

    goji "goji.io"

    "golang.org/x/net/context"

    "github.com/Sirupsen/logrus"
    glogrus "github.com/goji/glogrus2"
)

func a(ctx context.Context, w http.ResponseWriter, r *http.Request) {
    _, ok := w.(http.Flusher)
    fmt.Fprintln(w, ok)
}

func main() {
    broken := goji.NewMux()
    logr := logrus.New()
    logr.Formatter = new(logrus.JSONFormatter)
    broken.UseC(glogrus.NewGlogrus(logr, "my-app-name"))

    broken.HandleFuncC(pat.Get("/"), a)

    working := goji.NewMux()
    working.HandleFuncC(pat.Get("/"), a)

    go func() {
        http.ListenAndServe(":8081", working)
    }()
    log.Fatal(http.ListenAndServe(":8080", broken))
}

the results:

jchen@locke-(master|✔)> curl http://localhost:8081/
true
jchen@locke-(master|✔)> curl http://localhost:8080/
false

Also check out this example which seemingly proves that a struct that embeds an interface cannot be type asserted to another interface that the struct itself doesn't implement even if the embedded struct implements the second interface.

Proposal:

type assert the http.ResponseWriter in wrapWriter and use a new struct that implements http.Flusher, http.CloseNotifierand http.Hijacker if the ResponseWriter does. Similar to this perhaps?

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

1 participant