예제 #1
0
YETI_Result HttpTcpConnector::connect(const HttpUrl & url,
                                      HttpClient & client,
                                      const HttpProxyAddress * proxy,
                                      bool reuse, HttpClient::Connection *& connection)
{
    connection = NULL;
    const char * server_hostname;
    YETI_UInt16 server_port;
    if (proxy) {
        server_hostname = (const char *)proxy->get_hostname();
        server_port = proxy->get_port();
    } else {
        server_hostname = (const char *)url.get_host();
        server_port = url.get_port();
    }

    IpAddress address;
    YETI_CHECK_FINE(address.resolve_name(server_hostname, client.get_config().m_name_resolver_timeout_));
    YETI_LOG_FINE_2("TCP connector will connect to %s : %d", server_hostname, server_port);
    TcpClientSocket * tcp_socket = new TcpClientSocket();
    SocketReference socket(tcp_socket, true);
    tcp_socket->set_read_timeout(client.get_config().m_io_timeout_);
    tcp_socket->set_write_timeout(client.get_config().m_io_timeout_);
    SocketAddress socket_address(address, server_port);
    YETI_CHECK_FINE(tcp_socket->connect(socket_address, client.get_config().m_connection_timeout_));

    HttpSimpleConnection * _connection = new HttpSimpleConnection();
    _connection->m_socket_ = socket;
    connection = _connection;
    tcp_socket->get_input_stream(_connection->m_inputstream_);
    tcp_socket->get_output_stream(_connection->m_outputstream_);

    return YETI_SUCCESS;
}
예제 #2
0
YETI_Result HttpEnvProxySelector::get_proxy_for_url(const HttpUrl & url, HttpProxyAddress & proxy)
{
    HttpProxyAddress * protocol_proxy = NULL;
    switch (url.get_schemeid()) {
case Uri::SCHEME_ID_HTTP:
    protocol_proxy = &m_http_proxy_;
    break;

case Uri::SCHEME_ID_HTTPS:
    protocol_proxy = &m_https_proxy_;
    break;

default:
    return YETI_ERROR_HTTP_NO_PROXY;
    }

    if (m_no_proxy_.get_item_count()) {
        for (List<String>::iterator i = m_no_proxy_.get_first_item();
            i;
            ++i) {
                if ((*i) == "*") {
                    return YETI_ERROR_HTTP_NO_PROXY;
                }
                if (url.get_host().ends_with(*i, true)) {
                    if (url.get_host().get_length() == (*i).get_length()) {
                        return YETI_ERROR_HTTP_NO_PROXY;
                    }
                    if (url.get_host().get_chars()[url.get_host().get_length() - (*i).get_length() - 1] == '.') {
                        return YETI_ERROR_HTTP_NO_PROXY;
                    }
                }
        }
    }

    if (protocol_proxy->get_hostname().get_length()) {
        proxy = *protocol_proxy;
        return YETI_SUCCESS;
    }

    proxy = m_all_proxy_;
    return proxy.get_hostname().get_length() ? YETI_SUCCESS : YETI_ERROR_HTTP_NO_PROXY;
}