提交 | 用户 | 时间
|
a6de49
|
1 |
package com.iailab.module.data.common.utils; |
H |
2 |
|
|
3 |
import org.springframework.web.context.request.RequestContextHolder; |
|
4 |
import org.springframework.web.context.request.ServletRequestAttributes; |
|
5 |
|
|
6 |
import javax.servlet.http.HttpServletRequest; |
|
7 |
|
|
8 |
public class HttpContextUtils { |
|
9 |
|
|
10 |
public static HttpServletRequest getHttpServletRequest() { |
|
11 |
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
|
12 |
} |
|
13 |
|
|
14 |
public static String getDomain(){ |
|
15 |
HttpServletRequest request = getHttpServletRequest(); |
|
16 |
StringBuffer url = request.getRequestURL(); |
|
17 |
return url.delete(url.length() - request.getRequestURI().length(), url.length()).toString(); |
|
18 |
} |
|
19 |
|
|
20 |
public static String getOrigin(){ |
|
21 |
HttpServletRequest request = getHttpServletRequest(); |
|
22 |
return request.getHeader("Origin"); |
|
23 |
} |
|
24 |
} |