43 lines
864 B
Go
43 lines
864 B
Go
|
package server
|
||
|
|
||
|
import "net/http"
|
||
|
|
||
|
// Request is an interface for HTTP requests.
|
||
|
type Request interface {
|
||
|
Header(key string) string
|
||
|
Host() string
|
||
|
Method() string
|
||
|
Path() string
|
||
|
Protocol() string
|
||
|
}
|
||
|
|
||
|
// request represents the HTTP request used in the given context.
|
||
|
type request struct {
|
||
|
*http.Request
|
||
|
}
|
||
|
|
||
|
// Header returns the header value for the given key.
|
||
|
func (req request) Header(key string) string {
|
||
|
return req.Request.Header.Get(key)
|
||
|
}
|
||
|
|
||
|
// Method returns the request method.
|
||
|
func (req request) Method() string {
|
||
|
return req.Request.Method
|
||
|
}
|
||
|
|
||
|
// Protocol returns the request protocol.
|
||
|
func (req request) Protocol() string {
|
||
|
return req.Request.Proto
|
||
|
}
|
||
|
|
||
|
// Host returns the requested host.
|
||
|
func (req request) Host() string {
|
||
|
return req.Request.Host
|
||
|
}
|
||
|
|
||
|
// Path returns the requested path.
|
||
|
func (req request) Path() string {
|
||
|
return req.Request.URL.Path
|
||
|
}
|