Пример #1
0
DateTime HttpClient::getServerDate()
{
	DateTime res;
	String strSD = getResponseHeader("Date");
	if (res.parseHttpDate(strSD))
		return res;
	else
		return DateTime();
}
Пример #2
0
DateTime HttpClient::getLastModifiedDate()
{
	DateTime res;
	String strLM = getResponseHeader("Last-Modified");
	if (res.parseHttpDate(strLM))
		return res;
	else
		return DateTime();
}
char *chumby::HTTPResponse::getResponseString()
{
	std::string * response_header = getResponseHeader();
	_httpResponseLength = response_header->size();
	_httpResponseLength += _httpResponseContentLength;
	char * response = new char[_httpResponseLength + 1];
	memcpy(response, response_header->c_str(), response_header->size());
	if (_httpResponseContent) {
		memcpy(response + response_header->size(), _httpResponseContent, _httpResponseContentLength);
	}
	response[_httpResponseLength] = '\0';
	delete response_header;
	return response;
}
Пример #4
0
void UserTweetFetcher::httpFinished(int req,bool error) {
	// API Limit check
	QString rateLimit = getResponseHeader(req,"X-RateLimit-Remaining");
	QString rateReset = getResponseHeader(req,"X-RateLimit-Reset");
//	QMessageBox::information(0,rateLimit,rateReset);
	if (rateLimit!="") {
		long secondsToReset = rateReset.toLong()-QDateTime::currentDateTime().toTime_t();
		emit rateUpdate(rateLimit.toLong(),(secondsToReset<60?60:secondsToReset));
	}
	TweetFetcher::httpFinished(req,error);
	if (isError.contains(req))
		error = error || isError.take(req);
	if (sentTweet.contains(req)) {
		QString sentText = sentTweet.take(req);
		QString sentUser = sentInReplyTo.take(req);
		bool directMessage = isDirectMessage.take(req);
		if (error) {
			if (directMessage)
				emit failedDirectMessage(sentText,sentUser);
			else
				emit failedTweet(sentText,sentUser,"");
		}
	}
}
// virtual
void LLCurl::Responder::completedRaw(
	const LLChannelDescriptors& channels,
	const LLIOPipe::buffer_ptr_t& buffer)
{
	LLBufferStream istr(channels, buffer.get());
	const bool emit_parse_errors = false;

	// <Techwolf Lupindo> pass parse error down code path
	mDeserializeError = false;

	std::string debug_body("(empty)");
	bool parsed=true;
	if (EOF == istr.peek())
	{
		parsed=false;
	}
	// Try to parse body as llsd, no matter what 'content-type' says.
	else if (LLSDParser::PARSE_FAILURE == LLSDSerialize::fromXML(mContent, istr, emit_parse_errors))
	{
		parsed=false;
		char body[1025]; 
		body[1024] = '\0';
		istr.seekg(0, std::ios::beg);
		istr.get(body,1024);
		if (strlen(body) > 0)
		{
			mContent = body;
			debug_body = body;
		}
		// <Techwolf Lupindo> pass parse error down code path
		mDeserializeError = true;
	}

	// Only emit a warning if we failed to parse when 'content-type' == 'application/llsd+xml'
	if (!parsed && (HTTP_CONTENT_LLSD_XML == getResponseHeader(HTTP_IN_HEADER_CONTENT_TYPE)))
	{
		LL_WARNS() << "Failed to deserialize . " << mURL << " [status:" << mStatus << "] " 
			<< "(" << mReason << ") body: " << debug_body << LL_ENDL;
	}

	httpCompleted();
}
Пример #6
0
int HttpConnection::readResponse(OutputStream& os)
{
    char* responseBuffer  = NULL;
    char* zResponseBuffer = NULL;
    bool writeDataAtOnce = false;
    DWORD read = 0;
    int ret = 0;
    bool inflate = false;

#ifdef USE_ZLIB
    DWORD contentLength = 0;
    DWORD uncompressedContentLength = 0;
    DWORD size   = 512;
  
    if (compression_enabled) {

        //
        // get response length
        //
        StringBuffer val = getResponseHeader(HTTP_HEADER_CONTENT_LENGTH);
        if (val.empty()) {
            LOG.error("error reading %s from HTTP headers", HTTP_HEADER_CONTENT_LENGTH);
            return StatusInvalidParam;
        }
        contentLength = atoi(val.c_str());
        if (contentLength <= 0) {
            LOG.error("error reading %s from HTTP headers: %d", HTTP_HEADER_CONTENT_LENGTH, contentLength);
            return StatusInvalidParam;
        }

        //
        // get response encoding
        //
        val = getResponseHeader(HTTP_HEADER_CONTENT_ENCODING);
        if (val.empty()) {
            LOG.error("error reading %s from HTTP headers", HTTP_HEADER_CONTENT_ENCODING);
            return StatusInvalidParam;
        }
        if (val == "deflate") {
            inflate = true;
        }

        if (inflate) {
            //
            // get uncompressed content length
            //
            val = getResponseHeader(HTTP_HEADER_UNCOMPRESSED_CONTENT_LENGTH);
            if (val.empty()) {
                LOG.error("error reading %s from HTTP headers", HTTP_HEADER_UNCOMPRESSED_CONTENT_LENGTH);
                return StatusInvalidParam;
            }
            uncompressedContentLength = atoi(val.c_str());
            if (uncompressedContentLength <= 0) {
                LOG.error("error reading %s from HTTP headers: %d", HTTP_HEADER_UNCOMPRESSED_CONTENT_LENGTH, uncompressedContentLength);
                return StatusInvalidParam;
            }

            zResponseBuffer = new char[contentLength + 1];
        }
    }
#endif
    
    // Allocate a block of memory for response read.
    responseBuffer = new char[responseChunkSize + 1];
    memset(responseBuffer, 0, responseChunkSize);
    int zOffset = 0;
    // TODO: if enabled to check the connection, sometimes it crashes :( 
    // HttpConnectionTimer* th = new HttpConnectionTimer(&zOffset, req, responseTimeout);
    // th->start();
    do {
        if (!InternetReadFile(req, (LPVOID)responseBuffer, responseChunkSize, &read)) {
            ret = StatusReadingError;
            break;
        }

        if (read > 0) {
            if (inflate) {
                memcpy(zResponseBuffer + zOffset, responseBuffer, read);
                zOffset += read;
            } else {
                os.write(responseBuffer, read);
                zOffset += read;
                fireTransportEvent(read, DATA_RECEIVED);
            }
        }
    } while (read);
    
    // th->softTerminate();
    
    delete [] responseBuffer; 
    

    if (inflate) {
        uLong uncomprLen = uncompressedContentLength;
        Bytef* uncompr = new Bytef[uncompressedContentLength + 1];

        //
        // Decompresses the source buffer into the destination buffer.
        //
        int err = uncompress(uncompr, &uncomprLen, (Bytef*)zResponseBuffer, contentLength);

        if (err == Z_OK) {
            char* response = (char*)uncompr;
            response[uncompressedContentLength] = 0;
            os.write(response, uncompressedContentLength);
        } else  {
            LOG.error("Error in zlib uncompress: %s", zError(err));
            ret = StatusInternalError;
        }
        delete [] uncompr;
    }


    delete [] zResponseBuffer;
    return ret;
}