kriswallsmith / Buzz

PHP's lightweight HTTP client
MIT License
1.92k stars 251 forks source link

Library should uppercase HTTP method name #416

Open ostrolucky opened 4 years ago

ostrolucky commented 4 years ago

I was experimenting with using this library as http client for stripe-php, via psr18-adapter/stripe-php that I'm working on now, but had to go back to Guzzle, as Buzz is broken there. You see, stripe library defines lowercased HTTP methods names everywhere, but their servers do not accept those:

❯ curl -XGET "https://api.stripe.com/v1/customers"

{
  "error": {
    "message": "You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY'). See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/.",
    "type": "invalid_request_error"
  }
}
❯ curl -Xget "https://api.stripe.com/v1/customers"
<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>

I think you might want to make this library uppercase method names as well, like other libraries do. After all, you do that in some places already

sunkan commented 4 years ago

Hi

The question is where the method normalization belongs. Should it be in the PSR-18 client or in the PSR-7 request or even in the PSR-17 factory

I think it would probably be best handled inside the client to handle PSR-7 implementations that don't have any validation on the method case.

ostrolucky commented 4 years ago

I share same opinion. I don't think there currently exist PSR-17 factory or PSR-7 request with this normalization.

tuupola commented 3 years ago

HTTP method names are case sensitive. Even though the standardized request methods are by convention uppercase, techically GET, get, gEtand GeT are all valid but also different request methods.

https://tools.ietf.org/html/rfc2616#section-5.1.1 https://tools.ietf.org/html/rfc7231#section-4

IMO libraries should not alter user provided request methods. Instead the user should provide the correct request method. In above case the stripe library should be fixed.

ostrolucky commented 3 years ago

Why is Buzz doing normalization on some places, but not other places though?