Documentation ¶
Index ¶
- Constants
- Variables
- func CreateForbiddenResp(request *Request) *bfe_http.Response
- func CreateInternalResp(request *Request, code int) *bfe_http.Response
- func CreateInternalSrvErrResp(request *Request) *bfe_http.Response
- type BackendInfo
- type OperationStage
- type RedirectInfo
- type Request
- func (req *Request) AddTags(name string, ntags []string)
- func (req *Request) CachedCookie() bfe_http.CookieMap
- func (req *Request) CachedQuery() url.Values
- func (req *Request) Cookie(name string) (*bfe_http.Cookie, bool)
- func (req *Request) GetContext(key interface{}) interface{}
- func (req *Request) GetTags(name string) []string
- func (req *Request) Protocol() string
- func (req *Request) SetContext(key, val interface{})
- func (req *Request) SetRequestTransport(backend *backend.BfeBackend, transport bfe_http.RoundTripper)
- type RequestRoute
- type RequestStat
- type RequestTags
- type RequestTransport
- type ServerDataConfInterface
- type Session
- func (s *Session) ClearContext()
- func (s *Session) Finish()
- func (s *Session) GetContext(key interface{}) interface{}
- func (s *Session) GetError() (string, error)
- func (s *Session) GetVip() net.IP
- func (s *Session) IncReqNum(count int) int64
- func (s *Session) IncReqNumActive(count int) int64
- func (s *Session) ReadTotal() int
- func (s *Session) ReqNum() int64
- func (s *Session) ReqNumActive() int64
- func (s *Session) SetContext(key, val interface{})
- func (s *Session) SetError(errCode error, errMsg string)
- func (s *Session) SetReqNum(count int)
- func (s *Session) SetReqNumActive(count int)
- func (s *Session) SetTrustSource(isTrustSource bool)
- func (s *Session) String() string
- func (s *Session) TrustSource() bool
- func (s *Session) UpdateReadTotal(total int) int
- func (s *Session) UpdateWriteTotal(total int) int
- func (s *Session) WriteTotal() int
Constants ¶
View Source
const ( HeaderBfeIP = "X-Bfe-Ip" HeaderBfeLogId = "X-Bfe-Log-Id" HeaderForwardedHost = "X-Forwarded-Host" HeaderForwardedFor = "X-Forwarded-For" HeaderForwardedPort = "X-Forwarded-Port" HeaderRealIP = "X-Real-Ip" HeaderRealPort = "X-Real-Port" )
View Source
const ( SessionNotTrustSource int32 = 0 SessionTrustSource int32 = 1 )
View Source
const (
GlobalProduct = "global"
)
Variables ¶
View Source
var ( // client error ErrClientTlsHandshake = errors.New("CLIENT_TLS_HANDSHAKE") // tls handshake error ErrClientWrite = errors.New("CLIENT_WRITE") // write client error ErrClientClose = errors.New("CLIENT_CLOSE") // close by peer ErrClientLongHeader = errors.New("CLIENT_LONG_HEADER") // req too long header ErrClientLongUrl = errors.New("CLIENT_LONG_URL") // req too long url ErrClientTimeout = errors.New("CLIENT_TIMEOUT") // timeout ErrClientBadRequest = errors.New("CLIENT_BAD_REQUEST") // bad request ErrClientZeroContentlen = errors.New("CLIENT_ZERO_CONTENTLEN") // zero content length ErrClientExpectFail = errors.New("CLIENT_EXPECT_FAIL") // expect fail ErrClientReset = errors.New("CLIENT_RESET") // client reset connection ErrClientFrame = errors.New("CLIENT_LONG_FRAME") // only used for spdy/http2 // backend error ErrBkFindProduct = errors.New("BK_FIND_PRODUCT") // fail to find product ErrBkFindLocation = errors.New("BK_FIND_LOCATION") // fail to find location ErrBkNoCluster = errors.New("BK_NO_CLUSTER") // no cluster found ErrBkNoSubCluster = errors.New("BK_NO_SUB_CLUSTER") // no sub-cluster found ErrBkNoBackend = errors.New("BK_NO_BACKEND") // no backend found ErrBkRequestBackend = errors.New("BK_REQUEST_BACKEND") // forward request to backend error ErrBkConnectBackend = errors.New("BK_CONNECT_BACKEND") // connect backend error ErrBkWriteRequest = errors.New("BK_WRITE_REQUEST") // write request error (caused by bk or client) ErrBkReadRespHeader = errors.New("BK_READ_RESP_HEADER") // read response error ErrBkRespHeaderTimeout = errors.New("BK_RESP_HEADER_TIMEOUT") // read response timeout ErrBkTransportBroken = errors.New("BK_TRANSPORT_BROKEN") // conn broken ErrBkRetryTooMany = errors.New("BK_RETRY_TOOMANY") // reach retry max ErrBkNoSubClusterCross = errors.New("BK_NO_SUB_CLUSTER_CROSS") // no sub-cluster found ErrBkCrossRetryBalance = errors.New("BK_CROSS_RETRY_BALANCE") // cross retry balance failed // GSLB error ErrGslbBlackhole = errors.New("GSLB_BLACKHOLE") // deny by blackhole )
View Source
var HopHeaders = []string{
"Connection",
"Keep-Alive",
"Proxy-Authenticate",
"Proxy-Authorization",
"Te",
"Trailers",
"Transfer-Encoding",
"Upgrade",
}
HopHeaders are Hop-by-hop headers. These are removed when sent to the backend. http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html
Functions ¶
func CreateForbiddenResp ¶
CreateForbiddenResp returns a HTTP 403 response
func CreateInternalSrvErrResp ¶
CreateInternalSrvErrResp returns a HTTP 500 response
Types ¶
type BackendInfo ¶
type OperationStage ¶
type OperationStage int
const ( StageStartConn OperationStage = iota StageReadReqHeader StageReadReqBody StageConnBackend StageWriteBackend StageReadResponseHeader StageReadResponseBody StageWriteClient StageEndRequest )
type RedirectInfo ¶
type Request ¶
type Request struct { Connection net.Conn Session *Session RemoteAddr *net.TCPAddr // address of remote peer ClientAddr *net.TCPAddr // address of real client. Maybe nil if request is from HttpRequest *bfe_http.Request // incoming request OutRequest *bfe_http.Request // forwarded request HttpResponse *bfe_http.Response // corresponding response CookieMap bfe_http.CookieMap // cookie map Query url.Values // save url query LogId string // log id for each request ReqBody []byte // req body, size is limited ReqBodyPeeked bool // whether req body has been peeked Route RequestRoute // for get backend cluster based on host/path/query/header/... Tags RequestTags // request tag info Trans RequestTransport // request transport BfeStatusCode int // request directly return by bfe ErrCode error // error code for handling request ErrMsg string // additional error msg Stat *RequestStat // time, data length, etc. RetryTime int // times of retry Backend BackendInfo // backend info Redirect RedirectInfo // redirect info SvrDataConf ServerDataConfInterface // interface for ServerDataConf // User context associated with this request Context map[interface{}]interface{} }
Request is a wrapper of HTTP request
func NewRequest ¶
func NewRequest(request *bfe_http.Request, conn net.Conn, stat *RequestStat, session *Session, svrDataConf ServerDataConfInterface) *Request
NewRequest creates and initializes a new request.
func (*Request) CachedCookie ¶
func (*Request) CachedQuery ¶
func (*Request) GetContext ¶
func (req *Request) GetContext(key interface{}) interface{}
func (*Request) SetContext ¶
func (req *Request) SetContext(key, val interface{})
func (*Request) SetRequestTransport ¶
func (req *Request) SetRequestTransport(backend *backend.BfeBackend, transport bfe_http.RoundTripper)
type RequestRoute ¶
type RequestStat ¶
type RequestStat struct { // time stat ReadReqStart time.Time // after read first line of http request ReadReqEnd time.Time // after read http request FindProStart time.Time // just before find product FindProEnd time.Time // after find product LocateStart time.Time // just before find location LocateEnd time.Time // after find location ClusterStart time.Time // just before connect backend cluster ClusterEnd time.Time // after get response from backend cluster // info for last successful connected backend BackendStart time.Time // just before connect backend BackendEnd time.Time // after get response from backend ResponseStart time.Time // before write response to client ResponseEnd time.Time // after write response to client BackendFirst time.Time // just before connect backend, for first invoke (retry may exist) // data length HeaderLenIn int // length of request header BodyLenIn int // length of request body HeaderLenOut int // length of response header BodyLenOut int // length of response body // some status IsCrossCluster bool // with cross-cluster retry? }
func NewRequestStat ¶
func NewRequestStat(start time.Time) *RequestStat
type RequestTags ¶
type RequestTransport ¶
type RequestTransport struct { Backend *backend.BfeBackend // destination backend for request Transport bfe_http.RoundTripper // transport to backend }
type ServerDataConfInterface ¶
type ServerDataConfInterface interface { ClusterTableLookup(clusterName string) (*bfe_cluster.BfeCluster, error) HostTableLookup(hostname string) (string, error) }
ServerDataConfInterface is an interface used for lookup config for each request
type Session ¶
type Session struct { SessionId string // session id StartTime time.Time // time of accept the connection EndTime time.Time // time of close connection Overhead time.Duration Connection net.Conn RemoteAddr *net.TCPAddr // client address Use100Continue bool // "expect 100-continue" is used? Proto string // protocol for the connection IsSecure bool // over tls connection? TlsState *bfe_tls.ConnectionState // tls state when using TLS Vip net.IP // the virtual ip visited Vport int // vip virtual port visited Product string // product name of vip Rtt uint32 // smoothed RTT for current connection (us) // contains filtered or unexported fields }
func NewSession ¶
NewSession creates and initializes a new session
func (*Session) ClearContext ¶ added in v1.2.0
func (s *Session) ClearContext()
ClearContext clears the old context and makes a new one.
func (*Session) GetContext ¶
func (s *Session) GetContext(key interface{}) interface{}
func (*Session) IncReqNumActive ¶
func (*Session) ReqNumActive ¶
func (*Session) SetContext ¶
func (s *Session) SetContext(key, val interface{})
func (*Session) SetReqNumActive ¶ added in v1.2.0
func (*Session) SetTrustSource ¶ added in v1.2.0
func (*Session) TrustSource ¶ added in v1.2.0
func (*Session) UpdateReadTotal ¶
func (*Session) UpdateWriteTotal ¶
func (*Session) WriteTotal ¶
Click to show internal directories.
Click to hide internal directories.