Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve scripts #252

Merged
merged 5 commits into from
Oct 1, 2024
Merged

Improve scripts #252

merged 5 commits into from
Oct 1, 2024

Conversation

gorillamoe
Copy link
Member

No description provided.

@gorillamoe gorillamoe added the enhancement New feature or request label Sep 30, 2024
@gorillamoe gorillamoe self-assigned this Sep 30, 2024
@gorillamoe gorillamoe changed the title WIP Improve scripts Sep 30, 2024
@gorillamoe gorillamoe force-pushed the feat/improve-scripts branch 2 times, most recently from 6e43903 to 32e842a Compare October 1, 2024 13:26
@gorillamoe
Copy link
Member Author

gorillamoe commented Oct 1, 2024

Something like this is now easily possible:

./../scripts/pre-token-gen.js

// https://www.jetbrains.com/help/idea/http-response-reference.html#request-properties
const url = new URL(request.url.tryGetSubstituted());
const method = request.method;
const params = url.searchParams;
const unix_timestamp = Math.floor(Date.now() / 1000);
const token_raw = request.variables.get('TOKEN_RAW');
const key1 = params.get('key1');
const computed_token = `${method}${token_raw}${key1}${unix_timestamp}`;

// Either use request.variables.set which is only valid for the current request
// or use client.global.set("COMPUTED_TOKEN", computed_token) to store the value globally
// and persist it across restarts
request.variables.set('COMPUTED_TOKEN', computed_token);
const contentTypeHeader = request.headers.findByName('Content-Type');
if (contentTypeHeader) {
  client.log("Content-Type:" + contentTypeHeader.getRawValue());
}
client.log({ url, method, params });

advanced-scripting.http

< {%
request.variables.set('TOKEN_RAW', 'THIS_IS_A_TOKEN');
%}
< ./../scripts/pre-token-gen.js
POST https://httpbin.org/post?key1=value1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Token: {{COMPUTED_TOKEN}}

{
  "foobar": "lul"
}

@gorillamoe gorillamoe marked this pull request as ready for review October 1, 2024 16:11
@gorillamoe gorillamoe merged commit 6d6865c into main Oct 1, 2024
3 checks passed
@gorillamoe gorillamoe deleted the feat/improve-scripts branch October 1, 2024 16:11
gorillamoe added a commit to rcasia/kulala.nvim that referenced this pull request Oct 7, 2024
* feat(scripts): make it work with most jetbrains stuff

See: https://www.jetbrains.com/help/idea/http-response-reference.html#request-properties

* chore(version): bump

* feat(docs): request-reference

* feat(scripts): even closer to jetbrains

* fix(docs): linter
iamxiaojianzheng pushed a commit to iamxiaojianzheng/kulala.nvim that referenced this pull request Oct 24, 2024
* feat(scripts): make it work with most jetbrains stuff

See: https://www.jetbrains.com/help/idea/http-response-reference.html#request-properties

* chore(version): bump

* feat(docs): request-reference

* feat(scripts): even closer to jetbrains

* fix(docs): linter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose request verb, body, url, query params and headers in pre/post scripts.
1 participant