mistweaverco / kulala.nvim

A minimal 🤏 HTTP-client 🐼 interface 🖥️ for Neovim ❤️.
https://kulala.mwco.app
MIT License
559 stars 26 forks source link

[Q] Is it possible to have global headers? #60

Closed yujinyuz closed 1 month ago

yujinyuz commented 1 month ago

I just want to have all the requests have Accept: application/json because most of them are JSON anyways.

And there is a problem if the last request is json and then if you run another request without accept: application/json, it becomes plaintext and you'll get an error in treesitter

Error executing vim.schedule lua callback: ...table/share/nvim/runtime/lua/vim/treesitter/language.lua:107: no parser for 'text' language, see :help trees
itter-parsers
stack traceback:
        [C]: in function 'error'
        ...table/share/nvim/runtime/lua/vim/treesitter/language.lua:107: in function 'add'
        ...e/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:111: in function 'new'
        .../neovim/stable/share/nvim/runtime/lua/vim/treesitter.lua:41: in function '_create_parser'
        .../neovim/stable/share/nvim/runtime/lua/vim/treesitter.lua:108: in function 'get_parser'
        ...m/stable/share/nvim/runtime/lua/vim/treesitter/_fold.lua:117: in function 'compute_folds_levels'
        ...m/stable/share/nvim/runtime/lua/vim/treesitter/_fold.lua:380: in function 'fn'
        ...m/stable/share/nvim/runtime/lua/vim/treesitter/_fold.lua:293: in function <...m/stable/share/nvim/runtime/lua/vim/treesitter/_fold.lua:289>
Press ENTER or type command to continue
gorillamoe commented 1 month ago

And there is a problem if the last request is json and then if you run another request without accept: application/json, it becomes plaintext and you'll get an error in treesitter

Will try to fix that.

I just want to have all the requests have Accept: application/json because most of them are JSON anyways.

Afaik the http spec does not allow/enable us to do so, but I'm quite intrigued by the idea.

Maybe we can have a separate file like the http-client.env.json and call it http-client.headers.json

There we could put default headers.

The file would be completely optional. It would be also possible to override these headers on a per request basis.

On thing I'm not quite sure about is, if this headers file should be structured as the env filez so that you can have different headers for each environment..?!

What do you think?

yujinyuz commented 1 month ago

@gorillamoe

I don't have any opinions on the http-client.headers.json but I just got that idea from an insomnia plugin that I was using before (think it was merged into core)

where if you create an Environment and add the headers inside DEFAULT_HEADERS it would automatically pick it up and will get overridden if a header is provided

image
gorillamoe commented 1 month ago

I think we should add it to the http-client.env.json then.

Thanks for the example and explanation.

gorillamoe commented 1 month ago

Currently working on it.

gorillamoe commented 1 month ago

See: https://kulala.mwco.app/docs/usage/dotenv-and-http-client.env.json-support#default-http-headers