-1

I am sending X-Auth-HMAC header from Java using HttpClient to Nginx + PHP-FPM combo:

        HttpClient
                .newBuilder()
                .build()
                .sendAsync(
                        HttpRequest.newBuilder()
                                .uri("php-fpm:80")
                                .header("Content-Type", "application/json")
                                .header("X-Auth-HMAC", "test_hmac_header")
                                .POST(HttpRequest.BodyPublishers.ofString("test_body"))
                                .build(),
                        HttpResponse.BodyHandlers.ofString()
                );

But on PHP side in $_SERVER variable among all headers i get:

  ...
 "HTTP_X_AUTH_HMAC":"test_hmac_header",
 ...

How could X-Auth-HMAC become HTTP_X_AUTH_HMAC ?

Itsmeromka
  • 3,621
  • 9
  • 46
  • 79
  • Looks a bit like constant variable name would have been accidentally added in quotes and set as header name instead of the constant value.... – StefanR Nov 11 '21 at 18:39
  • 1
    In `$_SERVER` HTTP headers are formatted according to RFC 3875. See this answer: https://stackoverflow.com/questions/541430/how-do-i-read-any-request-header-in-php – cOle2 Nov 11 '21 at 18:42

1 Answers1

0

PHP formats HTTP headers in the $_SERVER variable according to RFC 3875 (the CGI 1.1 spec).

Specifically section 4.1.18:

Meta-variables with names beginning with HTTP_ contain values read from the client request header fields, if the protocol used is HTTP. The HTTP header field name is converted to upper case, has all occurrences of - replaced with _ and has HTTP_ prepended to give the meta-variable name.

Take a loot at this answer for more discussion and alternate methods of getting HTTP headers: How do I read any request header in PHP

cOle2
  • 4,725
  • 1
  • 24
  • 26