mirror of
https://github.com/eolinker/apinto
synced 2025-10-28 11:01:33 +08:00
httpCtx 副本包
This commit is contained in:
82
node/http-context/http-context-copy/uri.go
Normal file
82
node/http-context/http-context-copy/uri.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package http_context_copy
|
||||
|
||||
import (
|
||||
http_service "github.com/eolinker/eosc/eocontext/http-context"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
var _ http_service.IURIWriter = (*URIRequest)(nil)
|
||||
|
||||
type URIRequest struct {
|
||||
uri *fasthttp.URI
|
||||
}
|
||||
|
||||
func (ur *URIRequest) reset(uri *fasthttp.URI) {
|
||||
ur.uri = uri
|
||||
}
|
||||
func (ur *URIRequest) Path() string {
|
||||
return string(ur.uri.Path())
|
||||
}
|
||||
|
||||
func (ur *URIRequest) SetScheme(scheme string) {
|
||||
ur.uri.SetScheme(scheme)
|
||||
}
|
||||
|
||||
func (ur *URIRequest) Host() string {
|
||||
return string(ur.uri.Host())
|
||||
}
|
||||
|
||||
func (ur *URIRequest) SetQuery(key, value string) {
|
||||
|
||||
ur.uri.QueryArgs().Set(key, value)
|
||||
}
|
||||
|
||||
func (ur *URIRequest) AddQuery(key, value string) {
|
||||
ur.uri.QueryArgs().Add(key, value)
|
||||
}
|
||||
|
||||
func (ur *URIRequest) DelQuery(key string) {
|
||||
queryArgs := ur.uri.QueryArgs()
|
||||
queryArgs.Del(key)
|
||||
if queryArgs.Len() == 0 {
|
||||
ur.uri.SetQueryStringBytes(nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (ur *URIRequest) SetRawQuery(raw string) {
|
||||
ur.uri.SetQueryString(raw)
|
||||
}
|
||||
|
||||
func NewURIRequest(uri *fasthttp.URI) *URIRequest {
|
||||
return &URIRequest{uri: uri}
|
||||
}
|
||||
|
||||
func (ur *URIRequest) RequestURI() string {
|
||||
return string(ur.uri.RequestURI())
|
||||
}
|
||||
|
||||
func (ur *URIRequest) Scheme() string {
|
||||
return string(ur.uri.Scheme())
|
||||
}
|
||||
|
||||
func (ur *URIRequest) RawURL() string {
|
||||
return string(ur.uri.FullURI())
|
||||
}
|
||||
|
||||
func (ur *URIRequest) GetQuery(key string) string {
|
||||
|
||||
return string(ur.uri.QueryArgs().Peek(key))
|
||||
}
|
||||
|
||||
func (ur *URIRequest) RawQuery() string {
|
||||
return string(ur.uri.QueryString())
|
||||
}
|
||||
|
||||
func (ur *URIRequest) SetPath(s string) {
|
||||
ur.uri.SetPath(s)
|
||||
|
||||
}
|
||||
|
||||
func (ur *URIRequest) SetHost(host string) {
|
||||
ur.uri.SetHost(host)
|
||||
}
|
||||
Reference in New Issue
Block a user