Checkpoint
This commit is contained in:
@@ -14,6 +14,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"git.maze.io/maze/styx/ca"
|
||||
"git.maze.io/maze/styx/dataset"
|
||||
"git.maze.io/maze/styx/logger"
|
||||
)
|
||||
|
||||
@@ -42,6 +44,13 @@ type Context interface {
|
||||
|
||||
// Response is the response that will be sent back to the client.
|
||||
Response() *http.Response
|
||||
|
||||
// Client group.
|
||||
Client() (dataset.Client, error)
|
||||
}
|
||||
|
||||
type WithCertificateAuthority interface {
|
||||
CertificateAuthority() ca.CertificateAuthority
|
||||
}
|
||||
|
||||
type countingReader struct {
|
||||
@@ -80,6 +89,9 @@ type proxyContext struct {
|
||||
req *http.Request
|
||||
res *http.Response
|
||||
idleTimeout time.Duration
|
||||
ca ca.CertificateAuthority
|
||||
storage dataset.Storage
|
||||
client dataset.Client
|
||||
}
|
||||
|
||||
// NewContext returns an initialized context for the provided [net.Conn].
|
||||
@@ -218,4 +230,28 @@ func (c *proxyContext) WriteHeader(code int) {
|
||||
//return c.res.Header.Write(c)
|
||||
}
|
||||
|
||||
func (c *proxyContext) CertificateAuthority() ca.CertificateAuthority {
|
||||
return c.ca
|
||||
}
|
||||
|
||||
func (c *proxyContext) Client() (dataset.Client, error) {
|
||||
if c.storage == nil {
|
||||
return dataset.Client{}, dataset.ErrNotExist{Object: "client"}
|
||||
}
|
||||
if !c.client.CreatedAt.Equal(time.Time{}) {
|
||||
return c.client, nil
|
||||
}
|
||||
|
||||
var err error
|
||||
switch addr := c.Conn.RemoteAddr().(type) {
|
||||
case *net.TCPAddr:
|
||||
c.client, err = c.storage.ClientByIP(addr.IP)
|
||||
case *net.UDPAddr:
|
||||
c.client, err = c.storage.ClientByIP(addr.IP)
|
||||
default:
|
||||
err = dataset.ErrNotExist{Object: "client"}
|
||||
}
|
||||
return c.client, err
|
||||
}
|
||||
|
||||
var _ Context = (*proxyContext)(nil)
|
||||
|
Reference in New Issue
Block a user