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

Cookies are not getting used with the @ref meta #291

Closed hitesh-sourcefuse closed 1 month ago

hitesh-sourcefuse commented 1 month ago

Using in the VS Code extension with the setting for the cookies Jar as Enabled

### LoginRequest
# @no-cookie-jar

POST /auth/login
Host: {{host}}
...defaultHeaders

{"email":"useremail@example.com","password":"Password@123"}

### Preference
# @ref LoginRequest
GET /user-preference
Host: {{host}}

When running a Preference request, it is not using the Cookie set by the login API which got called first, as it refers to it. API responses are in console is as following:

=== LoginRequest ===

POST http://localhost:3001/auth/login
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.5
accept: application/json
content-length: 60
content-type: application/json
host: localhost:3001
user-agent: httpyac

{"email":"example-email@example.com","password":"Example@123"}

HTTP/1.1 200  - OK
access-control-allow-credentials: true
connection: close
content-length: 798
content-type: application/json
date: Mon, 20 May 2024 10:25:59 GMT
set-cookie: Auth=sessionIdValue; Path=/; Expires=Mon, 20 May 2024 14:01:59 GMT; HttpOnly; Secure; SameSite=None
vary: Origin
x-powered-by: Express

{"expiry":3600000,"accessToken":"..."}

---------------------

GET http://localhost:3001/user-preference
accept-encoding: gzip, deflate, br
accept: */*
host: localhost:3001
user-agent: httpyac

HTTP/1.1 401  - Unauthorized
access-control-allow-credentials: true
connection: close
content-length: 107
content-type: application/json; charset=utf-8
date: Mon, 20 May 2024 10:25:59 GMT
vary: Origin
x-content-type-options: nosniff
x-powered-by: Express

{"error":{"statusCode":401,"name":"UnauthorizedError"}}
AnWeber commented 1 month ago

If you use '# @no-cookie-jar', no cookies will be sent and the cookies received will not be reused for further requests. CookieJar support is completely deactivated. Why do you actually need # @no-cookie-jar? @ref actually ensures that the request is not called more than once. In other words, as long as you do not call up the login again manually, the request would actually be without a cookie. And if you want to delete the cookie manually, it would be stored in the UserStore and can be deleted (or just reset environment).

image
hitesh-sourcefuse commented 1 month ago

For the first request I wanted to use no cookies so that when API hit will have the fresh data set. The issue is resolved after removing the @no-cookie-jar and making the cooking non-secure.

I will close the issue, BTW screenshot was much help to know where I can see the current cookies.

Thanks