Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
helje5 opened this issue Jul 28, 2020 · 2 comments · Fixed by #157
Closed

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

helje5 opened this issue Jul 28, 2020 · 2 comments · Fixed by #157
Labels
kind/bug Feature doesn't work as expected.
Milestone

Comments

@helje5
Copy link

helje5 commented Jul 28, 2020

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)
  }
@tomerd
Copy link
Contributor

tomerd commented Jul 30, 2020

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

@tomerd tomerd added the kind/bug Feature doesn't work as expected. label Jul 30, 2020
@fabianfett
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Feature doesn't work as expected.
Projects
None yet
3 participants