Skip to content

how to return stream response? #899

Description

@NeoyeElf
func encodeXXResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error {
	flusher, ok := w.(http.Flusher)
	if !ok {
                // error happened here
		http.Error(w, "Streaming unsupported!", http.StatusInternalServerError)
		return nil
	}

	w.Header().Set("Content-Type", "text/event-stream; charset=utf-8")
	w.Header().Set("Cache-Control", "no-cache")
	w.Header().Set("Connection", "keep-alive")

       //... some code 
}

Why the w http.ResponseWriter not implement http.Flusher interface? How to return stream response? Thks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions