2016-02-09 21:43:00 +02:00
|
|
|
// +build !appengine
|
|
|
|
|
2016-01-29 09:46:11 +02:00
|
|
|
package fasthttp
|
|
|
|
|
2016-02-09 18:12:37 +02:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
2016-03-13 01:06:52 +02:00
|
|
|
"mime/multipart"
|
2016-02-09 18:12:37 +02:00
|
|
|
)
|
2016-01-29 09:46:11 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/labstack/echo/engine"
|
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
Request struct {
|
2016-03-10 22:05:33 +02:00
|
|
|
*fasthttp.RequestCtx
|
|
|
|
url engine.URL
|
|
|
|
header engine.Header
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2016-02-09 08:17:20 +02:00
|
|
|
func NewRequest(c *fasthttp.RequestCtx) *Request {
|
|
|
|
return &Request{
|
2016-03-10 22:05:33 +02:00
|
|
|
RequestCtx: c,
|
|
|
|
url: &URL{URI: c.URI()},
|
2016-03-13 19:03:39 +02:00
|
|
|
header: &RequestHeader{&c.Request.Header},
|
2016-02-09 08:17:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-23 07:13:08 +02:00
|
|
|
func (r *Request) TLS() bool {
|
2016-03-10 22:05:33 +02:00
|
|
|
return r.IsTLS()
|
2016-02-23 07:13:08 +02:00
|
|
|
}
|
|
|
|
|
2016-02-23 07:26:36 +02:00
|
|
|
func (r *Request) Scheme() string {
|
2016-03-10 22:05:33 +02:00
|
|
|
return string(r.RequestCtx.URI().Scheme())
|
2016-02-23 07:26:36 +02:00
|
|
|
}
|
|
|
|
|
2016-02-09 18:12:37 +02:00
|
|
|
func (r *Request) Host() string {
|
2016-03-10 22:05:33 +02:00
|
|
|
return string(r.RequestCtx.Host())
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-09 02:48:03 +02:00
|
|
|
func (r *Request) URI() string {
|
2016-03-10 22:05:33 +02:00
|
|
|
return string(r.RequestURI())
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-09 02:48:03 +02:00
|
|
|
func (r *Request) URL() engine.URL {
|
|
|
|
return r.url
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-09 02:48:03 +02:00
|
|
|
func (r *Request) Header() engine.Header {
|
|
|
|
return r.header
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-09 02:48:03 +02:00
|
|
|
func (r *Request) RemoteAddress() string {
|
2016-03-10 22:05:33 +02:00
|
|
|
return r.RemoteAddr().String()
|
2016-02-09 02:48:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Request) Method() string {
|
2016-03-10 22:05:33 +02:00
|
|
|
return string(r.RequestCtx.Method())
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Request) Body() io.ReadCloser {
|
2016-03-10 22:05:33 +02:00
|
|
|
return ioutil.NopCloser(bytes.NewBuffer(r.PostBody()))
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Request) FormValue(name string) string {
|
2016-03-13 01:06:52 +02:00
|
|
|
return string(r.RequestCtx.FormValue(name))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Request) FormFile(name string) (*multipart.FileHeader, error) {
|
|
|
|
return r.RequestCtx.FormFile(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Request) MultipartForm() (*multipart.Form, error) {
|
|
|
|
return r.RequestCtx.MultipartForm()
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
2016-02-09 18:12:37 +02:00
|
|
|
|
2016-02-22 05:58:19 +02:00
|
|
|
func (r *Request) reset(c *fasthttp.RequestCtx, h engine.Header, u engine.URL) {
|
2016-03-10 22:05:33 +02:00
|
|
|
r.RequestCtx = c
|
2016-02-22 05:58:19 +02:00
|
|
|
r.header = h
|
|
|
|
r.url = u
|
|
|
|
}
|