All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.smartboot.http.client.decode.HttpProtocolDecoder Maven / Gradle / Ivy

There is a newer version: 1.4.3
Show newest version
/*******************************************************************************
 * Copyright (c) 2017-2021, org.smartboot. All rights reserved.
 * project name: smart-http
 * file name: HttpProtocolDecoder.java
 * Date: 2021-07-15
 * Author: sandao ([email protected])
 ******************************************************************************/

package org.smartboot.http.client.decode;

import org.smartboot.http.client.impl.Response;
import org.smartboot.http.common.utils.Constant;
import org.smartboot.http.common.utils.StringUtils;
import org.smartboot.socket.transport.AioSession;

import java.nio.ByteBuffer;

/**
 * @author 三刀
 * @version V1.0 , 2020/3/30
 */
public class HttpProtocolDecoder implements HeaderDecoder {

    private final HttpStatusCodeDecoder decoder = new HttpStatusCodeDecoder();

    @Override
    public HeaderDecoder decode(ByteBuffer byteBuffer, AioSession aioSession, Response request) {
        int length = StringUtils.scanUntilAndTrim(byteBuffer, Constant.SP);
        if (length > 0) {
            request.setProtocol(StringUtils.convertToString(byteBuffer, byteBuffer.position() - length - 1, length, StringUtils.String_CACHE_COMMON));
            return decoder.decode(byteBuffer, aioSession, request);
        } else {
            return this;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy