protected HttpParser createParser() { return new HttpParser(); }
public void parse(Buf buf, RapidoidHelper helper) { Bytes bytes = buf.bytes(); BufRange protocol = helper.protocol; BufRanges headers = helper.headers; buf.scanUntil(SPACE, helper.verb); buf.scanUntil(SPACE, helper.uri); buf.scanLn(protocol); helper.isKeepAlive.value = detectKeepAlive(buf, helper, bytes, protocol, headers); BytesUtil.split(bytes, helper.uri, ASTERISK, helper.path, helper.query, false); helper.isGet.value = BytesUtil.matches(bytes, helper.verb, GET, true); if (!helper.isGet.value) { parseBody(buf, helper); } }
HttpContentType contentType = getContentType(src, headers, multipartBoundary); detectMultipartBoundary(src, body, multipartBoundary); parseMultiParts(src, body, data, dataContentTypes, autoFiles, multipartBoundary, helper); files.putAll(autoFiles); byte bodyStart = src.get(body.start); if (bodyStart != '{' && bodyStart != '[' && bodyStart != '<') { // not json nor xml parseURLEncodedKV(src, data, body); return true; } else {
BufRange charset = helper.ranges4.ranges[7]; int bodyPos = parseHeaders(src, from, to, headers, helper); partBody.setInterval(bodyPos, to); if (!parseDisposition(src, dispo1, dispo2, name, filename)) { if (!parseDisposition(src, dispo2, dispo1, name, filename)) { throw U.rte("Unrecognized Content-disposition header!"); checkCharset(src, contType, contEnc, charset, contentType);
@Override @SuppressWarnings("unchecked") public void process(Channel channel) { if (channel.isInitial()) { processor.waitToInitialize(); return; } Buf buf = channel.input(); RapidoidHelper helper = channel.helper(); HTTP_PARSER.parse(buf, helper); processor.onRequest(channel, helper); }
@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 isKeepAlive(Bytes bytes, BufRanges headers, RapidoidHelper helper, boolean keepAliveByDefault) { BufRange connHdr = headers.getByPrefix(bytes, CONNECTION, false); return connHdr != null ? getKeepAliveValue(bytes, connHdr, helper) : keepAliveByDefault; }
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); }
BufRange charset = helper.ranges4.ranges[7]; int bodyPos = parseHeaders(src, from, to, headers, helper); partBody.setInterval(bodyPos, to); if (!parseDisposition(src, dispo1, dispo2, name, filename)) { if (!parseDisposition(src, dispo2, dispo1, name, filename)) { throw U.rte("Unrecognized Content-disposition header!"); checkCharset(src, contType, contEnc, charset, contentType);
@Override public void process(Channel ctx) { if (ctx.isInitial()) { return; } Buf buf = ctx.input(); RapidoidHelper data = ctx.helper(); HTTP_PARSER.parse(buf, data); boolean keepAlive = data.isKeepAlive.value; HttpStatus status = handle(ctx, buf, data); switch (status) { case DONE: ctx.closeIf(!keepAlive); break; case NOT_FOUND: ctx.write(HTTP_404); ctx.closeIf(!keepAlive); break; case ERROR: ctx.write(HTTP_500); ctx.closeIf(!keepAlive); break; case ASYNC: // do nothing break; } }
@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 isKeepAlive(Bytes bytes, BufRanges headers, RapidoidHelper helper, boolean keepAliveByDefault) { BufRange connHdr = headers.getByPrefix(bytes, CONNECTION, false); return connHdr != null ? getKeepAliveValue(bytes, connHdr, helper) : keepAliveByDefault; }
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); }
HttpContentType contentType = getContentType(src, headers, multipartBoundary); detectMultipartBoundary(src, body, multipartBoundary); parseMultiParts(src, body, data, dataContentTypes, autoFiles, multipartBoundary, helper); files.putAll(autoFiles); byte bodyStart = src.get(body.start); if (bodyStart != '{' && bodyStart != '[' && bodyStart != '<') { // not json nor xml parseURLEncodedKV(src, data, body); return true; } else {
public void parse(Buf buf, RapidoidHelper helper) { Bytes bytes = buf.bytes(); BufRange protocol = helper.protocol; BufRanges headers = helper.headers; buf.scanUntil(SPACE, helper.verb); buf.scanUntil(SPACE, helper.uri); buf.scanLn(protocol); helper.isKeepAlive.value = detectKeepAlive(buf, helper, bytes, protocol, headers); BytesUtil.split(bytes, helper.uri, ASTERISK, helper.path, helper.query, false); helper.isGet.value = BytesUtil.matches(bytes, helper.verb, GET, true); if (!helper.isGet.value) { parseBody(buf, helper); } }
@Override @SuppressWarnings("unchecked") public void process(Channel channel) { if (channel.isInitial()) { processor.waitToInitialize(); return; } Buf buf = channel.input(); RapidoidHelper helper = channel.helper(); HTTP_PARSER.parse(buf, helper); processor.onRequest(channel, helper); }
protected HttpParser createParser() { return new HttpParser(); }
@Override public void process(Channel ctx) { if (ctx.isInitial()) { return; } Buf buf = ctx.input(); RapidoidHelper data = ctx.helper(); HTTP_PARSER.parse(buf, data); boolean keepAlive = data.isKeepAlive.value; HttpStatus status = handle(ctx, buf, data); switch (status) { case DONE: ctx.closeIf(!keepAlive); break; case NOT_FOUND: ctx.write(HTTP_404); ctx.closeIf(!keepAlive); break; case ERROR: ctx.write(HTTP_500); ctx.closeIf(!keepAlive); break; case ASYNC: // do nothing break; } }