mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-04 20:20:19 +00:00
37 lines
633 B
Go
37 lines
633 B
Go
|
package spdystream
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
// MirrorStreamHandler mirrors all streams.
|
||
|
func MirrorStreamHandler(stream *Stream) {
|
||
|
replyErr := stream.SendReply(http.Header{}, false)
|
||
|
if replyErr != nil {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
go func() {
|
||
|
io.Copy(stream, stream)
|
||
|
stream.Close()
|
||
|
}()
|
||
|
go func() {
|
||
|
for {
|
||
|
header, receiveErr := stream.ReceiveHeader()
|
||
|
if receiveErr != nil {
|
||
|
return
|
||
|
}
|
||
|
sendErr := stream.SendHeader(header, false)
|
||
|
if sendErr != nil {
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}()
|
||
|
}
|
||
|
|
||
|
// NoopStreamHandler does nothing when stream connects.
|
||
|
func NoOpStreamHandler(stream *Stream) {
|
||
|
stream.SendReply(http.Header{}, false)
|
||
|
}
|