use of com.blade.exception.HttpParseException in project blade by biezhi.
the class HttpRequest method init.
public void init(String remoteAddress) {
this.remoteAddress = remoteAddress.substring(1);
this.keepAlive = HttpUtil.isKeepAlive(nettyRequest);
this.url = nettyRequest.uri();
int pathEndPos = this.url().indexOf('?');
this.uri = pathEndPos < 0 ? this.url() : this.url().substring(0, pathEndPos);
this.protocol = nettyRequest.protocolVersion().text();
this.method = nettyRequest.method().name();
String cleanUri = this.uri;
if (!"/".equals(this.contextPath())) {
cleanUri = PathKit.cleanPath(cleanUri.replaceFirst(this.contextPath(), "/"));
this.uri = cleanUri;
}
this.httpHeaders = nettyRequest.headers();
if (!HttpServerHandler.PERFORMANCE) {
SessionManager sessionManager = WebContext.blade().sessionManager();
if (null != sessionManager) {
this.session = SESSION_HANDLER.createSession(this);
}
}
if ("GET".equals(this.method())) {
return;
}
try {
HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(HTTP_DATA_FACTORY, nettyRequest);
this.isMultipart = decoder.isMultipart();
List<ByteBuf> byteBuffs = new ArrayList<>(this.contents.size());
for (HttpContent content : this.contents) {
if (!isMultipart) {
byteBuffs.add(content.content().copy());
}
decoder.offer(content);
this.readHttpDataChunkByChunk(decoder);
content.release();
}
if (!byteBuffs.isEmpty()) {
this.body = Unpooled.copiedBuffer(byteBuffs.toArray(new ByteBuf[0]));
}
} catch (Exception e) {
throw new HttpParseException("build decoder fail", e);
}
}
Aggregations