         } else if req.uri.hasPrefix("/unauthorized") {
             try httpServer.respondWithUnauthorizedHeader()
         } else {
-            try httpServer.respond(with: getResponse(request: req))
-        }
-    }
-
-    func getResponse(request: _HTTPRequest) throws -> _HTTPResponse {
-
-        func headersAsJSONResponse() throws -> _HTTPResponse {
-            guard let body = try String(data: request.headersAsJSON(), encoding: .utf8) else {
-                return _HTTPResponse(response: .SERVER_ERROR, body: "Cant convert headers to JSON object")
-            }
-            let headers = "Content-Type: application/json\r\nContent-Length: \(body.count)"
-            return _HTTPResponse(response: .OK, headers: headers, body: body)
-        }
-
+            if req.method == .GET || req.method == .POST || req.method == .PUT {
+                try httpServer.respond(with: getResponse(request: req))
+            }
+            else {
+                try httpServer.respond(with: _HTTPResponse(response: .METHOD_NOT_ALLOWED, body: "Method not allowed"))
+            }
+        }
+    }
+
+    func getResponse(request: _HTTPRequest) -> _HTTPResponse {
         let uri = request.uri
-        if uri == "/head" {
-            guard request.method == .HEAD else { return _HTTPResponse(response: .METHOD_NOT_ALLOWED, body: "Method not allowed") }
-            return try headersAsJSONResponse()
-        }
-
-        if uri == "/get" {
-            guard request.method == .GET else { return _HTTPResponse(response: .METHOD_NOT_ALLOWED, body: "Method not allowed") }
-            return try headersAsJSONResponse()
-        }
-
-        if uri == "/put" {
-            guard request.method == .PUT else { return _HTTPResponse(response: .METHOD_NOT_ALLOWED, body: "Method not allowed") }
-            return try headersAsJSONResponse()
-        }
-
-        if uri == "/post" {
-            guard request.method == .POST else { return _HTTPResponse(response: .METHOD_NOT_ALLOWED, body: "Method not allowed") }
-            return try headersAsJSONResponse()
-        }
-
-        if uri == "/delete" {
-            guard request.method == .DELETE else { return _HTTPResponse(response: .METHOD_NOT_ALLOWED, body: "Method not allowed") }
-            return try headersAsJSONResponse()
-        }
-
         if uri == "/upload" {
-            if let contentLength = request.getHeader(for: "content-length") {
-                let text = "Upload completed!, Content-Length: \(contentLength)"
-                return _HTTPResponse(response: .OK, headers: "Content-Length: \(text.data(using: .utf8)!.count)", body: text)
-            }
-            if let te = request.getHeader(for: "transfer-encoding"), te == "chunked" {
-                return _HTTPResponse(response: .OK, body: "Received Chunked request")
-            } else {
-                return _HTTPResponse(response: .BAD_REQUEST, body: "Missing Content-Length")
-            }
+            let text = "Upload completed!"
+            return _HTTPResponse(response: .OK, headers: "Content-Length: \(text.data(using: .utf8)!.count)", body: text)
         }
 
         if uri == "/country.txt" {


struct _HTTPRequest {
    enum Method : String {
        case HEAD
        case GET
        case POST
        case PUT
        case DELETE
    }
    let method: Method
    let uri: String 

    let headers: [String]

    enum Error: Swift.Error {
        case headerEndNotFound
    }
    
    public init(header: String) throws {
        headers = header.components(separatedBy: _HTTPUtils.CRLF)
        let action = headers[0]
        method = Method(rawValue: action.components(separatedBy: " ")[0])!
        uri = action.components(separatedBy: " ")[1]
        body = ""
    }

