Added request and response
This commit is contained in:
parent
2eff3f64c5
commit
1e79269132
4 changed files with 109 additions and 5 deletions
42
Request.go
Normal file
42
Request.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue