55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package http2
|
|
|
|
import (
|
|
"errors"
|
|
"net"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
// a dummy HTTP2 server conn used by HTTP2 handler
|
|
type conn struct {
|
|
r *http.Request
|
|
w http.ResponseWriter
|
|
closed chan struct{}
|
|
}
|
|
|
|
func (c *conn) Read(b []byte) (n int, err error) {
|
|
return 0, &net.OpError{Op: "read", Net: "http2", Source: nil, Addr: nil, Err: errors.New("read not supported")}
|
|
}
|
|
|
|
func (c *conn) Write(b []byte) (n int, err error) {
|
|
return 0, &net.OpError{Op: "write", Net: "http2", Source: nil, Addr: nil, Err: errors.New("write not supported")}
|
|
}
|
|
|
|
func (c *conn) Close() error {
|
|
select {
|
|
case <-c.closed:
|
|
default:
|
|
close(c.closed)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (c *conn) LocalAddr() net.Addr {
|
|
addr, _ := net.ResolveTCPAddr("tcp", c.r.Host)
|
|
return addr
|
|
}
|
|
|
|
func (c *conn) RemoteAddr() net.Addr {
|
|
addr, _ := net.ResolveTCPAddr("tcp", c.r.RemoteAddr)
|
|
return addr
|
|
}
|
|
|
|
func (c *conn) SetDeadline(t time.Time) error {
|
|
return &net.OpError{Op: "set", Net: "http2", Source: nil, Addr: nil, Err: errors.New("deadline not supported")}
|
|
}
|
|
|
|
func (c *conn) SetReadDeadline(t time.Time) error {
|
|
return &net.OpError{Op: "set", Net: "http2", Source: nil, Addr: nil, Err: errors.New("deadline not supported")}
|
|
}
|
|
|
|
func (c *conn) SetWriteDeadline(t time.Time) error {
|
|
return &net.OpError{Op: "set", Net: "http2", Source: nil, Addr: nil, Err: errors.New("deadline not supported")}
|
|
}
|