2016-01-29 09:46:11 +02:00
|
|
|
package standard
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2016-03-13 01:06:52 +02:00
|
|
|
"mime/multipart"
|
2016-01-29 09:46:11 +02:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/labstack/echo/engine"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2016-03-15 04:58:46 +02:00
|
|
|
// Request implements `engine.Request`.
|
2016-01-29 09:46:11 +02:00
|
|
|
Request struct {
|
2016-03-10 22:05:33 +02:00
|
|
|
*http.Request
|
|
|
|
url engine.URL
|
|
|
|
header engine.Header
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2016-03-15 08:33:16 +02:00
|
|
|
// TLS implements `engine.Request#TLS` method.
|
2016-02-23 07:13:08 +02:00
|
|
|
func (r *Request) TLS() bool {
|
2016-03-10 22:05:33 +02:00
|
|
|
return r.Request.TLS != nil
|
2016-02-23 07:13:08 +02:00
|
|
|
}
|
|
|
|
|
2016-03-15 08:33:16 +02:00
|
|
|
// Scheme implements `engine.Request#Scheme` method.
|
2016-02-23 07:26:36 +02:00
|
|
|
func (r *Request) Scheme() string {
|
|
|
|
if r.TLS() {
|
|
|
|
return "https"
|
|
|
|
}
|
|
|
|
return "http"
|
|
|
|
}
|
|
|
|
|
2016-03-15 08:33:16 +02:00
|
|
|
// Host implements `engine.Request#Host` method.
|
2016-02-09 18:12:37 +02:00
|
|
|
func (r *Request) Host() string {
|
2016-03-10 22:05:33 +02:00
|
|
|
return r.Request.Host
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
|
2016-03-15 08:33:16 +02:00
|
|
|
// URL implements `engine.Request#URL` method.
|
2016-01-29 09:46:11 +02:00
|
|
|
func (r *Request) URL() engine.URL {
|
|
|
|
return r.url
|
|
|
|
}
|
|
|
|
|
2016-03-15 08:33:16 +02:00
|
|
|
// Header implements `engine.Request#URL` method.
|
2016-02-09 02:48:03 +02:00
|
|
|
func (r *Request) Header() engine.Header {
|
|
|
|
return r.header
|
|
|
|
}
|
|
|
|
|
2016-02-11 02:51:43 +02:00
|
|
|
// func Proto() string {
|
|
|
|
// return r.request.Proto()
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// func ProtoMajor() int {
|
|
|
|
// return r.request.ProtoMajor()
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// func ProtoMinor() int {
|
|
|
|
// return r.request.ProtoMinor()
|
|
|
|
// }
|
|
|
|
|
2016-03-15 08:33:16 +02:00
|
|
|
// UserAgent implements `engine.Request#UserAgent` method.
|
2016-03-15 04:58:46 +02:00
|
|
|
func (r *Request) UserAgent() string {
|
|
|
|
return r.Request.UserAgent()
|
|
|
|
}
|
|
|
|
|
2016-03-15 08:33:16 +02:00
|
|
|
// RemoteAddress implements `engine.Request#RemoteAddress` method.
|
2016-01-29 09:46:11 +02:00
|
|
|
func (r *Request) RemoteAddress() string {
|
2016-03-10 22:05:33 +02:00
|
|
|
return r.RemoteAddr
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
|
2016-03-15 08:33:16 +02:00
|
|
|
// Method implements `engine.Request#Method` method.
|
2016-01-29 09:46:11 +02:00
|
|
|
func (r *Request) Method() string {
|
2016-03-10 22:05:33 +02:00
|
|
|
return r.Request.Method
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
|
2016-03-15 08:33:16 +02:00
|
|
|
// SetMethod implements `engine.Request#SetMethod` method.
|
2016-03-15 07:45:29 +02:00
|
|
|
func (r *Request) SetMethod(method string) {
|
|
|
|
r.Request.Method = method
|
|
|
|
}
|
|
|
|
|
2016-03-15 08:33:16 +02:00
|
|
|
// URI implements `engine.Request#URI` method.
|
2016-01-29 09:46:11 +02:00
|
|
|
func (r *Request) URI() string {
|
2016-03-10 22:05:33 +02:00
|
|
|
return r.RequestURI
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
|
2016-03-15 08:33:16 +02:00
|
|
|
// Body implements `engine.Request#Body` method.
|
2016-03-17 06:24:04 +02:00
|
|
|
func (r *Request) Body() io.Reader {
|
2016-03-10 22:05:33 +02:00
|
|
|
return r.Request.Body
|
2016-01-29 09:46:11 +02:00
|
|
|
}
|
|
|
|
|
2016-03-15 08:33:16 +02:00
|
|
|
// FormValue implements `engine.Request#FormValue` method.
|
2016-01-29 09:46:11 +02:00
|
|
|
func (r *Request) FormValue(name string) string {
|
2016-03-10 22:05:33 +02:00
|
|
|
return r.Request.FormValue(name)
|
2016-02-09 18:12:37 +02:00
|
|
|
}
|
|
|
|
|
2016-03-15 08:33:16 +02:00
|
|
|
// FormFile implements `engine.Request#FormFile` method.
|
2016-03-13 01:06:52 +02:00
|
|
|
func (r *Request) FormFile(name string) (*multipart.FileHeader, error) {
|
|
|
|
_, fh, err := r.Request.FormFile(name)
|
|
|
|
return fh, err
|
|
|
|
}
|
|
|
|
|
2016-03-15 08:33:16 +02:00
|
|
|
// MultipartForm implements `engine.Request#MultipartForm` method.
|
2016-03-13 01:06:52 +02:00
|
|
|
func (r *Request) MultipartForm() (*multipart.Form, error) {
|
2016-03-13 23:19:22 +02:00
|
|
|
r.Request.ParseMultipartForm(32 << 20) // 32 MB
|
2016-03-13 01:06:52 +02:00
|
|
|
return r.Request.MultipartForm, nil
|
|
|
|
}
|
|
|
|
|
2016-02-05 00:40:08 +02:00
|
|
|
func (r *Request) reset(req *http.Request, h engine.Header, u engine.URL) {
|
2016-03-10 22:05:33 +02:00
|
|
|
r.Request = req
|
2016-02-05 00:40:08 +02:00
|
|
|
r.header = h
|
|
|
|
r.url = u
|
|
|
|
}
|