Package org.sentinel.servers.http.protocol

Source Code of org.sentinel.servers.http.protocol.HTTPHeaders

package org.sentinel.servers.http.protocol;

import org.sentinel.servers.http.protocol.HTTPHeader;
import java.util.ArrayList;

public class HTTPHeaders extends ArrayList<HTTPHeader>
{
   
    public HTTPHeader get(String name) throws NoSuchHTTPHeaderException
    {
        HTTPHeader found = null;
       
        for(HTTPHeader h : this) {
            if(h.getName().equalsIgnoreCase(name)) {
                found = h;
            }
        }
       
        if(found != null) {
            return found;
        }
        throw new NoSuchHTTPHeaderException(name);
    }
   
    public void addOrReplace(HTTPHeader header)
    {
        boolean found = false;
        for(HTTPHeader h : this) {
            if(h.getName().equalsIgnoreCase(header.getName())) {
                h.setValue(header.getValue());
                found = true;
            }
        }
       
        if(!found) {
            add(header);
        }
    }

    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
       
        for(HTTPHeader header : this) {
            sb.append(header.toString());
            sb.append("\n");
        }
       
        return sb.toString();
    }
   
}
TOP

Related Classes of org.sentinel.servers.http.protocol.HTTPHeaders

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.