chore: initial commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
type idleConn struct{ net.Conn }
|
||||
|
||||
func (c *idleConn) Read(b []byte) (int, error) {
|
||||
if e := c.SetReadDeadline(time.Now().Add(2 * time.Minute)); e != nil {
|
||||
return 0, e
|
||||
}
|
||||
return c.Conn.Read(b)
|
||||
}
|
||||
func (c *idleConn) Write(b []byte) (int, error) {
|
||||
if e := c.SetWriteDeadline(time.Now().Add(30 * time.Second)); e != nil {
|
||||
return 0, e
|
||||
}
|
||||
return c.Conn.Write(b)
|
||||
}
|
||||
|
||||
// SetPublicOrigin must be called before serving requests; forwarded headers are not trusted.
|
||||
func (s *Server) SetPublicOrigin(origin string) error {
|
||||
u, e := url.Parse(origin)
|
||||
if e != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" || u.User != nil || u.Path != "" || u.RawQuery != "" || u.ForceQuery || u.Fragment != "" {
|
||||
return errors.New("public origin must be an http(s) origin")
|
||||
}
|
||||
s.publicOrigin = origin
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user