swift-server / swift-aws-lambda-runtime

Swift implementation of AWS Lambda Runtime
Apache License 2.0
1.13k stars 102 forks source link

404 on a GET even though resource URL is valid for a POST #146

Closed helje5 closed 4 years ago

helje5 commented 4 years ago

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:

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)
  }
tomerd commented 4 years ago

thanks for reporting @helje5, imo your proposal makes sense. @fabianfett wdyt?

fabianfett commented 4 years ago

@tomerd I think this should be solved with the better testing facilities (two port solution).