com.github.liuanxin.api.util.Requests Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api-document Show documentation
Show all versions of api-document Show documentation
Collect api document, support to spring mvc
package com.github.liuanxin.api.util;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
public final class Requests {
public static String getDomain() {
HttpServletRequest request = getRequestAttributes().getRequest();
String scheme = request.getScheme();
int port = request.getServerPort();
StringBuilder sbd = new StringBuilder();
// sbd.append(scheme).append(":");
sbd.append("//").append(request.getServerName());
boolean notHttp = ("http".equalsIgnoreCase(scheme) && port != 80);
boolean notHttps = ("https".equalsIgnoreCase(scheme) && port != 443 && port != 80);
if (notHttp || notHttps) {
sbd.append(':').append(port);
}
return sbd.toString();
}
private static ServletRequestAttributes getRequestAttributes() {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy