mirror of
https://github.com/eolinker/apinto
synced 2025-10-06 09:17:45 +08:00
httpCtx 副本包
This commit is contained in:
89
node/http-context/http-context-copy/proxy-agent.go
Normal file
89
node/http-context/http-context-copy/proxy-agent.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package http_context_copy
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
http_service "github.com/eolinker/eosc/eocontext/http-context"
|
||||
)
|
||||
|
||||
var _ http_service.IProxy = (*requestAgent)(nil)
|
||||
|
||||
type requestAgent struct {
|
||||
http_service.IRequest
|
||||
host string
|
||||
scheme string
|
||||
statusCode int
|
||||
status string
|
||||
responseLength int
|
||||
beginTime time.Time
|
||||
endTime time.Time
|
||||
hostAgent *UrlAgent
|
||||
}
|
||||
|
||||
func (a *requestAgent) ProxyTime() time.Time {
|
||||
return a.beginTime
|
||||
}
|
||||
|
||||
func (a *requestAgent) StatusCode() int {
|
||||
return a.statusCode
|
||||
}
|
||||
|
||||
func (a *requestAgent) Status() string {
|
||||
return a.status
|
||||
}
|
||||
|
||||
func (a *requestAgent) setStatusCode(code int) {
|
||||
a.statusCode = code
|
||||
a.status = strconv.Itoa(code)
|
||||
}
|
||||
|
||||
func (a *requestAgent) ResponseLength() int {
|
||||
return a.responseLength
|
||||
}
|
||||
|
||||
func (a *requestAgent) setResponseLength(length int) {
|
||||
if length > 0 {
|
||||
a.responseLength = length
|
||||
}
|
||||
}
|
||||
|
||||
func newRequestAgent(IRequest http_service.IRequest, host string, scheme string, beginTime, endTime time.Time) *requestAgent {
|
||||
return &requestAgent{IRequest: IRequest, host: host, scheme: scheme, beginTime: beginTime, endTime: endTime}
|
||||
}
|
||||
|
||||
func (a *requestAgent) ResponseTime() int64 {
|
||||
return a.endTime.Sub(a.beginTime).Milliseconds()
|
||||
}
|
||||
|
||||
func (a *requestAgent) URI() http_service.IURIWriter {
|
||||
if a.hostAgent == nil {
|
||||
a.hostAgent = NewUrlAgent(a.IRequest.URI(), a.host, a.scheme)
|
||||
}
|
||||
return a.hostAgent
|
||||
}
|
||||
|
||||
type UrlAgent struct {
|
||||
http_service.IURIWriter
|
||||
host string
|
||||
scheme string
|
||||
}
|
||||
|
||||
func (u *UrlAgent) SetScheme(scheme string) {
|
||||
u.scheme = scheme
|
||||
}
|
||||
func (u *UrlAgent) Scheme() string {
|
||||
return u.scheme
|
||||
}
|
||||
|
||||
func (u *UrlAgent) Host() string {
|
||||
return u.host
|
||||
}
|
||||
|
||||
func (u *UrlAgent) SetHost(host string) {
|
||||
u.host = host
|
||||
}
|
||||
|
||||
func NewUrlAgent(IURIWriter http_service.IURIWriter, host string, scheme string) *UrlAgent {
|
||||
return &UrlAgent{IURIWriter: IURIWriter, host: host, scheme: scheme}
|
||||
}
|
Reference in New Issue
Block a user