public static String readHeaderFromClient(InputStream clientInpStream)
			throws IOException, IllegalRequestException {
		StringBuffer header = new StringBuffer(500);

		int inp = 0;
		int dfaState = 0;
		int FINAL_STATE = 4; // a DFA being used with 4 states
		while (dfaState != FINAL_STATE && (inp = clientInpStream.read()) > -1) {
			switch ((char) inp) {
			case '\r':
				if (dfaState == 0) {
					dfaState = 1;
				} else if (dfaState == 2) {
					dfaState = 3;
				}
				break;
			case '\n':
				if (dfaState == 1) {
					dfaState = 2;
				} else if (dfaState == 3) {
					dfaState = 4;
				}
				break;
			default:
				dfaState = 0;
			}

			header.append((char) inp);
		}

		if (dfaState != FINAL_STATE) {
			throw new IllegalRequestException(
					"client closed connection before server could read HTTP header");
		}

		header.deleteCharAt(header.length() - 1); // deleting \n
		header.deleteCharAt(header.length() - 1); // deleting \r

		logger.debug("header from the client - " + header.toString());

		return header.toString();
	}