Process the headers sent by the server to this client connection.

        'key' is the websocket handshake challenge/response key.
774997
def _process_server_headers(
        self, key: Union[str, bytes], headers: httputil.HTTPHeaders
    ) -> None:
        
        assert headers["Upgrade"].lower() == "websocket"
        assert headers["Connection"].lower() == "upgrade"
        accept = self.compute_accept_value(key)
        assert headers["Sec-Websocket-Accept"] == accept

        extensions = self._parse_extensions_header(headers)
        for ext in extensions:
            if ext[0] == "permessage-deflate" and self._compression_options is not None:
                self._create_compressors("client", ext[1])
            else:
                raise ValueError("unsupported extension %r", ext)

        self.selected_subprotocol = headers.get("Sec-WebSocket-Protocol", None)
1074103
def do_handshake(self):
        

        _logger.debug("Initiating handshake...")
        try:
            self._wrap_socket_library_call(
                lambda: SSL_do_handshake(self._ssl.value),
                ERR_HANDSHAKE_TIMEOUT)
        except openssl_error() as err:
            if err.ssl_error == SSL_ERROR_SYSCALL and err.result == -1:
                raise_ssl_error(ERR_PORT_UNREACHABLE, err)
            raise
        self._handshake_done = True
        _logger.debug("...completed handshake")
377776
private void handshake() {
        JsonNode helloResponse = this.readNextResponse();

        if (!helloResponse.has("hello")) {
            throw new JsiiException("Expecting 'hello' message from jsii-runtime");
        }

        String runtimeVersion = helloResponse.get("hello").asText();
        assertVersionCompatible(JSII_RUNTIME_VERSION, runtimeVersion);
    }
1363475
@Override
    public void setResponseHeader(String key, String value) {
        this.response.setResponseHeader(key, value);
    }
684913
def set_header(self, key: str, value: str) -> None:
        
        self.headers[key] = value
355372
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        if (!request.getServletPath().endsWith("insecure")) {
            response.addHeader("Content-Security-Policy", buildCSPHeader());
        }
        request.getRequestDispatcher("WEB-INF/chatq.jspx").forward(request, response);
    }
969898
private void processAJPHeader() {
        int oldState = this.state;
        if (anyAreSet(oldState, FLAG_START)) {

            PooledByteBuffer[] byteBuffers = null;

            //merge the cookies into the header map
            Connectors.flattenCookies(exchange);

            PooledByteBuffer pooled = pool.allocate();
            ByteBuffer buffer = pooled.getBuffer();
            buffer.put((byte) 'A');
            buffer.put((byte) 'B');
            buffer.put((byte) 0); //we fill the size in later
            buffer.put((byte) 0);
            buffer.put((byte) 4);
            putInt(buffer, exchange.getStatusCode());
            String reason = exchange.getReasonPhrase();
            if(reason == null) {
                reason = StatusCodes.getReason(exchange.getStatusCode());
            }
            if(reason.length() + 4 > buffer.remaining()) {
                pooled.close();
                throw UndertowMessages.MESSAGES.reasonPhraseToLargeForBuffer(reason);
            }
            putString(buffer, reason);

            int headers = 0;
            //we need to count the headers
            final HeaderMap responseHeaders = exchange.getResponseHeaders();
            for (HttpString name : responseHeaders.getHeaderNames()) {
                headers += responseHeaders.get(name).size();
            }

            putInt(buffer, headers);


            for (final HttpString header : responseHeaders.getHeaderNames()) {
                for (String headerValue : responseHeaders.get(header)) {
                    if(buffer.remaining() < header.length() + headerValue.length() + 6) {
                        //if there is not enough room in the buffer we need to allocate more
                        buffer.flip();
                        if(byteBuffers == null) {
                            byteBuffers = new PooledByteBuffer[2];
                            byteBuffers[0] = pooled;
                        } else {
                            PooledByteBuffer[] old = byteBuffers;
                            byteBuffers = new PooledByteBuffer[old.length + 1];
                            System.arraycopy(old, 0, byteBuffers, 0, old.length);
                        }
                        pooled = pool.allocate();
                        byteBuffers[byteBuffers.length - 1] = pooled;
                        buffer = pooled.getBuffer();
                    }

                    Integer headerCode = HEADER_MAP.get(header);
                    if (headerCode != null) {
                        putInt(buffer, headerCode);
                    } else {
                        putHttpString(buffer, header);
                    }
                    putString(buffer, headerValue);
                }
            }
            if(byteBuffers == null) {
                int dataLength = buffer.position() - 4;
                buffer.put(2, (byte) ((dataLength >> 8) & 0xFF));
                buffer.put(3, (byte) (dataLength & 0xFF));
                buffer.flip();
                queueFrame(new PooledBufferFrameCallback(pooled), buffer);
            } else {
                ByteBuffer[] bufs = new ByteBuffer[byteBuffers.length];
                for(int i = 0; i < bufs.length; ++i) {
                    bufs[i] = byteBuffers[i].getBuffer();
                }
                int dataLength = (int) (Buffers.remaining(bufs) - 4);
                bufs[0].put(2, (byte) ((dataLength >> 8) & 0xFF));
                bufs[0].put(3, (byte) (dataLength & 0xFF));
                buffer.flip();
                queueFrame(new PooledBuffersFrameCallback(byteBuffers), bufs);
            }
            state &= ~FLAG_START;
        }
    }
212304
public function getResponseHandshake($key, array $headers = [])
    {
        $headers = array_merge(
            $this->getSuccessResponseHeaders(
                $key
            ),
            $headers
        );

        return $this->getHttpResponse(self::HTTP_SWITCHING_PROTOCOLS, $headers);
    }
407710
def handle(self, key, value):
        '''
        
        '''
        # the master dict to return
        master = {}
        master['uuid'] = value
        master['total_pending'] = 0
        master['server_time'] = int(self.get_current_time())

        # break down key
        elements = key.split(":")
        dict = {}
        dict['spiderid'] = elements[1]
        dict['appid'] = elements[2]

        # log we received the info message
        extras = self.get_log_dict('info', dict['appid'],
                                   dict['spiderid'], master['uuid'])

        if len(elements) == 4:
            dict['crawlid'] = elements[3]
            extras = self.get_log_dict('info', dict['appid'],
                                       dict['spiderid'], master['uuid'],
                                       elements[3])
        self.logger.info('Received info request', extra=extras)

        # generate the information requested
        if 'crawlid' in dict:
            master = self._build_crawlid_info(master, dict)
        else:
            master = self._build_appid_info(master, dict)

        if self._send_to_kafka(master):
            extras['success'] = True
            self.logger.info('Sent info to kafka', extra=extras)
        else:
            extras['success'] = False
            self.logger.error('Failed to send info to kafka',
                              extra=extras)
144926
function Request_hasHeader(key) {
        if (Type.isString(key)) {
            return this.headers.hasOwnProperty(key.toLowerCase());
        } else {
            throw new error.HttpError(500, {key: key}, "Request.hasHeader: Header key must be string type");
        }
    }
471601
private HandshakeResponse buildHandshakeResponse(WebSocketConnection conn, String clientKey) throws WebSocketException {
        if (log.isDebugEnabled()) {
            log.debug("buildHandshakeResponse: {} client key: {}", conn, clientKey);
        }
        byte[] accept;
        try {
            // performs the accept creation routine from RFC6455 @see <a href="http://tools.ietf.org/html/rfc6455">RFC6455</a>
            // concatenate the key and magic string, then SHA1 hash and base64 encode
            MessageDigest md = MessageDigest.getInstance("SHA1");
            accept = Base64.encode(md.digest((clientKey + Constants.WEBSOCKET_MAGIC_STRING).getBytes()));
        } catch (NoSuchAlgorithmException e) {
            throw new WebSocketException("Algorithm is missing");
        }
        // make up reply data...
        IoBuffer buf = IoBuffer.allocate(308);
        buf.setAutoExpand(true);
        buf.put("HTTP/1.1 101 Switching Protocols".getBytes());
        buf.put(Constants.CRLF);
        buf.put("Upgrade: websocket".getBytes());
        buf.put(Constants.CRLF);
        buf.put("Connection: Upgrade".getBytes());
        buf.put(Constants.CRLF);
        buf.put("Server: Red5".getBytes());
        buf.put(Constants.CRLF);
        buf.put("Sec-WebSocket-Version-Server: 13".getBytes());
        buf.put(Constants.CRLF);
        buf.put(String.format("Sec-WebSocket-Origin: %s", conn.getOrigin()).getBytes());
        buf.put(Constants.CRLF);
        buf.put(String.format("Sec-WebSocket-Location: %s", conn.getHost()).getBytes());
        buf.put(Constants.CRLF);
        // send back extensions if enabled
        if (conn.hasExtensions()) {
            buf.put(String.format("Sec-WebSocket-Extensions: %s", conn.getExtensionsAsString()).getBytes());
            buf.put(Constants.CRLF);
        }
        // send back protocol if enabled
        if (conn.hasProtocol()) {
            buf.put(String.format("Sec-WebSocket-Protocol: %s", conn.getProtocol()).getBytes());
            buf.put(Constants.CRLF);
        }
        buf.put(String.format("Sec-WebSocket-Accept: %s", new String(accept)).getBytes());
        buf.put(Constants.CRLF);
        buf.put(Constants.CRLF);
        // if any bytes follow this crlf, the follow-up data will be corrupted
        if (log.isTraceEnabled()) {
            log.trace("Handshake response size: {}", buf.limit());
        }
        return new HandshakeResponse(buf);
    }
685242
def get_keys(custom_headers:nil)
      response = get_keys_async(custom_headers:custom_headers).value!
      response.body unless response.nil?
    end
1255844
private Map<String, List<String>> readHandshake(WebSocketInputStream input, String key) throws WebSocketException
    {
        return new HandshakeReader(this).readHandshake(input, key);
    }
108667
function Response(request, key) {

    // define private store
    const store = {
        body: '',
        cookies: [],
        headers: {},
        key: key,
        sent: false,
        statusCode: 0
    };
    this[STORE] = store;


    /**
     * The request that is tied to this response.
     * @name Response#req
     * @type {Request}
     */
    Object.defineProperty(this, 'req', {
        configurable: false,
        enumerable: true,
        value: request
    });

    /**
     * Determine if the response has already been sent.
     * @name Response#sent
     * @type {boolean}
     */
    Object.defineProperty(this, 'sent', {
        enumerable: true,
        get: () => store.sent
    });

    /**
     * Get the server instance that initialized this response.
     * @name Request#server
     * @type {SansServer}
     */
    Object.defineProperty(this, 'server', {
        enumerable: true,
        configurable: false,
        value: request.server
    });

    /**
     * Get a copy of the current response state.
     * @name Response#state
     * @type {ResponseState}
     */
    Object.defineProperty(this, 'state', {
        configurable: false,
        enumerable: true,
        get: () => {
            return {
                body: store.body,
                cookies: store.cookies.concat(),
                headers: Object.assign({}, store.headers),
                rawHeaders: rawHeaders(store.headers, store.cookies),
                statusCode: store.statusCode
            }
        }
    });

    /**
     * Get or set the status code.
     * @name Response#statusCode
     * @type {number}
     */
    Object.defineProperty(this, 'statusCode', {
        configurable: false,
        enumerable: true,
        get: () => store.statusCode,
        set: v => this.status(v)
    });

    /**
     * Produce a log event.
     * @param {string} message
     * @param {...*} [arg]
     * @returns {Response}
     * @fires Response#log
     */
    this.log = request.logger('sans-server', 'response', this);
}
9755
def _encode_header(key: str, pdict: Dict[str, str]) -> str:
    
    if not pdict:
        return key
    out = [key]
    # Sort the parameters just to make it easy to test.
    for k, v in sorted(pdict.items()):
        if v is None:
            out.append(k)
        else:
            # TODO: quote if necessary.
            out.append("%s=%s" % (k, v))
    return "; ".join(out)
8578
def parse_request_headers(headers):
    
    request_header_keys = set(headers.keys(lower=True))
    request_meta_keys = set(XHEADERS_TO_ARGS_DICT.keys())
    data_header_keys = request_header_keys.intersection(request_meta_keys)
    return dict(([XHEADERS_TO_ARGS_DICT[key],
                  headers.get(key, None)] for key in data_header_keys))
1188629
def _head(self, client_kwargs):
        
        with _handle_client_error():
            # Object
            if 'Key' in client_kwargs:
                header = self.client.head_object(**client_kwargs)

            # Bucket
            else:
                header = self.client.head_bucket(**client_kwargs)

        # Clean up HTTP request information
        for key in ('AcceptRanges', 'ResponseMetadata'):
            header.pop(key, None)
        return header