...

Source file src/github.com/moby/spdystream/handlers.go

Documentation: github.com/moby/spdystream

     1  /*
     2     Copyright 2014-2021 Docker Inc.
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    16  
    17  package spdystream
    18  
    19  import (
    20  	"io"
    21  	"net/http"
    22  )
    23  
    24  // MirrorStreamHandler mirrors all streams.
    25  func MirrorStreamHandler(stream *Stream) {
    26  	replyErr := stream.SendReply(http.Header{}, false)
    27  	if replyErr != nil {
    28  		return
    29  	}
    30  
    31  	go func() {
    32  		io.Copy(stream, stream)
    33  		stream.Close()
    34  	}()
    35  	go func() {
    36  		for {
    37  			header, receiveErr := stream.ReceiveHeader()
    38  			if receiveErr != nil {
    39  				return
    40  			}
    41  			sendErr := stream.SendHeader(header, false)
    42  			if sendErr != nil {
    43  				return
    44  			}
    45  		}
    46  	}()
    47  }
    48  
    49  // NoopStreamHandler does nothing when stream connects.
    50  func NoOpStreamHandler(stream *Stream) {
    51  	stream.SendReply(http.Header{}, false)
    52  }
    53  

View as plain text