繁体   English   中英

Set-Cookie标头已从响应中删除,Spring启动

[英]Set-Cookie header is removed from response, Spring boot

我有简单的@RestController,我正在尝试添加Cookie,但在响应中看不到它。 添加任何其他响应标头都可以,但是如果我使用.addCookie()或.addHeader(“ Set-Cookie”,“ something”),则会将其过滤掉。 此外,没有实现自定义过滤器。

如何禁用此功能并将Cookie添加到响应中?

Spring安全配置:

 @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {

        httpSecurity
                .authorizeRequests()
                .anyRequest()
                .permitAll();

控制器代码:

import  org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Cookie;

@RestController
public class MyRestController {

    @GetMapping(value="/some")
    public Object getUser(HttpServletResponse resp) {

        resp.addCookie(new Cookie("yes","it_is_possible"));
        return "Some test string";
    }
}

启动应用程序后,自定义Cookie可以正常运行:

$ curl -v http://127.0.0.1:8080/some
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET /some HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/1.2.3
> Accept: */*
> 
< HTTP/1.1 200 
< Set-Cookie: yes=it_is_possible
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 16
< Date: Mon, 15 Jul 2019 06:01:39 GMT
< 
* Curl_http_done: called premature == 0
* Connection #0 to host 127.0.0.1 left intact
Some test string   

我想,您最好发布代码来解决问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM