Added request and response

This commit is contained in:
2023-07-22 12:32:52 +02:00
parent 23f5227f6c
commit b50b9e1083
4 changed files with 109 additions and 5 deletions

42
Request.go Normal file
View 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
}