rest.nvim icon indicating copy to clipboard operation
rest.nvim copied to clipboard

[Bug] Can't recognize the variable in header

Open Alienover opened this issue 1 year ago • 6 comments

image

The {{TOKEN}} in this case, is parsed as value, instead of variable.

The header should be parsed to

  header
    name: name
    value: value
    value: value
    value: variable
      name: identifier

Alienover avatar May 03 '24 17:05 Alienover

Same problem, in my case, i tried image in older versions works, but i still i love this package, only is solve this little problem

malisoft avatar May 08 '24 00:05 malisoft

Same problem, in my case, i tried image in older versions works, but i still i love this package, only is solve this little problem

i find a solution, the problem iss because by some reason does not work when is together "Bearer {{TOKEN}}" i created another env file called ".env.http" selecting this env file using the Telescope rest env selector and storing in this env file:

TOKEN=Bearer ey.......

note that i am using a variable with a content without spaces between the texts(the problem was laravels does not support spaces un the env variables as well)

Finally this works:

GET {{APP_URL}}/api/1.0/apps?per_page=15
Authorization: {{TOKEN}}
Content-Type:application/json

malisoft avatar May 08 '24 01:05 malisoft

@malisoft that's the solution I am using.... have to replace the whole Authorization value.

Alienover avatar May 08 '24 15:05 Alienover

Hi, sorry for the delay. Life has been kinda busy and I'm still during exams weeks :/

I'm going to move this issue to the tree-sitter-http repository, as it seems to be a problem with the parser and not with rest.nvim itself and fix it as soon as I have some spare time to work on it.

NTBBloodbath avatar May 08 '24 17:05 NTBBloodbath

https://github.com/rest-nvim/tree-sitter-http/issues/29 I created this issue in tree-sitter-http before. No one replied, so I duplicated it here for visibility.

Alienover avatar May 08 '24 17:05 Alienover

I was having issues with setting the Authentication: Bearer XXXXX header, and it ended up being a problem when three conditions happen at the same time:

  • the value contains a space (between Bearer and the actual token, for example)
  • the token contains a pipe character "|"
  • the header value (concatenating the Bearer part and the token) was being made in the request definition

Whenever all happen, setting the header like this won't work:

GET /api/test
host: {{API_BASE_URL}}
Accept: application/json
Authorization: Bearer {{BEARER_TOKEN}}

The value received by the server is just Authorization: Bearer.

BUT, if the env variable already contains the whole value (with the Bearer part), then it works.

Here a snippet of how I'm setting the complete Authorization header value:

POST /api/auth
host: {{API_BASE_URL}}
Content-Type: application/json

{
   "email": "[email protected]",
   "password": "secret"
}

--{%

local body = context.json_decode(context.result.body)
context.set_env("BEARER_TOKEN", "Bearer " .. body.token)

--%}

javoscript avatar May 31 '24 13:05 javoscript

This seems to be a tree-sitter-http issue. Closing this due to v3 release.

boltlessengineer avatar Aug 23 '24 16:08 boltlessengineer