public Map<String, byte[]> toBinaryMap(Buf src, boolean urlDecodeKeys) { Map<String, byte[]> map = U.map(); for (int i = 0; i < count; i++) { String key = keys[i].str(src.bytes()); byte[] val = values[i].bytes(src); if (urlDecodeKeys) { key = URIs.urlDecodeOrKeepOriginal(key); } map.put(key, val); } return map; }
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; } }
@Override public String toString() { return isEmpty() ? "[]" : "[" + start + ":" + length + "]"; }
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); }
partBody.setInterval(bodyPos, to); disposition.strip(FORM_DATA.length, 0); } else { return; contType.reset(); contEnc.reset(); if (filename.isEmpty()) { int ind = data.add(); data.keys[ind].assign(name); data.values[ind].assign(partBody); String uploadParamName = src.get(name); String uploadFilename = src.get(filename); byte[] uploadContent = partBody.bytes(src); files.get(uploadParamName).add(new Upload(uploadFilename, uploadContent));
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; }
b0 = bytes.get(p); if (b0 == LF) { result.set(fromPos, 0); return p + 1; result.reset(); return NOT_FOUND; if (b1 == LF) { if (b0 == CR) { result.set(fromPos, 0); } else { result.set(fromPos, 1); result.reset(); return NOT_FOUND; if (b2 == LF) { if (b1 == CR) { result.set(fromPos, 1); } else { result.set(fromPos, 2); result.reset(); return NOT_FOUND; if (b3 == LF) { if (b2 == CR) { result.set(fromPos, 2);
boolean pendingBodyParsing = false; if (!isGet && !helper.body.isEmpty()) { KeyValueRanges postedKV = helper.pairs3.reset(); body = helper.body.bytes(buf); String verb = helper.verb.str(buf); String uri = helper.uri.str(buf); String path = URIs.urlDecode(helper.path.str(buf)); String query = URIs.urlDecodeOrKeepOriginal(helper.query.str(buf));
public Map<String, String> toMap(Bytes bytes, int from, int to, String separator) { Map<String, String> map = U.map(); for (int i = from; i <= to; i++) { String s = ranges[i].str(bytes); String[] kv = s.split(separator, 2); map.put(kv[0], kv.length > 1 ? kv[1] : ""); } return map; }
private boolean parseDisposition(Buf src, BufRange dispoA, BufRange dispoB, BufRange name, BufRange filename) { if (BytesUtil.startsWith(src.bytes(), dispoA, NAME_EQ, false)) { name.assign(dispoA); name.strip(NAME_EQ.length, 0); BytesUtil.trim(src.bytes(), name); name.strip(1, 1); if (BytesUtil.startsWith(src.bytes(), dispoB, FILENAME_EQ, false)) { filename.assign(dispoB); filename.strip(FILENAME_EQ.length, 0); BytesUtil.trim(src.bytes(), filename); filename.strip(1, 1); } else { filename.reset(); } return true; } return false; }
void removeTrailingSlash(Buf buf, BufRange range) { if (range.length > 1 && buf.get(range.last()) == '/') { range.length--; } }
private boolean detectKeepAlive(Buf buf, RapidoidHelper helper, Bytes bytes, BufRange protocol, BufRanges headers) { IntWrap result = helper.integers[0]; boolean keepAliveByDefault = protocol.isEmpty() || bytes.get(protocol.last()) != '0'; // e.g. HTTP/1.1 // try to detect the opposite of the default if (keepAliveByDefault) { buf.scanLnLn(headers.reset(), result, (byte) 's', (byte) 'e'); // clo[se] } else { buf.scanLnLn(headers.reset(), result, (byte) 'v', (byte) 'e'); // keep-ali[ve] } int possibleConnHeaderPos = result.value; if (possibleConnHeaderPos < 0) return keepAliveByDefault; // no evidence of the opposite BufRange possibleConnHdr = headers.get(possibleConnHeaderPos); if (BytesUtil.startsWith(bytes, possibleConnHdr, CONNECTION, true)) { return !keepAliveByDefault; // detected the opposite of the default } return isKeepAlive(bytes, headers, helper, keepAliveByDefault); }
private void consumeAndSkip(int toPos, BufRange range, int skip) { range.setInterval(_position, toPos); _position = toPos + skip; }
private void checkCharset(Buf src, BufRange contType, BufRange contEnc, BufRange charset, BufRange contentType) { if (contentType != null) { BytesUtil.split(src.bytes(), contentType, SEMI_COL, contType, contEnc, true); if (BytesUtil.startsWith(src.bytes(), contEnc, CHARSET_EQ, false)) { charset.assign(contEnc); charset.strip(CHARSET_EQ.length, 0); BytesUtil.trim(src.bytes(), charset); if (!BytesUtil.matches(src.bytes(), charset, _UTF_8, false) && !BytesUtil.matches(src.bytes(), charset, _ISO_8859_1, false)) { Log.warn("Tipically the UTF-8 and ISO-8859-1 charsets are expected, but received different!", "charset", src.get(charset)); } } } }
public BufRanges reset() { for (int i = 0; i < count; i++) { ranges[i].reset(); } count = 0; return this; }