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

com.firefly.codec.http2.model.Protocol Maven / Gradle / Ivy

There is a newer version: 5.0.0-dev6
Show newest version
package com.firefly.codec.http2.model;

/**
 * @author Pengtao Qiu
 */
public enum Protocol {
    NONE, H2, WEB_SOCKET;

    public static Protocol from(MetaData.Request request) {
        return getProtocol(request);
    }

    public static Protocol from(MetaData.Response response) {
        if (response.getStatus() == HttpStatus.SWITCHING_PROTOCOLS_101) {
            return getProtocol(response);
        } else {
            return NONE;
        }
    }

    private static Protocol getProtocol(MetaData metaData) {
        if (metaData.getFields().contains(HttpHeader.CONNECTION, "Upgrade")) {
            if (metaData.getFields().contains(HttpHeader.UPGRADE, "h2c")) {
                return H2;
            } else if (metaData.getFields().contains(HttpHeader.UPGRADE, "websocket")) {
                return WEB_SOCKET;
            } else {
                return NONE;
            }
        } else {
            return NONE;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy