Java Code Examples for io.netty.handler.codec.http.HttpConstants#CR
The following examples show how to use
io.netty.handler.codec.http.HttpConstants#CR .
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: HttpPostMultipartRequestDecoder.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
/** * Skip one empty line * * @return True if one empty line was skipped */ private boolean skipOneLine() { if (!undecodedChunk.isReadable()) { return false; } byte nextByte = undecodedChunk.readByte(); if (nextByte == HttpConstants.CR) { if (!undecodedChunk.isReadable()) { undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1); return false; } nextByte = undecodedChunk.readByte(); if (nextByte == HttpConstants.LF) { return true; } undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 2); return false; } if (nextByte == HttpConstants.LF) { return true; } undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1); return false; }
Example 2
Source File: LineParser.java From NioImapClient with Apache License 2.0 | 6 votes |
@Override public boolean process(byte value) throws Exception { char nextByte = (char) value; if (nextByte == HttpConstants.CR) { return true; } else if (nextByte == HttpConstants.LF) { return false; } else { if (size >= maxLineLength) { throw new TooLongFrameException( "Line is larger than " + maxLineLength + " bytes."); } size++; seq.append(nextByte); return true; } }
Example 3
Source File: HttpPostMultipartRequestDecoder.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
/** * Skip one empty line * * @return True if one empty line was skipped */ private boolean skipOneLine() { if (!undecodedChunk.isReadable()) { return false; } byte nextByte = undecodedChunk.readByte(); if (nextByte == HttpConstants.CR) { if (!undecodedChunk.isReadable()) { undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1); return false; } nextByte = undecodedChunk.readByte(); if (nextByte == HttpConstants.LF) { return true; } undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 2); return false; } if (nextByte == HttpConstants.LF) { return true; } undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1); return false; }
Example 4
Source File: MqttOverWebsocketProtocol.java From joyqueue with Apache License 2.0 | 6 votes |
@Override public boolean process(byte value) throws Exception { char nextByte = (char) (value & 0xFF); if (nextByte == HttpConstants.CR) { return true; } if (nextByte == HttpConstants.LF) { return false; } if (++ size > maxLength) { // TODO: Respond with Bad Request and discard the traffic // or close the connection. // No need to notify the upstream handlers - just log. // If decoding a response, just throw an exception. throw newException(maxLength); } seq.append(nextByte); return true; }
Example 5
Source File: HttpPostMultipartRequestDecoder.java From dorado with Apache License 2.0 | 6 votes |
/** * Skip one empty line * * @return True if one empty line was skipped */ private boolean skipOneLine() { if (!undecodedChunk.isReadable()) { return false; } byte nextByte = undecodedChunk.readByte(); if (nextByte == HttpConstants.CR) { if (!undecodedChunk.isReadable()) { undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1); return false; } nextByte = undecodedChunk.readByte(); if (nextByte == HttpConstants.LF) { return true; } undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 2); return false; } if (nextByte == HttpConstants.LF) { return true; } undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1); return false; }
Example 6
Source File: HttpPostMultipartRequestDecoder.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Read one line up to the CRLF or LF * * @return the String from one line * @throws NotEnoughDataDecoderException * Need more chunks and reset the {@code readerIndex} to the previous * value */ private static String readLine(ByteBuf undecodedChunk, Charset charset) { if (!undecodedChunk.hasArray()) { return readLineStandard(undecodedChunk, charset); } SeekAheadOptimize sao = new SeekAheadOptimize(undecodedChunk); int readerIndex = undecodedChunk.readerIndex(); try { ByteBuf line = buffer(64); while (sao.pos < sao.limit) { byte nextByte = sao.bytes[sao.pos++]; if (nextByte == HttpConstants.CR) { if (sao.pos < sao.limit) { nextByte = sao.bytes[sao.pos++]; if (nextByte == HttpConstants.LF) { sao.setReadPosition(0); return line.toString(charset); } else { // Write CR (not followed by LF) sao.pos--; line.writeByte(HttpConstants.CR); } } else { line.writeByte(nextByte); } } else if (nextByte == HttpConstants.LF) { sao.setReadPosition(0); return line.toString(charset); } else { line.writeByte(nextByte); } } } catch (IndexOutOfBoundsException e) { undecodedChunk.readerIndex(readerIndex); throw new NotEnoughDataDecoderException(e); } undecodedChunk.readerIndex(readerIndex); throw new NotEnoughDataDecoderException(); }
Example 7
Source File: HttpPostMultipartRequestDecoder.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
/** * Read one line up to the CRLF or LF * * @return the String from one line * @throws NotEnoughDataDecoderException * Need more chunks and reset the readerInder to the previous * value */ private String readLineStandard() { int readerIndex = undecodedChunk.readerIndex(); try { ByteBuf line = buffer(64); while (undecodedChunk.isReadable()) { byte nextByte = undecodedChunk.readByte(); if (nextByte == HttpConstants.CR) { // check but do not changed readerIndex nextByte = undecodedChunk.getByte(undecodedChunk.readerIndex()); if (nextByte == HttpConstants.LF) { // force read undecodedChunk.readByte(); return line.toString(charset); } else { // Write CR (not followed by LF) line.writeByte(HttpConstants.CR); } } else if (nextByte == HttpConstants.LF) { return line.toString(charset); } else { line.writeByte(nextByte); } } } catch (IndexOutOfBoundsException e) { undecodedChunk.readerIndex(readerIndex); throw new NotEnoughDataDecoderException(e); } undecodedChunk.readerIndex(readerIndex); throw new NotEnoughDataDecoderException(); }
Example 8
Source File: ResponseDecoder.java From NioImapClient with Apache License 2.0 | 5 votes |
/** * Reset checks to see if we are at the end of this response line. If not it fast forwards the buffer to the end of this line to prepare for the next response. * * @param in */ private void reset(ByteBuf in) { char c = (char) in.readUnsignedByte(); if (c == UNTAGGED_PREFIX || c == CONTINUATION_PREFIX || c == TAGGED_PREFIX) { // We are already at the end of the line in.readerIndex(in.readerIndex() - 1); } else if (!(c == HttpConstants.CR || c == HttpConstants.LF)) { lineParser.parse(in); } discardSomeReadBytes(); responseBuilder = new TaggedResponse.Builder(); checkpoint(State.START_RESPONSE); }
Example 9
Source File: ResponseDecoder.java From NioImapClient with Apache License 2.0 | 5 votes |
private UntaggedSearchResponse parseSearch(ByteBuf in) { List<Long> ids = new ArrayList<>(); for (; ; ) { char c = ((char) in.readUnsignedByte()); in.readerIndex(in.readerIndex() - 1); if (c == HttpConstants.CR || c == HttpConstants.LF) { lineParser.parse(in); break; } ids.add(Long.parseLong(atomOrStringParser.parse(in))); } return new UntaggedSearchResponse(ids); }
Example 10
Source File: HttpPostMultipartRequestDecoder.java From dorado with Apache License 2.0 | 5 votes |
/** * Load the field value or file data from a Multipart request * * @return {@code true} if the last chunk is loaded (boundary delimiter found), * {@code false} if need more chunks * @throws ErrorDataDecoderException */ private static boolean loadDataMultipartStandard(ByteBuf undecodedChunk, String delimiter, HttpData httpData) { final int startReaderIndex = undecodedChunk.readerIndex(); final int delimeterLength = delimiter.length(); int index = 0; int lastPosition = startReaderIndex; byte prevByte = HttpConstants.LF; boolean delimiterFound = false; while (undecodedChunk.isReadable()) { final byte nextByte = undecodedChunk.readByte(); // Check the delimiter if (prevByte == HttpConstants.LF && nextByte == delimiter.codePointAt(index)) { index++; if (delimeterLength == index) { delimiterFound = true; break; } continue; } lastPosition = undecodedChunk.readerIndex(); if (nextByte == HttpConstants.LF) { index = 0; lastPosition -= (prevByte == HttpConstants.CR) ? 2 : 1; } prevByte = nextByte; } if (prevByte == HttpConstants.CR) { lastPosition--; } ByteBuf content = undecodedChunk.copy(startReaderIndex, lastPosition - startReaderIndex); try { httpData.addContent(content, delimiterFound); } catch (IOException e) { throw new ErrorDataDecoderException(e); } undecodedChunk.readerIndex(lastPosition); return delimiterFound; }
Example 11
Source File: HttpPostMultipartRequestDecoder.java From dorado with Apache License 2.0 | 5 votes |
/** * Read one line up to the CRLF or LF * * @return the String from one line * @throws NotEnoughDataDecoderException Need more chunks and reset the * {@code readerIndex} to the previous * value */ private static String readLine(ByteBuf undecodedChunk, Charset charset) { if (!undecodedChunk.hasArray()) { return readLineStandard(undecodedChunk, charset); } SeekAheadOptimize sao = new SeekAheadOptimize(undecodedChunk); int readerIndex = undecodedChunk.readerIndex(); try { ByteBuf line = buffer(64); while (sao.pos < sao.limit) { byte nextByte = sao.bytes[sao.pos++]; if (nextByte == HttpConstants.CR) { if (sao.pos < sao.limit) { nextByte = sao.bytes[sao.pos++]; if (nextByte == HttpConstants.LF) { sao.setReadPosition(0); return line.toString(charset); } else { // Write CR (not followed by LF) sao.pos--; line.writeByte(HttpConstants.CR); } } else { line.writeByte(nextByte); } } else if (nextByte == HttpConstants.LF) { sao.setReadPosition(0); return line.toString(charset); } else { line.writeByte(nextByte); } } } catch (IndexOutOfBoundsException e) { undecodedChunk.readerIndex(readerIndex); throw new NotEnoughDataDecoderException(e); } undecodedChunk.readerIndex(readerIndex); throw new NotEnoughDataDecoderException(); }
Example 12
Source File: HttpPostMultipartRequestDecoder.java From dorado with Apache License 2.0 | 5 votes |
/** * Read one line up to the CRLF or LF * * @return the String from one line * @throws NotEnoughDataDecoderException Need more chunks and reset the * {@code readerIndex} to the previous * value */ private static String readLineStandard(ByteBuf undecodedChunk, Charset charset) { int readerIndex = undecodedChunk.readerIndex(); try { ByteBuf line = buffer(64); while (undecodedChunk.isReadable()) { byte nextByte = undecodedChunk.readByte(); if (nextByte == HttpConstants.CR) { // check but do not changed readerIndex nextByte = undecodedChunk.getByte(undecodedChunk.readerIndex()); if (nextByte == HttpConstants.LF) { // force read undecodedChunk.readByte(); return line.toString(charset); } else { // Write CR (not followed by LF) line.writeByte(HttpConstants.CR); } } else if (nextByte == HttpConstants.LF) { return line.toString(charset); } else { line.writeByte(nextByte); } } } catch (IndexOutOfBoundsException e) { undecodedChunk.readerIndex(readerIndex); throw new NotEnoughDataDecoderException(e); } undecodedChunk.readerIndex(readerIndex); throw new NotEnoughDataDecoderException(); }
Example 13
Source File: HttpPostMultipartRequestDecoder.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Load the field value or file data from a Multipart request 从多部分请求加载字段值或文件数据 * * @return {@code true} if the last chunk is loaded (boundary delimiter found), {@code false} if need more chunks * @throws ErrorDataDecoderException */ private static boolean loadDataMultipartStandard(ByteBuf undecodedChunk, String delimiter, HttpData httpData) { final int startReaderIndex = undecodedChunk.readerIndex(); final int delimeterLength = delimiter.length(); int index = 0; int lastPosition = startReaderIndex; byte prevByte = HttpConstants.LF; boolean delimiterFound = false; while (undecodedChunk.isReadable()) { final byte nextByte = undecodedChunk.readByte(); // Check the delimiter if (prevByte == HttpConstants.LF && nextByte == delimiter.codePointAt(index)) { index++; if (delimeterLength == index) { delimiterFound = true; break; } continue; } lastPosition = undecodedChunk.readerIndex(); if (nextByte == HttpConstants.LF) { index = 0; lastPosition -= (prevByte == HttpConstants.CR)? 2 : 1; } prevByte = nextByte; } if (prevByte == HttpConstants.CR) { lastPosition--; } ByteBuf content = undecodedChunk.copy(startReaderIndex, lastPosition - startReaderIndex); try { httpData.addContent(content, delimiterFound); } catch (IOException e) { throw new ErrorDataDecoderException(e); } undecodedChunk.readerIndex(lastPosition); return delimiterFound; }
Example 14
Source File: HttpPostMultipartRequestDecoder.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Read one line up to the CRLF or LF * * @return the String from one line * @throws NotEnoughDataDecoderException * Need more chunks and reset the {@code readerIndex} to the previous * value */ private static String readLineStandard(ByteBuf undecodedChunk, Charset charset) { int readerIndex = undecodedChunk.readerIndex(); try { ByteBuf line = buffer(64); while (undecodedChunk.isReadable()) { byte nextByte = undecodedChunk.readByte(); if (nextByte == HttpConstants.CR) { // check but do not changed readerIndex nextByte = undecodedChunk.getByte(undecodedChunk.readerIndex()); if (nextByte == HttpConstants.LF) { // force read undecodedChunk.readByte(); return line.toString(charset); } else { // Write CR (not followed by LF) line.writeByte(HttpConstants.CR); } } else if (nextByte == HttpConstants.LF) { return line.toString(charset); } else { line.writeByte(nextByte); } } } catch (IndexOutOfBoundsException e) { undecodedChunk.readerIndex(readerIndex); throw new NotEnoughDataDecoderException(e); } undecodedChunk.readerIndex(readerIndex); throw new NotEnoughDataDecoderException(); }
Example 15
Source File: HttpPostMultipartRequestDecoder.java From dorado with Apache License 2.0 | 4 votes |
/** * Load the field value from a Multipart request * * @return {@code true} if the last chunk is loaded (boundary delimiter found), * {@code false} if need more chunks * @throws ErrorDataDecoderException */ private static boolean loadDataMultipart(ByteBuf undecodedChunk, String delimiter, HttpData httpData) { if (!undecodedChunk.hasArray()) { return loadDataMultipartStandard(undecodedChunk, delimiter, httpData); } final SeekAheadOptimize sao = new SeekAheadOptimize(undecodedChunk); final int startReaderIndex = undecodedChunk.readerIndex(); final int delimeterLength = delimiter.length(); int index = 0; int lastRealPos = sao.pos; byte prevByte = HttpConstants.LF; boolean delimiterFound = false; while (sao.pos < sao.limit) { final byte nextByte = sao.bytes[sao.pos++]; // Check the delimiter if (prevByte == HttpConstants.LF && nextByte == delimiter.codePointAt(index)) { index++; if (delimeterLength == index) { delimiterFound = true; break; } continue; } lastRealPos = sao.pos; if (nextByte == HttpConstants.LF) { index = 0; lastRealPos -= (prevByte == HttpConstants.CR) ? 2 : 1; } prevByte = nextByte; } if (prevByte == HttpConstants.CR) { lastRealPos--; } final int lastPosition = sao.getReadPosition(lastRealPos); final ByteBuf content = undecodedChunk.copy(startReaderIndex, lastPosition - startReaderIndex); try { httpData.addContent(content, delimiterFound); } catch (IOException e) { throw new ErrorDataDecoderException(e); } undecodedChunk.readerIndex(lastPosition); return delimiterFound; }
Example 16
Source File: ResponseDecoder.java From NioImapClient with Apache License 2.0 | 4 votes |
@Timed private void parseFetch(ByteBuf in) throws UnknownFetchItemTypeException, IOException, ResponseParseException { skipControlCharacters(in); char next = ((char) in.readUnsignedByte()); if (next != LPAREN && next != RPAREN) { in.readerIndex(in.readerIndex() - 1); } else if (next == RPAREN) { // Check to see if this is the end of this fetch response char second = ((char) in.readUnsignedByte()); if (second == HttpConstants.CR || second == HttpConstants.LF) { // At the end of the fetch, add the current message to the untagged responses and reset messageComplete(); return; } else { in.readerIndex(in.readerIndex() - 2); } } String fetchItemString = fetchResponseTypeParser.parse(in); if (StringUtils.isBlank(fetchItemString)) { checkpoint(State.FETCH); return; } FetchDataItemType fetchType = FetchDataItemType.getFetchType(fetchItemString); switch (fetchType) { case FLAGS: List<String> flags = nestedArrayParserRecycler.get().parse(in).stream() .map(o -> ((String) o)) .collect(Collectors.toList()); currentMessage.setFlagStrings(flags); break; case INTERNALDATE: String internalDate = atomOrStringParser.parse(in); currentMessage.setInternalDate(internalDate); break; case RFC822_SIZE: currentMessage.setSize(Ints.checkedCast(numberParser.parse(in))); break; case UID: currentMessage.setUid(numberParser.parse(in)); break; case ENVELOPE: currentMessage.setEnvelope(parseEnvelope(in)); break; case BODY: startBodyParse(in); return; case X_GM_MSGID: currentMessage.setGmailMessageId(numberParser.parse(in)); break; case X_GM_THRID: currentMessage.setGmailThreadId(numberParser.parse(in)); break; case X_GM_LABELS: currentMessage.setGMailLabels( nestedArrayParserRecycler.get().parse(in).stream() .filter(o -> !(o instanceof NilMarker)) .map(o -> ((String) o)) .map(GMailLabel::get) .collect(Collectors.toSet()) ); break; case INVALID: default: throw new UnknownFetchItemTypeException(fetchItemString); } checkpoint(State.FETCH); }
Example 17
Source File: HttpPostMultipartRequestDecoder.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
/** * Load the field value from a Multipart request 从多部分请求加载字段值 * * @return {@code true} if the last chunk is loaded (boundary delimiter found), {@code false} if need more chunks * @throws ErrorDataDecoderException */ private static boolean loadDataMultipart(ByteBuf undecodedChunk, String delimiter, HttpData httpData) { if (!undecodedChunk.hasArray()) { return loadDataMultipartStandard(undecodedChunk, delimiter, httpData); } final SeekAheadOptimize sao = new SeekAheadOptimize(undecodedChunk); final int startReaderIndex = undecodedChunk.readerIndex(); final int delimeterLength = delimiter.length(); int index = 0; int lastRealPos = sao.pos; byte prevByte = HttpConstants.LF; boolean delimiterFound = false; while (sao.pos < sao.limit) { final byte nextByte = sao.bytes[sao.pos++]; // Check the delimiter if (prevByte == HttpConstants.LF && nextByte == delimiter.codePointAt(index)) { index++; if (delimeterLength == index) { delimiterFound = true; break; } continue; } lastRealPos = sao.pos; if (nextByte == HttpConstants.LF) { index = 0; lastRealPos -= (prevByte == HttpConstants.CR)? 2 : 1; } prevByte = nextByte; } if (prevByte == HttpConstants.CR) { lastRealPos--; } final int lastPosition = sao.getReadPosition(lastRealPos); final ByteBuf content = undecodedChunk.copy(startReaderIndex, lastPosition - startReaderIndex); try { httpData.addContent(content, delimiterFound); } catch (IOException e) { throw new ErrorDataDecoderException(e); } undecodedChunk.readerIndex(lastPosition); return delimiterFound; }
Example 18
Source File: HttpPostMultipartRequestDecoder.java From netty4.0.27Learn with Apache License 2.0 | 4 votes |
/** * Read one line up to the CRLF or LF * * @return the String from one line * @throws NotEnoughDataDecoderException * Need more chunks and reset the readerInder to the previous * value */ private String readLine() { SeekAheadOptimize sao; try { sao = new SeekAheadOptimize(undecodedChunk); } catch (SeekAheadNoBackArrayException ignored) { return readLineStandard(); } int readerIndex = undecodedChunk.readerIndex(); try { ByteBuf line = buffer(64); while (sao.pos < sao.limit) { byte nextByte = sao.bytes[sao.pos++]; if (nextByte == HttpConstants.CR) { if (sao.pos < sao.limit) { nextByte = sao.bytes[sao.pos++]; if (nextByte == HttpConstants.LF) { sao.setReadPosition(0); return line.toString(charset); } else { // Write CR (not followed by LF) sao.pos--; line.writeByte(HttpConstants.CR); } } else { line.writeByte(nextByte); } } else if (nextByte == HttpConstants.LF) { sao.setReadPosition(0); return line.toString(charset); } else { line.writeByte(nextByte); } } } catch (IndexOutOfBoundsException e) { undecodedChunk.readerIndex(readerIndex); throw new NotEnoughDataDecoderException(e); } undecodedChunk.readerIndex(readerIndex); throw new NotEnoughDataDecoderException(); }