github.com/ice-blockchain/go/src@v0.0.0-20240403114104-1564d284e521/net/http/h2_ws_hijacker.go (about)

     1  // SPDX-License-Identifier: ice License 1.0
     2  
     3  package http
     4  
     5  import (
     6  	"bufio"
     7  	"net"
     8  	stdlibtime "time"
     9  )
    10  
    11  type connWrapper struct {
    12  	rw *http2responseWriter
    13  }
    14  
    15  func (rw *connWrapper) Write(b []byte) (n int, err error) {
    16  	return rw.rw.Write(b)
    17  }
    18  func (rw *connWrapper) Flush() {
    19  	rw.rw.Flush()
    20  }
    21  
    22  func (rw *connWrapper) SetReadDeadline(t stdlibtime.Time) error {
    23  	return nil
    24  }
    25  
    26  func (rw *connWrapper) SetWriteDeadline(t stdlibtime.Time) error {
    27  	return nil
    28  }
    29  
    30  func (rw *connWrapper) Read(b []byte) (n int, err error) {
    31  	return rw.rw.rws.stream.body.Read(b)
    32  }
    33  
    34  func (rw *connWrapper) Close() error {
    35  	if rw.rw.rws.stream.state != http2stateClosed {
    36  		rw.rw.handlerDone()
    37  	}
    38  
    39  	return nil
    40  }
    41  
    42  func (rw *connWrapper) LocalAddr() net.Addr {
    43  	return rw.rw.rws.conn.conn.LocalAddr()
    44  }
    45  
    46  func (rw *connWrapper) RemoteAddr() net.Addr {
    47  	return rw.rw.rws.conn.conn.RemoteAddr()
    48  }
    49  
    50  func (rw *connWrapper) SetDeadline(t stdlibtime.Time) error {
    51  	return nil
    52  }
    53  
    54  func (rw *http2responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
    55  	brw := bufio.NewReadWriter(bufio.NewReader(rw.rws.stream.body), rw.rws.bw)
    56  	return &connWrapper{rw: rw}, brw, nil
    57  }