Home > Backend Development > Golang > Why Aren\'t My HTTPOnly Cookies Setting on Localhost Using `fetch()`?

Why Aren\'t My HTTPOnly Cookies Setting on Localhost Using `fetch()`?

Mary-Kate Olsen
Release: 2024-11-27 19:25:18
Original
919 people have browsed it

Why Aren't My HTTPOnly Cookies Setting on Localhost Using `fetch()`?

HTTPOnly Cookie Failing to Set in Browser on Localhost

A developer encountered an issue where HTTPOnly cookies were not being set in the browser while developing a REST API locally.

Approaches Attempted

Various approaches were employed to troubleshoot the issue, including:

  • Creating a simplified Go API to recreate the core functionality.
  • Developing a Node API with Express.

Problem Diagnosis

Despite following recommended practices, the HTTPOnly cookie property remained unset in both cases. The problem was eventually traced to the JavaScript fetch() method used in the front-end.

Solution

The problem was resolved by adding the credentials: 'include' option to the fetch() request. This allows the browser to send and receive cookies, enabling the HTTPOnly attribute to function as intended.

The above is the detailed content of Why Aren\'t My HTTPOnly Cookies Setting on Localhost Using `fetch()`?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template