current position:Home>Tool class for obtaining specific information in HTTP request
Tool class for obtaining specific information in HTTP request
2022-04-29 08:45:56【White Java notes】
package com.zeekr.hr.recruitment.share.util;
import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;
/**
* @author xxx
* @date 2020/9/2 from http request Tool class for obtaining specific information in
*/
public class RequestInfoUtil {
private static final String TOKEN_HEADER_KEY = "Authorization";
private static final String REFERER_HEADER_KEY = "Referer";
private static final String ORIGIN_HEADER_KEY = "Origin";
private static final String SOURCE_TYPE_HEADER_KEY = "source-type";
private static final String APP_HEADER_KEY = "userId";
private static final String SIGNATURE_HEADER_KEY = "signature";
public static String getToken(HttpServletRequest request) {
// String token = request.getHeader(TOKEN_HEADER_KEY);
Cookie[] cookies = request.getCookies();
String token = "";
if (Objects.nonNull(cookies)&&cookies.length>0){
for (Cookie cookie : cookies) {
switch(cookie.getName()){
case "Authorization":
token = cookie.getValue();
if (StringUtils.isBlank(token)) {
continue;
}
break;
default:
break;
}
}
}
if (StringUtils.isBlank(token)){
token = request.getHeader(TOKEN_HEADER_KEY);
}
return token;
}
public static String getRefererHeader(HttpServletRequest request) {
String referer = request.getHeader(REFERER_HEADER_KEY);
return referer;
}
public static String getOriginHeader(HttpServletRequest request){
return request.getHeader(ORIGIN_HEADER_KEY);
}
public static String getSourceType(HttpServletRequest request, HttpServletResponse response) {
if (request.getMethod().equals("OPTIONS")) {
response.setStatus(HttpServletResponse.SC_OK);
}
String sourceType = request.getHeader(SOURCE_TYPE_HEADER_KEY);
return sourceType;
}
public static String getAppId(HttpServletRequest request) {
String referer = request.getHeader(APP_HEADER_KEY);
return referer;
}
public static String getSignature(HttpServletRequest request) {
String referer = request.getHeader(SIGNATURE_HEADER_KEY);
return referer;
}
}
copyright notice
author[White Java notes],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204290618309156.html
The sidebar is recommended
- How to configure Vue in Vue project config. JS to solve cross domain problems
- Centos6 makes nginx-1.21.6-rpm package -- the way to build a dream
- [vue2-sgg v] vuex
- [vue2-sgg vi] route Vue router guard
- [vue2-sgg VII] Vue export and deploy to nginx --- UI component library (element UI...)
- Chapter 12 Ajax
- Clion remote debugging ubutun server, blood lessons
- The latest vue-i18n international plug-in realizes language switching (with source code)
- Vue monitors watch usage
- Vue encapsulates Axios to the full version of the calling interface (code source code)
guess what you like
Watch data monitoring in Vue and detailed explanation of various attributes in watch
Vue encapsulates Axios to call interface Full Version (code source code) latest recommendation (II)
Vue encapsulates Axios to the full version of the calling interface (code source code)
Ajax usage based on JQ
Vue project optimization
Vue - form generator form code generation
Data acquisition in vuex is assigned to the local problem, and when is vuex data assigned to the local problem
The modal box component is encapsulated in Vue, and the animation effect in Vue
Swiper, the application of swiper in Vue, and various versions of swiper are applied in Vue projects
Python——ReadTimeoutError: HTTPSConnectionPool(host=‘files.pythonhosted.org‘, port=443)
Random recommended
- Lesson 3 of ROS quick start - subscriber subscriber of ROS
- A lifeless face
- Mock in Vue JS preliminary simple use
- The Java Web servlet triggers the alert box on the front end
- CSS sets the color of the small vertical bar in front of the title
- Incomplete display of CSS background image
- [front end learning notes] save the front-end related codes
- Precautions for AWS serverless design dynamodb
- AWS serverless design - apigateway
- AWS serverless design lambda
- AWS serverless design - firewall WAF
- AWS serverless design-s3
- Python repeated element determination function program
- Nginx direction agent solves cross domain Problems-2
- The foundation of JavaScript
- DOM based on JavaScript
- Javascript based BOM
- JavaScript advanced functions
- Basic summary of JavaScript advanced
- Object oriented JavaScript
- JavaScript advanced threading mechanism and event mechanism
- HTML+CSS
- Introduction to less
- CSS3 media query
- Learn about bootstrap
- JQuery learning
- Ajax case
- Ajax sends a post request
- Ajax sends get requests
- Ajax notes
- Ajax learning notes
- Relearn react (1) - recognize the life cycle
- Small problems encountered by react usereducer and Solutions
- CSS realizes the square of adaptive screen width
- Nginx + ModSecurity setup
- Bootstrap web job
- bootstrap
- Swoft 2. X Foundation (HTTP, database, redis)
- Docker actual combat case 2: nginx load balancing
- Vue basic syntax