Skip to content
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

Request method comparison is case sensitive #40

Open
gdotdesign opened this issue Jan 24, 2020 · 3 comments
Open

Request method comparison is case sensitive #40

gdotdesign opened this issue Jan 24, 2020 · 3 comments

Comments

@gdotdesign
Copy link

I am building an integration and testing it with WebMock and run into this issue.

given I have this mock:

WebMock.stub(:get, "https://api.sandbox.paypal.com/v2/checkout/orders/ORDER_ID")
  .to_return(body: {
    "id"     => "ID",
    "status" => "COMPLETED",
  }.to_json)

and this request:

HTTP::Client
  .new(URI.parse("https://api.sandbox.paypal.com"))
  .exec("get", "/v2/checkout/orders/ORDER_ID")

The request is not handled by WebMock, and the reason is that the method comparison is case sensitive: https://github.com/manastech/webmock.cr/blob/master/src/webmock/stub.cr#L66 in this case "get" == "GET"

I don't have time to fix it now, but I might do it later, using uppercase methods as a workaround now.

@straight-shoota
Copy link

Your request is simply incorrect. According to RFC 7230 and RFC 2616 the request method token is case-sensitive. So you must use upper-case GET. HTTP servers (and thus HTTP server mockups) should not try to autocorrect invalid requests, but fail with 400 Bad Request.

@gdotdesign
Copy link
Author

All right, so what is your suggestion here? Is this a Crystal HTTP::Client issue? should it make sure that the request method is uppercase?

If it remains this way, maybe it should at least warn the user that it's not matching because it's lowercase or something like that? (for the next person who will run into this)

@straight-shoota
Copy link

No, HTTP::Client should just pass through whatever it receives. And this would eventually lead to 400 Bad Request.

Maybe Webmock could intercept requests based on case-insensitive matching method and return 400 Bad Request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants