Added request headers

This commit is contained in:
2024-03-27 22:12:16 +01:00
parent b6c208c75b
commit c3bb8336a3
6 changed files with 131 additions and 65 deletions

View File

@ -4,6 +4,7 @@ import "git.akyoto.dev/go/router"
// Request is an interface for HTTP requests.
type Request interface {
Header(string) string
Host() string
Method() string
Path() string
@ -13,12 +14,25 @@ type Request interface {
// request represents the HTTP request used in the given context.
type request struct {
scheme string
host string
method string
path string
query string
params []router.Parameter
scheme string
host string
method string
path string
query string
headers []header
body []byte
params []router.Parameter
}
// Header returns the header value for the given key.
func (req *request) Header(key string) string {
for _, header := range req.headers {
if header.Key == key {
return header.Value
}
}
return ""
}
// Host returns the requested host.