Skip to content

Commit 05e6f69

Browse files
committed
feat: add an api to verify cookie
1 parent 62f9e61 commit 05e6f69

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

e2e/test-suite.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ items:
1717
api: /lower?text=Hello
1818
expect:
1919
body: hello
20+
21+
## Cookies
22+
- name: no-cookie
23+
request:
24+
api: /cookies/echo
25+
expect:
26+
body: cookies are empty
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.github.devopsws.demo.service;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RestController;
6+
import jakarta.servlet.http.Cookie;
7+
import jakarta.servlet.http.HttpServletRequest;
8+
9+
@RestController
10+
@RequestMapping("/cookies")
11+
public class CookieService {
12+
@GetMapping("/echo")
13+
public String cookie(HttpServletRequest request, String name) {
14+
Cookie[] cookies= request.getCookies();
15+
if (cookies == null) {
16+
return "cookies are empty";
17+
}
18+
19+
for (int i = 0; i < cookies.length; i++) {
20+
if (cookies[i].getName().equals(name)) {
21+
return cookies[i].getValue();
22+
}
23+
}
24+
25+
return "not found";
26+
}
27+
}

src/main/java/io/github/devopsws/demo/service/Health.java renamed to src/main/java/io/github/devopsws/demo/service/HealthService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.springframework.web.bind.annotation.RestController;
55

66
@RestController
7-
public class Health {
7+
public class HealthService {
88
@GetMapping("/health")
99
public String health() {
1010
return "OK";

0 commit comments

Comments
 (0)