What does @_request.env['HTTP_X_MY_TOKEN'] return?

133 Views Asked by At

I'm not a ruby or rails programmer, but I'm tasked with reverse engineering an API for an RoR app. My HTTP POST requests are failing a validation check, where this line is supposed to provide a specific piece of data:

value = @_request.env['HTTP_X_MY_TOKEN'];

From what little experience I have and searching I've done, it appears to be looking for an HTTP request header MY_TOKEN but I'm unsure if that's the case.

My current HTTP request looks like this:

POST /myapp HTTP/1.1
Host: website.com:80
Content-Type: application/json
Content-Length: 12 

my post data

If that is the case, can I simply add it to my HTTP post request headers as follows:

POST /myapp HTTP/1.1
Host: website.com:80
Content-Type: application/json
MY_TOKEN: sometokentext
Content-Length: 12 

my post data

If not, how do I fill this value during my HTTP POST request?

1

There are 1 best solutions below

1
Martin Konecny On BEST ANSWER

Sending X-MY-TOKEN should do the trick.

As a side note, prepending custom headers with X- is no longer recommended and deprecated according to RFC-6648:

Custom HTTP headers : naming conventions