private boolean getKeepAliveValue(Bytes bytes, BufRange connHdr, RapidoidHelper helper) { assert bytes != null; assert connHdr != null; BufRange connVal = helper.ranges5.ranges[3]; connVal.setInterval(connHdr.start + CONNECTION.length, connHdr.limit()); BytesUtil.trim(bytes, connVal); return BytesUtil.matches(bytes, connVal, KEEP_ALIVE, false); }
private long hash(Bytes bytes, BufRange key) { int prefix = BytesUtil.getIntPrefixOf(bytes, key.start, key.limit()); return prefix * 17 + key.length * 19 + bytes.get(key.last()); }
private void detectMultipartBoundary(Buf src, BufRange body, BufRange multipartBoundary) { BytesUtil.parseLine(src.bytes(), multipartBoundary, body.start, body.limit()); multipartBoundary.strip(2, 0); }
public static boolean split(Bytes bytes, BufRange target, byte sep, BufRange before, BufRange after, boolean trimParts) { int pos = find(bytes, target.start, target.limit(), sep, true); if (pos >= 0) { before.setInterval(target.start, pos); after.setInterval(pos + 1, target.limit()); if (trimParts) { trim(bytes, before); trim(bytes, after); } return true; } else { before.assign(target); after.reset(); if (trimParts) { trim(bytes, before); } return false; } }
private void parseMultiParts(Buf src, BufRange body, KeyValueRanges data, BufRanges dataContentTypes, Map<String, List<Upload>> files, BufRange multipartBoundary, RapidoidHelper helper) { int start = body.start; int limit = body.limit(); int sepLen = multipartBoundary.length + 2; int pos1 = -1, pos2; try { while ((pos2 = BytesUtil.find(src.bytes(), start, limit, helper.bytes, 0, sepLen, true)) >= 0) { if (pos1 >= 0 && pos2 >= 0) { int from = pos1 + sepLen + 2; int to = pos2 - 2; parseMultiPart(src, data, dataContentTypes, files, helper, from, to); } pos1 = pos2; start = pos2 + sepLen; } } catch (Throwable e) { Log.warn("Multipart parse error!", e); throw U.rte("Multipart data parse error!", e); } }
private void parseURLEncodedKV(Buf buf, KeyValueRanges params, BufRange body) { int pos = buf.position(); int limit = buf.limit(); buf.position(body.start); buf.limit(body.limit()); while (buf.hasRemaining()) { int ind = params.add(); int which = buf.scanTo(EQ, AMP, params.keys[ind], false); if (which == 1) { buf.scanTo(AMP, params.values[ind], false); } } buf.position(pos); buf.limit(limit); }
private void parseBody(Buf buf, RapidoidHelper helper) { BufRanges headers = helper.headers; BufRange body = helper.body; BufRange clen = headers.getByPrefix(buf.bytes(), CONTENT_LENGTH, false); if (clen != null) { BufRange clenValue = helper.ranges5.ranges[helper.ranges5.ranges.length - 1]; clenValue.setInterval(clen.start + CONTENT_LENGTH.length, clen.limit()); BytesUtil.trim(buf.bytes(), clenValue); long len = buf.getN(clenValue); U.must(len >= 0 && len <= Integer.MAX_VALUE, "Invalid body size!"); buf.scanN((int) len, body); Log.debug("Request body complete", "range", body); } else { body.reset(); } }
private HttpContentType getContentType(Buf buf, KeyValueRanges headers, BufRange multipartBoundary) { BufRange contType = headers.get(buf, CONTENT_TYPE, false); if (contType != null) { if (BytesUtil.startsWith(buf.bytes(), contType, CT_FORM_URLENCODED, false)) { multipartBoundary.reset(); return HttpContentType.FORM_URLENCODED; } if (BytesUtil.startsWith(buf.bytes(), contType, CT_JSON, false)) { multipartBoundary.reset(); return HttpContentType.JSON; } if (BytesUtil.startsWith(buf.bytes(), contType, CT_MULTIPART_FORM_DATA_BOUNDARY1, false)) { multipartBoundary.setInterval(contType.start + CT_MULTIPART_FORM_DATA_BOUNDARY1.length, contType.limit()); return HttpContentType.MULTIPART; } if (BytesUtil.startsWith(buf.bytes(), contType, CT_MULTIPART_FORM_DATA_BOUNDARY2, false)) { multipartBoundary.setInterval(contType.start + CT_MULTIPART_FORM_DATA_BOUNDARY2.length, contType.limit()); return HttpContentType.MULTIPART; } if (BytesUtil.startsWith(buf.bytes(), contType, CT_MULTIPART_FORM_DATA, false)) { multipartBoundary.reset(); return HttpContentType.MULTIPART; } } multipartBoundary.reset(); return contType != null ? HttpContentType.OTHER : HttpContentType.NOT_FOUND; }
private boolean getKeepAliveValue(Bytes bytes, BufRange connHdr, RapidoidHelper helper) { assert bytes != null; assert connHdr != null; BufRange connVal = helper.ranges5.ranges[3]; connVal.setInterval(connHdr.start + CONNECTION.length, connHdr.limit()); BytesUtil.trim(bytes, connVal); return BytesUtil.matches(bytes, connVal, KEEP_ALIVE, false); }
private long hash(Bytes bytes, BufRange key) { int prefix = BytesUtil.getIntPrefixOf(bytes, key.start, key.limit()); return prefix * 17 + key.length * 19 + bytes.get(key.last()); }
private void detectMultipartBoundary(Buf src, BufRange body, BufRange multipartBoundary) { BytesUtil.parseLine(src.bytes(), multipartBoundary, body.start, body.limit()); multipartBoundary.strip(2, 0); }
public static boolean split(Bytes bytes, BufRange target, byte sep, BufRange before, BufRange after, boolean trimParts) { int pos = find(bytes, target.start, target.limit(), sep, true); if (pos >= 0) { before.setInterval(target.start, pos); after.setInterval(pos + 1, target.limit()); if (trimParts) { trim(bytes, before); trim(bytes, after); } return true; } else { before.assign(target); after.reset(); if (trimParts) { trim(bytes, before); } return false; } }
private void parseMultiParts(Buf src, BufRange body, KeyValueRanges data, BufRanges dataContentTypes, Map<String, List<Upload>> files, BufRange multipartBoundary, RapidoidHelper helper) { int start = body.start; int limit = body.limit(); int sepLen = multipartBoundary.length + 2; int pos1 = -1, pos2; try { while ((pos2 = BytesUtil.find(src.bytes(), start, limit, helper.bytes, 0, sepLen, true)) >= 0) { if (pos1 >= 0 && pos2 >= 0) { int from = pos1 + sepLen + 2; int to = pos2 - 2; parseMultiPart(src, data, dataContentTypes, files, helper, from, to); } pos1 = pos2; start = pos2 + sepLen; } } catch (Throwable e) { Log.warn("Multipart parse error!", e); throw U.rte("Multipart data parse error!", e); } }
private void parseURLEncodedKV(Buf buf, KeyValueRanges params, BufRange body) { int pos = buf.position(); int limit = buf.limit(); buf.position(body.start); buf.limit(body.limit()); while (buf.hasRemaining()) { int ind = params.add(); int which = buf.scanTo(EQ, AMP, params.keys[ind], false); if (which == 1) { buf.scanTo(AMP, params.values[ind], false); } } buf.position(pos); buf.limit(limit); }
private void parseBody(Buf buf, RapidoidHelper helper) { BufRanges headers = helper.headers; BufRange body = helper.body; BufRange clen = headers.getByPrefix(buf.bytes(), CONTENT_LENGTH, false); if (clen != null) { BufRange clenValue = helper.ranges5.ranges[helper.ranges5.ranges.length - 1]; clenValue.setInterval(clen.start + CONTENT_LENGTH.length, clen.limit()); BytesUtil.trim(buf.bytes(), clenValue); long len = buf.getN(clenValue); U.must(len >= 0 && len <= Integer.MAX_VALUE, "Invalid body size!"); buf.scanN((int) len, body); Log.debug("Request body complete", "range", body); } else { body.reset(); } }
private HttpContentType getContentType(Buf buf, KeyValueRanges headers, BufRange multipartBoundary) { BufRange contType = headers.get(buf, CONTENT_TYPE, false); if (contType != null) { if (BytesUtil.startsWith(buf.bytes(), contType, CT_FORM_URLENCODED, false)) { multipartBoundary.reset(); return HttpContentType.FORM_URLENCODED; } if (BytesUtil.startsWith(buf.bytes(), contType, CT_JSON, false)) { multipartBoundary.reset(); return HttpContentType.JSON; } if (BytesUtil.startsWith(buf.bytes(), contType, CT_MULTIPART_FORM_DATA_BOUNDARY1, false)) { multipartBoundary.setInterval(contType.start + CT_MULTIPART_FORM_DATA_BOUNDARY1.length, contType.limit()); return HttpContentType.MULTIPART; } if (BytesUtil.startsWith(buf.bytes(), contType, CT_MULTIPART_FORM_DATA_BOUNDARY2, false)) { multipartBoundary.setInterval(contType.start + CT_MULTIPART_FORM_DATA_BOUNDARY2.length, contType.limit()); return HttpContentType.MULTIPART; } if (BytesUtil.startsWith(buf.bytes(), contType, CT_MULTIPART_FORM_DATA, false)) { multipartBoundary.reset(); return HttpContentType.MULTIPART; } } multipartBoundary.reset(); return contType != null ? HttpContentType.OTHER : HttpContentType.NOT_FOUND; }