Skip to content

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

@bsdlp

Description

@bsdlp

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions