java header类_Java HttpHeaderUtil类代码示例

import io.netty.handler.codec.http.HttpHeaderUtil; //导入依赖的package包/类

@Override

protected void decode(ChannelHandlerContext ctx, FullHttpRequest request, List out) throws Exception {

// Handle a bad request.

if (!request.decoderResult().isSuccess()) {

sendHttpResponse(ctx, request, new DefaultFullHttpResponse(HTTP_1_1, BAD_REQUEST));

return;

}

if ("websocket".equalsIgnoreCase((String) request.headers().get("Upgrade"))) {

handleWebSocket(ctx, request);

return;

}

String queryStr = request.uri();

if ("/favicon.ico".equals(queryStr)) {

FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, NOT_FOUND);

sendHttpResponse(ctx, request, res);

return;

}

if (queryStr != null) {

queryStr = queryStr.trim();

if (queryStr.length() > 0 && queryStr.charAt(0) == '/') {

if (queryStr.length() == 1) {

queryStr = "";

} else {

int wh = queryStr.indexOf('?');

if (wh > 0) {

queryStr = queryStr.substring(wh + 1);

} else {

queryStr = queryStr.substring(1);

}

}

}

} else {

queryStr = "";

}

HttpMethod method = request.method();

logger.debug("decode queryStr ={}, method={}, msg={}", queryStr, method, request);

if (directHandleMethod(ctx, request, method)) {

return;

}

ByteBuf content;

if (queryStr.length() == 0) {

if (HttpMethod.GET.equals(method)) {

handleHttpHomePage(ctx, request);

return;

}

content = request.content().retain();

} else {

queryStr = URLDecoder.decode(queryStr, "UTF-8");

int strLen = queryStr.length();

if (queryStr.charAt(0) != '[' && strLen > 5) {

boolean wordOrLetter = Character.isLetterOrDigit(queryStr.charAt(strLen - 1));

for (int i = 2, MAX = Math.min(strLen, 7); i < MAX; i++) {

char c = queryStr.charAt(strLen - i);

if (c == '.') {

if (wordOrLetter) {

serverDef.httpResourceHandler.process(ctx, request, queryStr, strLen - i);

return;

}

break;

} else if (wordOrLetter && !Character.isLetterOrDigit(c)) {

wordOrLetter = false;

}

}

}

byte[] bytes = queryStr.getBytes();

// System.err.println("URI: bytes[0] = "+bytes[0]+", len =

// "+bytes.length);

content = ctx.alloc().buffer(bytes.length);

content.writeBytes(bytes);

}

logger.debug("content.size = " + content.readableBytes());

out.add(content);

boolean alive = HttpHeaderUtil.isKeepAlive(request);

Object event = alive ? thriftMessageWrapperKeepAlive : thriftMessageWrapperNormal;

ctx.fireUserEventTriggered(event);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值