Example usage for io.netty.handler.codec.http HttpMethod hashCode

List of usage examples for io.netty.handler.codec.http HttpMethod hashCode

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpMethod hashCode.

Prototype

@Override
    public int hashCode() 

Source Link

Usage

From source file:org.ebayopensource.scc.cache.RequestKeyGenerator.java

License:Apache License

private String getRequestHash(FullHttpRequest request) {
    HttpHeaders headers = request.headers();
    String requestURI = getRequestURI(request);
    HttpMethod requestMethod = request.getMethod();
    Set<String> skipHeaders = m_skipHeaders;
    boolean skipRequestContent = m_uriMatchEnabled && WildcardMatcher.isPatternCanBeMatchedIn(m_uriMatchOnly,
            new CacheDecisionObject(requestURI, requestMethod.name()));
    if (skipRequestContent) {
        skipHeaders = new HashSet<>(m_skipHeaders);
        skipHeaders.add(HttpHeaders.Names.CONTENT_LENGTH.toUpperCase());
    }/*w  w  w .  java 2 s . co  m*/

    int uriHashcode = requestURI.hashCode();
    int methodHashCode = requestMethod.hashCode();
    List<Entry<String, String>> entries = headers.entries();
    List<String> hashList = new ArrayList<>();
    for (Iterator<Entry<String, String>> it = entries.iterator(); it.hasNext();) {
        Entry<String, String> entry = it.next();
        if (skipHeaders.contains(entry.getKey().toUpperCase())) {
            continue;
        }
        hashList.add(entry.getKey());
        hashList.add(entry.getValue());
    }

    int headersHashcode = hashList.hashCode();

    StringBuilder sb = new StringBuilder(4);
    sb.append(uriHashcode).append(methodHashCode).append(headersHashcode);

    if (!skipRequestContent) {
        ByteBuf content = request.content();
        sb.append(content.hashCode());
    }

    return Checksum.checksum(sb.toString());
}