| | |
| | | package com.ruoyi.common.filter; |
| | | |
| | | import cn.hutool.core.io.IoUtil; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HtmlUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | |
| | |
| | | |
| | | // 为空,直接返回 |
| | | String json = IoUtil.read(super.getInputStream(), StandardCharsets.UTF_8); |
| | | if (Validator.isEmpty(json)) |
| | | if (StringUtils.isEmpty(json)) |
| | | { |
| | | return super.getInputStream(); |
| | | } |
| | | |
| | | // xss过滤 |
| | | json = HtmlUtil.cleanHtmlTag(json).trim(); |
| | | |
| | | final ByteArrayInputStream bis = IoUtil.toStream(json, StandardCharsets.UTF_8); |
| | | byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8); |
| | | final ByteArrayInputStream bis = IoUtil.toStream(jsonBytes); |
| | | return new ServletInputStream() |
| | | { |
| | | @Override |
| | |
| | | public boolean isReady() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public int available() throws IOException |
| | | { |
| | | return jsonBytes.length; |
| | | } |
| | | |
| | | @Override |
| | |
| | | public boolean isJsonRequest() |
| | | { |
| | | String header = super.getHeader(HttpHeaders.CONTENT_TYPE); |
| | | return StrUtil.startWithIgnoreCase(header, MediaType.APPLICATION_JSON_VALUE); |
| | | return StringUtils.startsWithIgnoreCase(header, MediaType.APPLICATION_JSON_VALUE); |
| | | } |
| | | } |
| | | } |