Commit e30aa59f by 雷紫添

增加限流空置。

parent 07e51ac9
package com.founder.common; package com.founder.common;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
public class IpADdress { public class IpADdress {
public String name; public String name;
public String code; public String code;
...@@ -19,4 +25,8 @@ public class IpADdress { ...@@ -19,4 +25,8 @@ public class IpADdress {
public void setCode(String code) { public void setCode(String code) {
this.code = code; this.code = code;
} }
public static HttpServletRequest getRequest() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
return (requestAttributes == null) ? null : ((ServletRequestAttributes) requestAttributes).getRequest();
}
} }
...@@ -2,11 +2,15 @@ package com.founder.ratelimit.guava.controller; ...@@ -2,11 +2,15 @@ package com.founder.ratelimit.guava.controller;
import cn.hutool.core.lang.Dict; import cn.hutool.core.lang.Dict;
import com.founder.common.IpADdress;
import com.founder.ratelimit.guava.annotation.RateLimiter; import com.founder.ratelimit.guava.annotation.RateLimiter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
/** /**
* <p> * <p>
* 测试 * 测试
...@@ -22,9 +26,15 @@ public class TestController { ...@@ -22,9 +26,15 @@ public class TestController {
@RateLimiter(value = 0.1) @RateLimiter(value = 0.1)
@GetMapping("/test1") @GetMapping("/test1")
public Dict test1() { public Dict test1() {
HttpServletRequest request = IpADdress.getRequest();
String key = request.getHeader("founder.authorization");
if("".equals(key)||key==null){
return Dict.create().set("msg","无权限");
}else {
log.info("【test1】被执行了。。。。。"); log.info("【test1】被执行了。。。。。");
return Dict.create().set("msg", "hello,world!").set("description", "别想一直看到我,不信你快速刷新看看~"); return Dict.create().set("msg", "hello,world!").set("description", "别想一直看到我,不信你快速刷新看看~");
} }
}
@GetMapping("/test2") @GetMapping("/test2")
public Dict test2() { public Dict test2() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment