@SuppressWarnings("unchecked") public boolean parsePosted(Buf input, KeyValueRanges headersKV, BufRange rBody, KeyValueRanges posted, Map<String, List<Upload>> files, RapidoidHelper helper, Map<String, Object> dest) { BufRanges dataContentTypes = helper.ranges3.reset(); boolean completed = parseBody(input, headersKV, rBody, posted, dataContentTypes, files, helper); posted.toUrlDecodedParams(input, dest, dataContentTypes); return completed; }
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); }
@Override protected int state1(Channel ctx) { ctx.log("receiving response"); final BufRanges head = ctx.helper().ranges1.reset(); final BufRanges body = ctx.helper().ranges2.reset(); Buf in = ctx.input(); in.scanLnLn(head); Map<String, String> headers = head.toMap(in.bytes(), 1, head.count - 1, "\\s*\\:\\s*"); Map<String, String> headersLow = Msc.lowercase(headers); if ("chunked".equals(headersLow.get("transfer-encoding"))) { ctx.log("got chunked encoding"); parseChunkedBody(in, body); callback.onResult(in, head, body); } else if (headersLow.containsKey("content-length")) { ctx.log("got content length"); int clength = Integer.parseInt(headersLow.get("content-length")); parseBodyByContentLength(in, body, clength); callback.onResult(in, head, body); } else { // no content length is provided, read until connection is closed ctx.log("read until closed"); readBodyUntilClosed(ctx, body); callback.onResult(in, head, body); } ctx.log("done"); ctx.close(); // improve: keep-alive return STOP; }
public int parseHeaders(Buf buf, int from, int to, KeyValueRanges headersKV, RapidoidHelper helper) { int pos = buf.position(); int limit = buf.limit(); buf.position(from); buf.limit(to); BufRanges headers = helper.ranges2.reset(); buf.scanLnLn(headers); parseHeadersIntoKV(buf, headers, headersKV, null, helper); int bodyPos = buf.position(); buf.position(pos); buf.limit(limit); return bodyPos; }
@SuppressWarnings("unchecked") public boolean parsePosted(Buf input, KeyValueRanges headersKV, BufRange rBody, KeyValueRanges posted, Map<String, List<Upload>> files, RapidoidHelper helper, Map<String, Object> dest) { BufRanges dataContentTypes = helper.ranges3.reset(); boolean completed = parseBody(input, headersKV, rBody, posted, dataContentTypes, files, helper); posted.toUrlDecodedParams(input, dest, dataContentTypes); return completed; }
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); }
public int parseHeaders(Buf buf, int from, int to, KeyValueRanges headersKV, RapidoidHelper helper) { int pos = buf.position(); int limit = buf.limit(); buf.position(from); buf.limit(to); BufRanges headers = helper.ranges2.reset(); buf.scanLnLn(headers); parseHeadersIntoKV(buf, headers, headersKV, null, helper); int bodyPos = buf.position(); buf.position(pos); buf.limit(limit); return bodyPos; }