TUN-2178: public API to create new h2mux.MuxedStreamRequest

This commit is contained in:
Nick Vollmar 2019-11-13 14:04:19 -06:00
parent c5af83af66
commit 1d96bccc04
2 changed files with 9 additions and 2 deletions

View File

@ -390,7 +390,7 @@ func isConnectionClosedError(err error) bool {
// Called by proxy server and tunnel // Called by proxy server and tunnel
func (m *Muxer) OpenStream(ctx context.Context, headers []Header, body io.Reader) (*MuxedStream, error) { func (m *Muxer) OpenStream(ctx context.Context, headers []Header, body io.Reader) (*MuxedStream, error) {
stream := m.NewStream(headers) stream := m.NewStream(headers)
if err := m.MakeMuxedStreamRequest(ctx, MuxedStreamRequest{stream, body}); err != nil { if err := m.MakeMuxedStreamRequest(ctx, NewMuxedStreamRequest(stream, body)); err != nil {
return nil, err return nil, err
} }
if err := m.AwaitResponseHeaders(ctx, stream); err != nil { if err := m.AwaitResponseHeaders(ctx, stream); err != nil {
@ -401,7 +401,7 @@ func (m *Muxer) OpenStream(ctx context.Context, headers []Header, body io.Reader
func (m *Muxer) OpenRPCStream(ctx context.Context) (*MuxedStream, error) { func (m *Muxer) OpenRPCStream(ctx context.Context) (*MuxedStream, error) {
stream := m.NewStream(RPCHeaders()) stream := m.NewStream(RPCHeaders())
if err := m.MakeMuxedStreamRequest(ctx, MuxedStreamRequest{stream: stream, body: nil}); err != nil { if err := m.MakeMuxedStreamRequest(ctx, NewMuxedStreamRequest(stream, nil)); err != nil {
return nil, err return nil, err
} }
if err := m.AwaitResponseHeaders(ctx, stream); err != nil { if err := m.AwaitResponseHeaders(ctx, stream); err != nil {

View File

@ -54,6 +54,13 @@ type MuxedStreamRequest struct {
body io.Reader body io.Reader
} }
func NewMuxedStreamRequest(stream *MuxedStream, body io.Reader) MuxedStreamRequest {
return MuxedStreamRequest{
stream: stream,
body: body,
}
}
func (r *MuxedStreamRequest) flushBody() { func (r *MuxedStreamRequest) flushBody() {
io.Copy(r.stream, r.body) io.Copy(r.stream, r.body)
r.stream.CloseWrite() r.stream.CloseWrite()