This commit is contained in:
k 2021-04-08 23:29:47 +08:00 committed by GitHub
commit 5d1ad85ed0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 4 deletions

View File

@ -50,6 +50,11 @@ public class ArithmeticCaptcha extends ArithmeticCaptchaAbstract {
return toBase64("data:image/png;base64,");
}
@Override
public String getContentType() {
return "image/png";
}
/**
* 生成验证码图形
*
@ -93,4 +98,4 @@ public class ArithmeticCaptcha extends ArithmeticCaptchaAbstract {
}
return false;
}
}
}

View File

@ -46,6 +46,11 @@ public class ChineseCaptcha extends ChineseCaptchaAbstract {
return toBase64("data:image/png;base64,");
}
@Override
public String getContentType() {
return "image/png";
}
/**
* 生成验证码图形
*

View File

@ -79,6 +79,11 @@ public class ChineseGifCaptcha extends ChineseCaptchaAbstract {
return toBase64("data:image/gif;base64,");
}
@Override
public String getContentType() {
return "image/gif";
}
/**
* 画随机码图
*

View File

@ -85,6 +85,11 @@ public class GifCaptcha extends Captcha {
return toBase64("data:image/gif;base64,");
}
@Override
public String getContentType() {
return "image/gif";
}
/**
* 画随机码图
*

View File

@ -50,6 +50,11 @@ public class SpecCaptcha extends Captcha {
return toBase64("data:image/png;base64,");
}
@Override
public String getContentType() {
return "image/png";
}
/**
* 生成验证码图形
*
@ -96,4 +101,4 @@ public class SpecCaptcha extends Captcha {
}
return false;
}
}
}

View File

@ -116,6 +116,13 @@ public abstract class Captcha extends Randoms {
*/
public abstract String toBase64();
/**
* 获取图片类型
*
* @return 图片格式MIME类型
*/
public abstract String getContentType();
/**
* 输出base64编码
*
@ -308,4 +315,4 @@ public abstract class Captcha extends Randoms {
public void setCharType(int charType) {
this.charType = charType;
}
}
}

View File

@ -117,6 +117,7 @@ public class CaptchaUtil {
*/
public static void out(Captcha captcha, HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType(captcha.getContentType());
setHeader(response);
request.getSession().setAttribute(SESSION_KEY, captcha.text().toLowerCase());
captcha.out(response.getOutputStream());
@ -152,7 +153,6 @@ public class CaptchaUtil {
* @param response HttpServletResponse
*/
public static void setHeader(HttpServletResponse response) {
response.setContentType("image/gif");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);