Added request methods

This commit is contained in:
Eduard Urbach 2024-03-28 10:53:53 +01:00
parent 9cbbd3957a
commit 8969c32887
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
3 changed files with 17 additions and 8 deletions

View File

@ -143,7 +143,7 @@ func (s *server) handleConnection(conn net.Conn) {
method = message[:space]
if method != "GET" {
if !isRequestMethod(method) {
continue
}

View File

@ -1,7 +0,0 @@
package web
// header is used to store HTTP headers.
type header struct {
Key string
Value string
}

View File

@ -2,6 +2,22 @@ package web
import "strings"
// header is used to store HTTP headers.
type header struct {
Key string
Value string
}
// isRequestMethod returns true if the given string is a valid HTTP request method.
func isRequestMethod(method string) bool {
switch method {
case "GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE", "PATCH":
return true
default:
return false
}
}
// parseURL parses a URL and returns the scheme, host, path and query.
func parseURL(url string) (scheme string, host string, path string, query string) {
schemePos := strings.Index(url, "://")