From 8969c328871f2dcce1d91074c7c7156b2819b94c Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 28 Mar 2024 10:53:53 +0100 Subject: [PATCH] Added request methods --- Server.go | 2 +- header.go | 7 ------- parseURL.go => http.go | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) delete mode 100644 header.go rename parseURL.go => http.go (60%) diff --git a/Server.go b/Server.go index e35449c..f372ac0 100644 --- a/Server.go +++ b/Server.go @@ -143,7 +143,7 @@ func (s *server) handleConnection(conn net.Conn) { method = message[:space] - if method != "GET" { + if !isRequestMethod(method) { continue } diff --git a/header.go b/header.go deleted file mode 100644 index c0dbbd6..0000000 --- a/header.go +++ /dev/null @@ -1,7 +0,0 @@ -package web - -// header is used to store HTTP headers. -type header struct { - Key string - Value string -} diff --git a/parseURL.go b/http.go similarity index 60% rename from parseURL.go rename to http.go index 1b2709d..ce7c32c 100644 --- a/parseURL.go +++ b/http.go @@ -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, "://")