Java 类io.netty.handler.codec.http.HttpConstants 实例源码
项目:NioImapClient
文件:LineParser.java
@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;
}
}
项目:netty4.0.27Learn
文件:HttpPostMultipartRequestDecoder.java
/**
* Clean the String from any unallowed character
*
* @return the cleaned String
*/
@SuppressWarnings("IfStatementWithIdenticalBranches")
private static String cleanString(String field) {
StringBuilder sb = new StringBuilder(field.length());
for (int i = 0; i < field.length(); i++) {
char nextChar = field.charAt(i);
if (nextChar == HttpConstants.COLON) {
sb.append(HttpConstants.SP);
} else if (nextChar == HttpConstants.COMMA) {
sb.append(HttpConstants.SP);
} else if (nextChar == HttpConstants.EQUALS) {
sb.append(HttpConstants.SP);
} else if (nextChar == HttpConstants.SEMICOLON) {
sb.append(HttpConstants.SP);
} else if (nextChar == HttpConstants.HT) {
sb.append(HttpConstants.SP);
} else if (nextChar == HttpConstants.DOUBLE_QUOTE) {
// nothing added, just removes it
} else {
sb.append(nextChar);
}
}
return sb.toString().trim();
}
项目:netty4.0.27Learn
文件:HttpPostMultipartRequestDecoder.java
/**
* 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;
}
项目:netty4study
文件:HttpPostRequestDecoder.java
/**
* 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() throws NotEnoughDataDecoderException {
int readerIndex = undecodedChunk.readerIndex();
try {
ByteBuf line = buffer(64);
while (undecodedChunk.isReadable()) {
byte nextByte = undecodedChunk.readByte();
if (nextByte == HttpConstants.CR) {
nextByte = undecodedChunk.readByte();
if (nextByte == HttpConstants.LF) {
return line.toString(charset);
}
} 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();
}
项目:netty4study
文件:HttpPostRequestDecoder.java
/**
* Clean the String from any unallowed character
*
* @return the cleaned String
*/
private static String cleanString(String field) {
StringBuilder sb = new StringBuilder(field.length());
for (int i = 0; i < field.length(); i++) {
char nextChar = field.charAt(i);
if (nextChar == HttpConstants.COLON) {
sb.append(HttpConstants.SP);
} else if (nextChar == HttpConstants.COMMA) {
sb.append(HttpConstants.SP);
} else if (nextChar == HttpConstants.EQUALS) {
sb.append(HttpConstants.SP);
} else if (nextChar == HttpConstants.SEMICOLON) {
sb.append(HttpConstants.SP);
} else if (nextChar == HttpConstants.HT) {
sb.append(HttpConstants.SP);
} else if (nextChar == HttpConstants.DOUBLE_QUOTE) {
// nothing added, just removes it
} else {
sb.append(nextChar);
}
}
return sb.toString().trim();
}
项目:netty4study
文件:HttpPostRequestDecoder.java
/**
* 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;
}
项目:netty-netty-5.0.0.Alpha1
文件:HttpPostMultipartRequestDecoder.java
/**
* 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) {
nextByte = undecodedChunk.readByte();
if (nextByte == HttpConstants.LF) {
return line.toString(charset);
}
} 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();
}
项目:netty-netty-5.0.0.Alpha1
文件:HttpPostMultipartRequestDecoder.java
/**
* Clean the String from any unallowed character
*
* @return the cleaned String
*/
private static String cleanString(String field) {
StringBuilder sb = new StringBuilder(field.length());
for (int i = 0; i < field.length(); i++) {
char nextChar = field.charAt(i);
if (nextChar == HttpConstants.COLON) {
sb.append(HttpConstants.SP);
} else if (nextChar == HttpConstants.COMMA) {
sb.append(HttpConstants.SP);
} else if (nextChar == HttpConstants.EQUALS) {
sb.append(HttpConstants.SP);
} else if (nextChar == HttpConstants.SEMICOLON) {
sb.append(HttpConstants.SP);
} else if (nextChar == HttpConstants.HT) {
sb.append(HttpConstants.SP);
} else if (nextChar == HttpConstants.DOUBLE_QUOTE) {
// nothing added, just removes it
} else {
sb.append(nextChar);
}
}
return sb.toString().trim();
}
项目:netty-netty-5.0.0.Alpha1
文件:HttpPostMultipartRequestDecoder.java
/**
* 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;
}
项目:mockserver
文件:ContentTypeMapper.java
public static Charset getCharsetFromContentTypeHeader(String contentType) {
Charset charset = DEFAULT_HTTP_CHARACTER_SET;
if (contentType != null) {
String charsetName = StringUtils.substringAfterLast(contentType, CHARSET.toString() + (char) HttpConstants.EQUALS);
if (!Strings.isNullOrEmpty(charsetName)) {
try {
charset = Charset.forName(charsetName);
} catch (UnsupportedCharsetException uce) {
MOCK_SERVER_LOGGER.info("Unsupported character set {} in Content-Type header: {}.", StringUtils.substringAfterLast(contentType, CHARSET.toString() + HttpConstants.EQUALS), contentType);
} catch (IllegalCharsetNameException icne) {
MOCK_SERVER_LOGGER.info("Illegal character set {} in Content-Type header: {}.", StringUtils.substringAfterLast(contentType, CHARSET.toString() + HttpConstants.EQUALS), contentType);
}
} else if (UTF_8_CONTENT_TYPES.contains(contentType)) {
charset = CharsetUtil.UTF_8;
}
}
return charset;
}
项目:NioImapClient
文件:ResponseDecoder.java
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);
}
项目:NioImapClient
文件:ResponseDecoder.java
/**
* 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);
}
项目:netty4.0.27Learn
文件:HttpPostMultipartRequestDecoder.java
/**
* 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();
}
项目:netty4.0.27Learn
文件:AbstractMemoryHttpData.java
@Override
public String getString(Charset encoding) {
if (byteBuf == null) {
return "";
}
if (encoding == null) {
encoding = HttpConstants.DEFAULT_CHARSET;
}
return byteBuf.toString(encoding);
}
项目:netty4study
文件:AbstractMemoryHttpData.java
@Override
public String getString(Charset encoding) {
if (byteBuf == null) {
return "";
}
if (encoding == null) {
encoding = HttpConstants.DEFAULT_CHARSET;
}
return byteBuf.toString(encoding);
}
项目:netty-netty-5.0.0.Alpha1
文件:AbstractMemoryHttpData.java
@Override
public String getString(Charset encoding) {
if (byteBuf == null) {
return "";
}
if (encoding == null) {
encoding = HttpConstants.DEFAULT_CHARSET;
}
return byteBuf.toString(encoding);
}
项目:Limitart
文件:QueryStringDecoderV2.java
public QueryStringDecoderV2(String uri) {
this(uri, HttpConstants.DEFAULT_CHARSET);
}
项目:Limitart
文件:QueryStringDecoderV2.java
public QueryStringDecoderV2(String uri, boolean hasPath) {
this(uri, HttpConstants.DEFAULT_CHARSET, hasPath);
}
项目:Limitart
文件:QueryStringDecoderV2.java
public QueryStringDecoderV2(URI uri) {
this(uri, HttpConstants.DEFAULT_CHARSET);
}
项目:NioImapClient
文件:ResponseDecoder.java
@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);
}
项目:knotx
文件:UrlEncodedBodyBuilder.java
public static String encodeBody(final MultiMap formAttributes) {
return encodeBody(formAttributes, HttpConstants.DEFAULT_CHARSET);
}
项目:reactor-netty
文件:HttpClientOperations.java
void _subscribe(CoreSubscriber<? super Long> s) {
if (!parent.markSentHeaders()) {
Operators.error(s,
new IllegalStateException("headers have already " + "been sent"));
return;
}
HttpDataFactory df = DEFAULT_FACTORY;
try {
HttpClientFormEncoder encoder = new HttpClientFormEncoder(df,
parent.nettyRequest,
false,
HttpConstants.DEFAULT_CHARSET,
HttpPostRequestEncoder.EncoderMode.RFC1738);
formCallback.accept(encoder);
encoder = encoder.applyChanges(parent.nettyRequest);
df = encoder.newFactory;
if (!encoder.isMultipart()) {
parent.chunkedTransfer(false);
}
parent.addHandlerFirst(NettyPipeline.ChunkedWriter, new ChunkedWriteHandler());
boolean chunked = HttpUtil.isTransferEncodingChunked(parent.nettyRequest);
HttpRequest r = encoder.finalizeRequest();
if (!chunked) {
HttpUtil.setTransferEncodingChunked(r, false);
HttpUtil.setContentLength(r, encoder.length());
}
ChannelFuture f = parent.channel()
.writeAndFlush(r);
Flux<Long> tail = encoder.progressFlux.onBackpressureLatest();
if (encoder.cleanOnTerminate) {
tail = tail.doOnCancel(encoder)
.doAfterTerminate(encoder);
}
if (encoder.isChunked()) {
tail.subscribe(s);
parent.channel()
.writeAndFlush(encoder);
}
else {
FutureMono.from(f)
.cast(Long.class)
.switchIfEmpty(Mono.just(encoder.length()))
.flux()
.subscribe(s);
}
}
catch (Throwable e) {
Exceptions.throwIfFatal(e);
df.cleanRequestHttpData(parent.nettyRequest);
Operators.error(s, Exceptions.unwrap(e));
}
}
项目:netty4.0.27Learn
文件:AbstractDiskHttpData.java
@Override
public String getString() throws IOException {
return getString(HttpConstants.DEFAULT_CHARSET);
}
项目:netty4.0.27Learn
文件:DiskAttribute.java
/**
* Constructor used for huge Attribute
*/
public DiskAttribute(String name) {
super(name, HttpConstants.DEFAULT_CHARSET, 0);
}
项目:netty4.0.27Learn
文件:DiskAttribute.java
public DiskAttribute(String name, String value) throws IOException {
super(name, HttpConstants.DEFAULT_CHARSET, 0); // Attribute have no default size
setValue(value);
}
项目:netty4.0.27Learn
文件:MemoryAttribute.java
public MemoryAttribute(String name) {
super(name, HttpConstants.DEFAULT_CHARSET, 0);
}
项目:netty4.0.27Learn
文件:MemoryAttribute.java
public MemoryAttribute(String name, String value) throws IOException {
super(name, HttpConstants.DEFAULT_CHARSET, 0); // Attribute have no default size
setValue(value);
}
项目:netty4.0.27Learn
文件:AbstractMemoryHttpData.java
@Override
public String getString() {
return getString(HttpConstants.DEFAULT_CHARSET);
}
项目:netty4study
文件:AbstractDiskHttpData.java
@Override
public String getString() throws IOException {
return getString(HttpConstants.DEFAULT_CHARSET);
}
项目:netty4study
文件:DiskAttribute.java
/**
* Constructor used for huge Attribute
*/
public DiskAttribute(String name) {
super(name, HttpConstants.DEFAULT_CHARSET, 0);
}
项目:netty4study
文件:DiskAttribute.java
public DiskAttribute(String name, String value) throws IOException {
super(name, HttpConstants.DEFAULT_CHARSET, 0); // Attribute have no default size
setValue(value);
}
项目:netty4study
文件:MemoryAttribute.java
public MemoryAttribute(String name) {
super(name, HttpConstants.DEFAULT_CHARSET, 0);
}
项目:netty4study
文件:MemoryAttribute.java
public MemoryAttribute(String name, String value) throws IOException {
super(name, HttpConstants.DEFAULT_CHARSET, 0); // Attribute have no default size
setValue(value);
}
项目:netty4study
文件:AbstractMemoryHttpData.java
@Override
public String getString() {
return getString(HttpConstants.DEFAULT_CHARSET);
}
项目:netty-netty-5.0.0.Alpha1
文件:AbstractDiskHttpData.java
@Override
public String getString() throws IOException {
return getString(HttpConstants.DEFAULT_CHARSET);
}
项目:netty-netty-5.0.0.Alpha1
文件:MixedAttribute.java
public MixedAttribute(String name, long limitSize) {
this(name, limitSize, HttpConstants.DEFAULT_CHARSET);
}
项目:netty-netty-5.0.0.Alpha1
文件:MixedAttribute.java
public MixedAttribute(String name, String value, long limitSize) {
this(name, value, limitSize, HttpConstants.DEFAULT_CHARSET);
}
项目:netty-netty-5.0.0.Alpha1
文件:DiskAttribute.java
/**
* Constructor used for huge Attribute
*/
public DiskAttribute(String name) {
this(name, HttpConstants.DEFAULT_CHARSET);
}
项目:netty-netty-5.0.0.Alpha1
文件:DiskAttribute.java
public DiskAttribute(String name, String value) throws IOException {
this(name, value, HttpConstants.DEFAULT_CHARSET);
}
项目:netty-netty-5.0.0.Alpha1
文件:MemoryAttribute.java
public MemoryAttribute(String name) {
this(name, HttpConstants.DEFAULT_CHARSET);
}