Closed
Description
Following https://fabianfett.de/swift-on-aws-lambda-creating-your-first-http-endpoint, there is the section about curl + 404:
curl -i http://localhost:7000/invoke
gives
HTTP/1.1 404 Not Found
Which seems to be triggered by the default branch in processRequest(context:request:)
:
// unknown call
default:
self.writeResponse(context: context, status: .notFound)
I think this should be:
- 405 if request is not POST and url.hasSuffix(self.invocationEndpoint)
- 405 is request is not GET and url.hasSuffix(Consts.getNextInvocationURLSuffix)
- maybe a few more like that for the other branches
- 404
Essentially a path which exists for a POST should not throw a 404 for a GET.
I'd suggest to switch on the url at the top level, and then within do the necessary guard for a resource, like:
case url.hasSuffix(Consts.postResponseURLSuffix):
guard method == .POST else {
return self.writeResponse(context: context, status: .methodNotAllowed)
}