AnWeber / httpbook

Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code
https://httpyac.github.io/
MIT License
61 stars 4 forks source link

Global Before/After request hooks are not working #38

Closed rngtng closed 2 years ago

rngtng commented 2 years ago

Imagine following code:

{{+request
   request.headers = { "enforced-header": "foo"};   
}}
{{+response
    console.info(response.body);
}}

# @name request1
GET /v1/foo

# @name request2
GET /v1/foo2

Running this in std. vs-plugin or cli works fine for both requests, but in httpbook it doesn't. Looks like the global hooks are not evaluated

rngtng commented 2 years ago

Btw. I fixed this with the workaround of moving the before request hook into a plugin. still I'd expect behaviour of httpbook, same as text version...

AnWeber commented 2 years ago

the reason is that I parse the whole file from disk and the executing cell from the content of the cell and just patch those together. However, this causes my global script logic to not work correctly. When parsing, the global script is attached directly to the HttpRegion and not thie httpFile. The events request, response, streaming and responseLogging can be easily changed. The Event after gives me problems.

AnWeber commented 2 years ago

The bug was fixed with the new version of vscode-httpyac. Updating httpbook is not necessary

rngtng commented 2 years ago

nice!

AnWeber commented 2 years ago

I don't really like the two newly created hooks (BeforeHttpRegion and AfterHttpRegion) in the plugin API. Please don't consider these two hooks as part of the api, That is why I have not yet included them in the documentation. I will probably remove them again by extending my hook system. And cool that it works now.

AnWeber commented 2 years ago

I have removed the two hooks BeforeHttpRegion and AfterHttpRegion and replaced them with an ExecuteHook + merge Functionality of hooks. In detail, a different order now occurs between interceptor/ hook calls between HttpFile and HttpRegion hooks. However, these should not be a major problem.

Before: httpRegion - hooks => httpRegion - afterLoop => httpFile hooks => httpFile - afterLoop Now: httpRegion - hooks => httpFile hooks => httpRegion - afterLoop => httpFile - afterLoop