예제 #1
0
void HTTPSocket::OnLine(const std::string& line)
{
	if (m_first)
	{
		Parse pa(line);
		std::string str = pa.getword();
		if (str.substr(0,4) == "HTTP") // response
		{
			m_http_version = str;
			m_status = pa.getword();
			m_status_text = pa.getrest();
			m_response = true;
		}
		else // request
		{
			m_method = str;
			m_url = pa.getword();
			size_t spl = m_url.find("?");
			if (spl != std::string::npos)
			{
				m_uri = m_url.substr(0,spl);
				m_query_string = m_url.substr(spl + 1);
			}
			else
			{
				m_uri = m_url;
			}
			m_http_version = pa.getword();
			m_request = true;
		}
		m_first = false;
		OnFirst();
		return;
	}
	if (!line.size())
	{
//		SetLineProtocol(false);
		m_header = false;
		OnHeaderComplete();
		return;
	}
	Parse pa(line,":");
	std::string key = pa.getword();
	std::string value = pa.getrest();
	OnHeader(key,value);
	/* If remote end tells us to keep connection alive, and we're operating
	in http/1.1 mode (not http/1.0 mode), then we mark the socket to be
	retained. */
/*	if (!strcasecmp(key.c_str(), "connection") &&
	    !strcasecmp(value.c_str(), "keep-alive") )
	{
		SetRetain();
	}*/
}
예제 #2
0
void MyFrame::OnChar( wxKeyEvent& event )
{
    wxCommandEvent evt;

    if ( event.m_keyCode == WXK_F1 )
    {
        OnFirst( evt );
    }
    else
    {
        if ( event.m_keyCode == WXK_F2 )
        {
            OnSecond( evt );
        }
        else
        {
            if ( event.m_keyCode == WXK_F3 )
            {
                OnThird( evt );
            }
            if ( event.m_keyCode == WXK_F4 && !event.AltDown() )
            {
                // "AI" :-)
                wxMessageBox(_("There are only 3 layouts in this demo :-("));
            }
            else
            {
                if ( event.m_keyCode == WXK_TAB )
                {
                    //  USEFUL TRICK:: avoids flickering of application's frame
                    //                 when closing NN windows on exit:

                    Show(false);

                    if ( (mAutoSave && mSavedAlready) || !mAutoSave )
                    {
                    }
                    else
                    {
                        wxCommandEvent evt;
                        OnStore(evt);
                    }

                    Destroy();
                }
                else
                {
                    event.Skip();
                }
            }
        }
    }
}
예제 #3
0
void HTTPSocket::OnLine(const std::string& line)
{
	if (m_first)
	{
		Parse pa(line);
		std::string str = pa.getword();
		if (str.size() > 4 && Utility::ToLower(str.substr(0,5)) == "http/") // response
		{
			m_http_version = str;
			m_status = pa.getword();
			m_status_text = pa.getrest();
			m_response = true;
		}
		else // request
		{
			m_method = str;
			m_url = pa.getword();
			size_t spl = m_url.find("?");
			if (spl != std::string::npos)
			{
				m_uri = m_url.substr(0,spl);
				m_query_string = m_url.substr(spl + 1);
			}
			else
			{
				m_uri = m_url;
				m_query_string = "";
			}
			m_http_version = pa.getword();
			m_b_http_1_1 = m_http_version.size() > 4 && m_http_version.substr(4) == "/1.1";
			m_b_keepalive = m_b_http_1_1;
			m_request = true;
		}
		m_first = false;
		OnFirst();
		return;
	}
	if (!line.size())
	{
		if (m_body_size_left || !m_b_http_1_1 || !m_b_keepalive || m_b_chunked)
		{
			SetLineProtocol(false);
			m_header = false;
		}
		OnHeaderComplete();
		if (!m_body_size_left && !m_b_chunked)
		{
			OnDataComplete();
		}
		return;
	}
	Parse pa(line,":");
	std::string key = pa.getword();
	std::string value = pa.getrest();
	OnHeader(key,value);
	if (Utility::ToLower(key) == "content-length")
	{
		m_body_size_left = atol(value.c_str());
	}
	if (m_b_http_1_1 && Utility::ToLower(key) == "connection")
	{
		m_b_keepalive = Utility::ToLower(value) != "close";
	}
	if (Utility::ToLower(key) == "transfer-encoding" && Utility::ToLower(value) == "chunked")
	{
		m_b_chunked = true;
	}
	/* If remote end tells us to keep connection alive, and we're operating
	in http/1.1 mode (not http/1.0 mode), then we mark the socket to be
	retained. */
#ifdef ENABLE_POOL
	if (m_b_http_1_1 && m_b_keepalive)
	{
		SetRetain();
	}
#endif
}