agoo_ws_add_headers(agooReq req, agooText t) {
    int		klen = 0;
    const char	*key;

    t = agoo_text_append(t, up_con, sizeof(up_con) - 1);
    if (NULL != (key = agoo_con_header_value(req->header.start, req->header.len, "Sec-WebSocket-Key", &klen)) &&
	klen + sizeof(ws_magic) < MAX_KEY_LEN) {
	char		buf[MAX_KEY_LEN];
	unsigned char	sha[32];
	int		len = klen + sizeof(ws_magic) - 1;

	strncpy(buf, key, klen);
	strcpy(buf + klen, ws_magic);
	sha1((unsigned char*)buf, len, sha);
	len = b64_to(sha, SHA1_DIGEST_SIZE, buf);

	t = agoo_text_append(t, ws_accept, sizeof(ws_accept) - 1);
	t = agoo_text_append(t, buf, len);
	t = agoo_text_append(t, "\r\n", 2);
    }
    if (NULL != (key = agoo_con_header_value(req->header.start, req->header.len, "Sec-WebSocket-Protocol", &klen))) {
	t = agoo_text_append(t, ws_protocol, sizeof(ws_protocol) - 1);
	t = agoo_text_append(t, key, klen);
	t = agoo_text_append(t, "\r\n", 2);
    }
    return t;
}
agoo_ws_add_headers(agooReq req, agooText t) {
    int		klen = 0;
    const char	*key;

    t = agoo_text_append(t, up_con, sizeof(up_con) - 1);
    if (NULL != (key = agoo_con_header_value(req->header.start, req->header.len, "Sec-WebSocket-Key", &klen)) &&
	klen + sizeof(ws_magic) < MAX_KEY_LEN) {
	char		buf[MAX_KEY_LEN];
	unsigned char	sha[32];
	int		len = klen + sizeof(ws_magic) - 1;

	strncpy(buf, key, klen);
	strcpy(buf + klen, ws_magic);
	sha1((unsigned char*)buf, len, sha);
	len = b64_to(sha, SHA1_DIGEST_SIZE, buf);

	t = agoo_text_append(t, ws_accept, sizeof(ws_accept) - 1);
	t = agoo_text_append(t, buf, len);
	t = agoo_text_append(t, "\r\n", 2);
    }
    if (NULL != (key = agoo_con_header_value(req->header.start, req->header.len, "Sec-WebSocket-Protocol", &klen))) {
	t = agoo_text_append(t, ws_protocol, sizeof(ws_protocol) - 1);
	t = agoo_text_append(t, key, klen);
	t = agoo_text_append(t, "\r\n", 2);
    }
    return t;
}