Java Code Examples for io.netty.util.internal.StringUtil#substringAfter()

The following examples show how to use io.netty.util.internal.StringUtil#substringAfter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpPostRequestDecoder.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
/**
 * Check from the request ContentType if this request is a Multipart request. 检查请求内容类型是否该请求是多部分请求。
 * @return an array of String if multipartDataBoundary exists with the multipartDataBoundary
 * as first element, charset if any as second (missing if not set), else null
 */
protected static String[] getMultipartDataBoundary(String contentType) {
    // Check if Post using "multipart/form-data; boundary=--89421926422648 [; charset=xxx]"
    String[] headerContentType = splitHeaderContentType(contentType);
    final String multiPartHeader = HttpHeaderValues.MULTIPART_FORM_DATA.toString();
    if (headerContentType[0].regionMatches(true, 0, multiPartHeader, 0 , multiPartHeader.length())) {
        int mrank;
        int crank;
        final String boundaryHeader = HttpHeaderValues.BOUNDARY.toString();
        if (headerContentType[1].regionMatches(true, 0, boundaryHeader, 0, boundaryHeader.length())) {
            mrank = 1;
            crank = 2;
        } else if (headerContentType[2].regionMatches(true, 0, boundaryHeader, 0, boundaryHeader.length())) {
            mrank = 2;
            crank = 1;
        } else {
            return null;
        }
        String boundary = StringUtil.substringAfter(headerContentType[mrank], '=');
        if (boundary == null) {
            throw new ErrorDataDecoderException("Needs a boundary value");
        }
        if (boundary.charAt(0) == '"') {
            String bound = boundary.trim();
            int index = bound.length() - 1;
            if (bound.charAt(index) == '"') {
                boundary = bound.substring(1, index);
            }
        }
        final String charsetHeader = HttpHeaderValues.CHARSET.toString();
        if (headerContentType[crank].regionMatches(true, 0, charsetHeader, 0, charsetHeader.length())) {
            String charset = StringUtil.substringAfter(headerContentType[crank], '=');
            if (charset != null) {
                return new String[] {"--" + boundary, charset};
            }
        }
        return new String[] {"--" + boundary};
    }
    return null;
}
 
Example 2
Source File: HttpPostRequestDecoder.java    From dorado with Apache License 2.0 5 votes vote down vote up
/**
 * Check from the request ContentType if this request is a Multipart request.
 * @return an array of String if multipartDataBoundary exists with the multipartDataBoundary
 * as first element, charset if any as second (missing if not set), else null
 */
protected static String[] getMultipartDataBoundary(String contentType) {
    // Check if Post using "multipart/form-data; boundary=--89421926422648 [; charset=xxx]"
    String[] headerContentType = splitHeaderContentType(contentType);
    final String multiPartHeader = HttpHeaderValues.MULTIPART_FORM_DATA.toString();
    if (headerContentType[0].regionMatches(true, 0, multiPartHeader, 0 , multiPartHeader.length())) {
        int mrank;
        int crank;
        final String boundaryHeader = HttpHeaderValues.BOUNDARY.toString();
        if (headerContentType[1].regionMatches(true, 0, boundaryHeader, 0, boundaryHeader.length())) {
            mrank = 1;
            crank = 2;
        } else if (headerContentType[2].regionMatches(true, 0, boundaryHeader, 0, boundaryHeader.length())) {
            mrank = 2;
            crank = 1;
        } else {
            return null;
        }
        String boundary = StringUtil.substringAfter(headerContentType[mrank], '=');
        if (boundary == null) {
            throw new ErrorDataDecoderException("Needs a boundary value");
        }
        if (boundary.charAt(0) == '"') {
            String bound = boundary.trim();
            int index = bound.length() - 1;
            if (bound.charAt(index) == '"') {
                boundary = bound.substring(1, index);
            }
        }
        final String charsetHeader = HttpHeaderValues.CHARSET.toString();
        if (headerContentType[crank].regionMatches(true, 0, charsetHeader, 0, charsetHeader.length())) {
            String charset = StringUtil.substringAfter(headerContentType[crank], '=');
            if (charset != null) {
                return new String[] {"--" + boundary, charset};
            }
        }
        return new String[] {"--" + boundary};
    }
    return null;
}
 
Example 3
Source File: HttpPostRequestDecoder.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
/**
 * Check from the request ContentType if this request is a Multipart request.
 * @return an array of String if multipartDataBoundary exists with the multipartDataBoundary
 * as first element, charset if any as second (missing if not set), else null
 */
protected static String[] getMultipartDataBoundary(String contentType) {
    // Check if Post using "multipart/form-data; boundary=--89421926422648 [; charset=xxx]"
    String[] headerContentType = splitHeaderContentType(contentType);
    if (headerContentType[0].toLowerCase().startsWith(
            HttpHeaders.Values.MULTIPART_FORM_DATA)) {
        int mrank;
        int crank;
        if (headerContentType[1].toLowerCase().startsWith(
                HttpHeaders.Values.BOUNDARY)) {
            mrank = 1;
            crank = 2;
        } else if (headerContentType[2].toLowerCase().startsWith(
                HttpHeaders.Values.BOUNDARY)) {
            mrank = 2;
            crank = 1;
        } else {
            return null;
        }
        String boundary = StringUtil.substringAfter(headerContentType[mrank], '=');
        if (boundary == null) {
            throw new ErrorDataDecoderException("Needs a boundary value");
        }
        if (boundary.charAt(0) == '"') {
            String bound = boundary.trim();
            int index = bound.length() - 1;
            if (bound.charAt(index) == '"') {
                boundary = bound.substring(1, index);
            }
        }
        if (headerContentType[crank].toLowerCase().startsWith(
                HttpHeaders.Values.CHARSET)) {
            String charset = StringUtil.substringAfter(headerContentType[crank], '=');
            if (charset != null) {
                return new String[] {"--" + boundary, charset};
            }
        }
        return new String[] {"--" + boundary};
    }
    return null;
}