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
224 stars 20 forks source link

Script not executed when 302 #189

Closed sir-farfan closed 1 year ago

sir-farfan commented 1 year ago

Hello I'm trying to get some variables from a redirect output (location header) , currently I copy-paste them, I'm trying to put them in the global object for use in the next request but, for whatever reason, when I get the 302 status, the script never gets executed.

###
# @title scripting a redirect
https://httpbin.org/redirect-to?url=http://localhost:3000/some/failed/callback

{{
  console.info("whoot");
  $global.foo = "var";
}}

The call has about 3 redirects, at least the first 2 seem to have the code I need, the last one will always be 302 until we implement the callback (not even in the backlog yet).

Is there an event or something I can use to execute on every redirect to extract the information I need?

jrussellsmyth commented 1 year ago

The issue you are having is the final redirect to your non-existent endpoint will actually get a connection error

sir-farfan commented 1 year ago

I had to add # @no-redirect

AnWeber commented 1 year ago

@sir-farfan I log all redirects in history view

image

And it would also be possible to output them using hook. I haven't created a wrapper for it, but the one provided by got would work.

{{

  Object.assign(request.options, {
    hooks: {
      beforeRedirect: [(options, response) => {
        console.info(response);
      }]
    }
  })
}}

GET https://httpbin.org/absolute-redirect/3
sir-farfan commented 1 year ago

I'll give that a try, maybe better than the 3 @no-redirect's I'm using.