implemented responses for PUT and OPTIONS

This commit is contained in:
Altair-sh
2026-11-06 03:09:01 +01:00
parent 7a43e7f8c9
commit 2098082aa6
11 changed files with 206 additions and 33 deletions
+11 -6
View File
@@ -28,17 +28,15 @@ func (conn *TcpConnection) Start() {
conn.http.Start()
}
func (conn *TcpConnection) handleHttpRequest(req *http.Request) (res *http.Response) {
func (conn *TcpConnection) handleHttpRequest(req *http.Request) *http.Response {
switch req.Method {
case "GET", "HEAD":
res = conn.serveFileOrDir(req)
return conn.GET_HEAD(req)
case "PUT", "OPTIONS":
res = conn.handleUpload(req)
return conn.PUT_OPTIONS(req)
default:
res = conn.createErrorResponse(req, false, http.StatusMethodNotAllowed, req.Method)
res.Headers["allow"] = "GET, HEAD, PUT, OPTIONS"
return conn.responseMethodNotAllowed(req, "GET, HEAD, PUT, OPTIONS")
}
return
}
func (conn *TcpConnection) createErrorResponse(
@@ -46,3 +44,10 @@ func (conn *TcpConnection) createErrorResponse(
) *http.Response {
return conn.http.CreateErrorResponse(req, wantsClose, http.NewHttpError(status, msg))
}
func (conn *TcpConnection) responseMethodNotAllowed(req *http.Request, allowedMethods string,
) *http.Response {
return conn.createErrorResponse(req, false,
http.StatusMethodNotAllowed, req.Method).
WithHeader("allow", allowedMethods)
}