chore: initial commit

This commit is contained in:
2026-10-23 18:35:44 +08:00
commit f6921b7b23
69 changed files with 12148 additions and 0 deletions
+33
View File
@@ -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
}