AnWeber / vscode-httpyac

Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=anweber.vscode-httpyac
MIT License
222 stars 20 forks source link

Global scripts not executed with @request #281

Closed slackwareer closed 2 months ago

slackwareer commented 2 months ago

The script below contains a global region and a test region(only JavaScript with no request named test-1) . When executing test-1 region , the first global region cannot be executed. An exception will be raised during exec of the test-1 region.

{{@request
  exports.host = 'https://github.com';
  console.log('Global Script executed.');
}}

### test-1
GET {{host}} HTTP/1.1

image

But when the @request is removed, the test-1 regions will run successfully..

{{
  exports.host = 'https://github.com';
  console.log('Global Script executed.');
}}

### test-1
GET {{host}} HTTP/1.1

image

Maybe the variable replace hookitem should be moved after the @request region , just before the request execution?

AnWeber commented 2 months ago

@slackwareer The behavior is intentional. I only added the request hooks later. I wanted to offer an easy way to change/extend the replaced request again later. The difference between an execute and the request hook is basically the replacement.