This post is about a tiny bug (correct me if I am wrong) I found in thunder client and postman vs code extensions.
We all know about API testing and cookies. and today's post is about a small bug I found when testing my APIs.
A refresher about how cookies are used:
First, we send a request to a server at an URL. If that server wants to send us cookies, it uses the Set-Cookie header to send us some cookies.
Then every time we send a request to that same domain/server, our cookies are automatically sent to that server. Right?
We/our browsers/clients use the Cookie header in the request for sending their cookies to the server.
So what's the issue here?
Problem in thunder client vs code extension:(v2.9.1)
Now say I am using postman vs code extension to test some API.I sent a request and so I got some cookies from the server. Now every time I send a request to that same server, my cookies are going to be sent as well. Also, they are supposed to be sent using the request Cookie header. Right?
But It won't. You will not find any Cookie header in the request header in thunder client vs code extension.
Problem in postman vs code extension:(v0.3.0)
I have found the same problem in the postman vs code extension.
After getting cookies if you send requests you will not see those cookies in the Cookie header.
✅UPDATE:Postman has fixed this issue. If you are using >= 0.3.1 you won't find this issue.
Now this was very confusing. I was a newbie and couldn't figure out why wasn't I sending the cookies in the Cookie header. Cookies are supposed to be sent in the request Cookie header.
Turns out, the cookies will be sent to the server. But, you won't find them in the header.😑
✨Also One thing I should mention you won't find this issue in the official postman desktop application.
Now I have made an example explaing the whole thing.If you have the patience follow along.
You can find code and some usefull screenshots in this github repo(see the Readme file):
https://github.com/ss-joy/Cookie-header-problem-post
Or you can simply copy paste this code and hit these 2 urls to check the issues:
const express = require("express");
const cookieParser = require("cookie-parser");
const app = express();
app.use(cookieParser());
app.get("/get-some-cookies", (req, res) => {
res.cookie("cartoon-name-one", "ben10");
res.cookie("cartoon-name-two", "mega-xlr");
res.cookie("cartoon-name-three", "powerpuff girls");
res.send("Conrats you have some cookies in your response");
});
app.get("/see-some-cookies", (req, res) => {
console.log(req.cookies);
res.send("OK got it");
});
app.listen(3000, () => {
console.log("server started @port 3000");
});
Top comments (0)