package org.kne.cloud.network;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;

public class HTTPDetectorItem implements ProtocolDetectorItem {

	@Override
	public Protocol apply(InputStream t) {
		try {
			byte[]b=new byte[5];
			new DataInputStream(t).readFully(b);
			String s=new String(b, "ascii");
			if(s.startsWith("GET")||s.startsWith("POST")||s.startsWith("HEAD")||s.startsWith("PUT")||s.startsWith("DELETE")||s.startsWith("CONNECT")||s.startsWith("OPTIONS")||s.startsWith("TRACE")||s.startsWith("PATCH")) {
				return new Protocol("HTTP");
			}
		} catch (IOException e) {
		}
		return null;
	}

}
