guzzle / psr7

PSR-7 HTTP message library
MIT License
7.88k stars 3 forks source link

Header validation (InvalidArgumentException : ":<header>" is not valid header name) #597

Closed guram-vashakidze closed 8 months ago

guram-vashakidze commented 8 months ago

Description There aren't way to use "not valid" headers (which isn't follow RFC7230). In my app I'm implementing app push notification trough APNS. This API is using headers: :method, :path, :scheme.

Solutions

  1. Add option disable_header_validation - to disable assertHeader method
  2. Add option header_regex - to change default regex /^[a-zA-Z0-9\'#$%&*+.^_|~!-]+$/D`
  3. Add option header_validation - with closure which overwrite assertHeader method
GrahamCampbell commented 8 months ago

Does their API work if you encode the : as %3A?

GrahamCampbell commented 8 months ago

Actually, I think you are misunderstanding the spec you linked to. You are not supposed to add the :method etc headers as real headers. Those are pesudo-headers as part of HTTP/2. You need to set these values as the native method, path and schema on our request object, not as headers.

GrahamCampbell commented 8 months ago

See https://httpwg.org/specs/rfc7540.html#rfc.section.8.1.2.3.

guram-vashakidze commented 8 months ago

@GrahamCampbell Unfortunately these are the request headers not request body (also %3A - not working) - it's clear from their doc and I checked it. I implement it on native cURL lib and it works.

GrahamCampbell commented 8 months ago

Their doc says to use HTTP/2. cURL is for sure correcting your mistake and not using those as real headers for you.

GrahamCampbell commented 8 months ago

If it's "not working", likely you need to instruct Guzzle to use HTTP/2. By default it will only use 1.0 or 1.1.