예제 #1
0
std::istream& HTTPClientSession::receiveResponse(HTTPResponse& response)
{
	delete _pRequestStream;
	_pRequestStream = 0;

	do
	{
		response.clear();
		HTTPHeaderInputStream his(*this);
		try
		{
			response.read(his);
		}
		catch (MessageException&)
		{
			close();
			if (networkException())
				networkException()->rethrow();
			else
				throw;
		}
		catch (Exception&)
		{
			close();
			throw;
		}
	}
	while (response.getStatus() == HTTPResponse::HTTP_CONTINUE);

	_mustReconnect = getKeepAlive() && !response.getKeepAlive();

	if (!_expectResponseBody)
		_pResponseStream = new HTTPFixedLengthInputStream(*this, 0);
	else if (response.getChunkedTransferEncoding())
		_pResponseStream = new HTTPChunkedInputStream(*this);
	else if (response.getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH)
		_pResponseStream = new HTTPFixedLengthInputStream(*this, response.getContentLength());
	else
		_pResponseStream = new HTTPInputStream(*this);
		
	return *_pResponseStream;
}
예제 #2
0
std::istream& HTTPClientSession::receiveResponse(HTTPResponse& response) {
    _pRequestStream = 0;
    if (networkException()) networkException()->rethrow();

    do {
        response.clear();
        HTTPHeaderInputStream his(*this);
        try {
            response.read(his);
        }
        catch (MessageException&) {
            close();
            if (networkException())
                networkException()->rethrow();
            else
                throw;
        }
        catch (Exception&) {
            close();
            throw;
        }
    } while (false /* response.getStatus() == HTTPResponse::HTTP_CONTINUE */);

    _mustReconnect = getKeepAlive() && !response.getKeepAlive();

    if (!_expectResponseBody || response.getStatus() < 200
            || response.getStatus() == HTTPResponse::HTTP_NO_CONTENT
            || response.getStatus() == HTTPResponse::HTTP_NOT_MODIFIED)
        _pResponseStream.reset(new HTTPFixedLengthInputStream(*this, 0));
    else if (response.getChunkedTransferEncoding())
        throw NotImplementedException("HTTPClientSession::receiveResponse ChunkedInputStream");
    else if (response.hasContentLength())
        _pResponseStream.reset(new HTTPFixedLengthInputStream(*this, response.getContentLength()));
    else
        throw NotImplementedException("HTTPClientSession::receiveResponse HTTPIOStream");

    return *_pResponseStream;
}