[英]Set-Cookie header is removed from response, Spring boot
I have simple @RestController and im trying to add cookies but I don't see it in the response. 我有简单的@RestController,我正在尝试添加Cookie,但在响应中看不到它。 Adding any other response header works just fine, but if I use .addCookie() or .addHeader("Set-Cookie", "something") its being filtered out. 添加任何其他响应标头都可以,但是如果我使用.addCookie()或.addHeader(“ Set-Cookie”,“ something”),则会将其过滤掉。 Further no custom filters are implemented. 此外,没有实现自定义过滤器。
How can I disable this and add cookie to response? 如何禁用此功能并将Cookie添加到响应中?
Spring security configuration: Spring安全配置:
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.authorizeRequests()
.anyRequest()
.permitAll();
Controller code: 控制器代码:
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";
}
}
After launch the application, custom cookie works OK: 启动应用程序后,自定义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
I guess, you should better post your code to solve the issue 我想,您最好发布代码来解决问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.