Search in sources :

Example 1 with SessionManager

use of com.blade.mvc.http.session.SessionManager 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);
    }
}
Also used : SessionManager(com.blade.mvc.http.session.SessionManager) ArrayList(java.util.ArrayList) HttpParseException(com.blade.exception.HttpParseException) ByteBuf(io.netty.buffer.ByteBuf) HttpPostRequestDecoder(io.netty.handler.codec.http.multipart.HttpPostRequestDecoder) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent) HttpParseException(com.blade.exception.HttpParseException) IOException(java.io.IOException)

Aggregations

HttpParseException (com.blade.exception.HttpParseException)1 SessionManager (com.blade.mvc.http.session.SessionManager)1 ByteBuf (io.netty.buffer.ByteBuf)1 HttpContent (io.netty.handler.codec.http.HttpContent)1 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)1 HttpPostRequestDecoder (io.netty.handler.codec.http.multipart.HttpPostRequestDecoder)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1