Skip to content

Streaming模式并不实时 #15

Open
@vaxin

Description

@vaxin

io.Copy无法保证实时转发streaming流,需要改进

`buf := make([]byte, 1024*1024) // 1MB buffer
for {

n, err := resp.Body.Read(buf)
if err != nil && err != io.EOF {
    http.Error(w, err.Error(), http.StatusInternalServerError)
    return
}
if n == 0 {
    break
}
if _, err := w.Write(buf[:n]); err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
    return
}
w.(http.Flusher).Flush()

}`

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