当前位置: 首页>>代码示例>>C++>>正文


C++ HttpConnection类代码示例

本文整理汇总了C++中HttpConnection的典型用法代码示例。如果您正苦于以下问题:C++ HttpConnection类的具体用法?C++ HttpConnection怎么用?C++ HttpConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HttpConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: begin_request

static int begin_request(mg_connection* cnt)
{
    mg_request_info const* req = mg_get_request_info(cnt);
    
    // create http object.
    use<HttpServer> serv = req->user_data;
    HttpConnection http;
    http.connection = cnt;
    http.request = req;
    http.server = serv;
    http.update();
    
    // dispatch.
    core::string const& req_file = http.uri.filename();
    static const core::regex re_python("^\\S+.py$");
    if (re_python.match(req_file))
    {
        python::FileRequest pyreq;
        pyreq.uri = serv->config.document + http.uri;
        pyreq.method = http.method;
        if (pyreq.process())
        {
            parser::Http11Response resp;
            resp.data.append(pyreq.stream);
            http.write(resp.full());
        }
    }
    
    // send signal.
    serv->emit(kSignalNewConnection, eventobj_t::Data(&http));
    
    return 1;
}
开发者ID:imace,项目名称:nnt,代码行数:33,代码来源:HttpServer.cpp

示例2: TRACE

void HttpWorker::spawnConnection(Socket* client, ServerSocket* listener)
{
	TRACE(1, "client connected; fd:%d", client->handle());

	++connectionLoad_;
	++connectionCount_;

	// XXX since socket has not been used so far, I might be able to defer its creation out of its socket descriptor
	// XXX so that I do not have to double-initialize libev's loop handles for this socket.
	client->setLoop(loop_);

	HttpConnection* c;
	if (likely(freeConnections_ != nullptr)) {
		c = freeConnections_;
		c->id_ = connectionCount_;
		freeConnections_ = c->next_;

		c->reinitialize();
	}
	else {
		c = new HttpConnection(this, connectionCount_/*id*/);
	}

	if (connections_)
		connections_->prev_ = c;

	c->next_ = connections_;
	connections_ = c;

	c->start(listener, client);
}
开发者ID:,项目名称:,代码行数:31,代码来源:

示例3: setRequestHeaders

void HttpUploader::setRequestHeaders(const StringBuffer& luid, HttpConnection& httpConnection, InputStream& inputStream) {
    
    StringBuffer dataSize;
    int totalSize = inputStream.getTotalSize();
    LOG.debug("[%s]: input stream size is %i", __FUNCTION__, totalSize);
    LOG.debug("[%s]: totalDataToUpload size is %i", __FUNCTION__, totalDataToUpload);
    if (totalDataToUpload > 0) {
        totalSize = totalDataToUpload;
    } 
    dataSize.sprintf("%d", totalSize);
    

    httpConnection.setRequestHeader(HTTP_HEADER_ACCEPT,         "*/*");
    httpConnection.setRequestHeader(HTTP_HEADER_CONTENT_TYPE,   "application/octet-stream");

    // set transfer enconding to chunked
    //httpConnection.setRequestHeader(HTTP_HEADER_TRANSFER_ENCODING, "chunked");

    // set Funambol mandatory custom headers
    httpConnection.setRequestHeader(HTTP_HEADER_X_FUNAMBOL_FILE_SIZE, dataSize);
    httpConnection.setRequestHeader(HTTP_HEADER_X_FUNAMBOL_DEVICE_ID, deviceID);
    httpConnection.setRequestHeader(HTTP_HEADER_X_FUNAMBOL_LUID, luid);
    
    if (partialUploadedData > 0) {
        StringBuffer s;
        s.sprintf("bytes %d-%d/%d", partialUploadedData, totalSize-1, totalSize);
        
        httpConnection.setRequestHeader(HTTP_HEADER_CONTENT_RANGE, s.c_str());
    }
}
开发者ID:fieldwind,项目名称:syncsdk,代码行数:30,代码来源:HttpUploader.cpp

示例4: AppLogTag

void
ProjectGiraffeTab4::OnAppControlCompleteResponseReceived(const AppId &appId, const String &operationId, AppCtrlResult appControlResult, const IMap *extraData)
{
	AppLogTag("camera1", "appid %ls opid %ls", appId.GetPointer(), operationId.GetPointer());
	if (appId.Equals(L"tizen.filemanager", true) &&
			operationId.Equals(L"http://tizen.org/appcontrol/operation/pick", true))
	{
		if (appControlResult == APP_CTRL_RESULT_SUCCEEDED) {
			AppLogTag("camera1", "Media list success.");
			String pathKey = L"path";
			String *filePath = (String *)extraData->GetValue(pathKey);

			AppLogTag("camera1", "filepath: %ls", filePath->GetPointer());

			HttpMultipartEntity* userParameters = new HttpMultipartEntity();
			userParameters->Construct();
			userParameters->AddFilePart(L"avatar", *filePath);

			HttpConnection *connection = HttpConnection::userUpdatePutConnection(this, userParameters);
			connection->begin();

			// TODO: figure out when to free
//			delete userParameters;
		} else if (appControlResult == APP_CTRL_RESULT_CANCELED) {
			AppLogTag("camera1", "Media list canceled.");
		} else if (appControlResult == APP_CTRL_RESULT_FAILED) {
			AppLogTag("camera1", "Media list failed.");
		}
	} else if (appId.Equals(L"tizen.camera", true) &&
			operationId.Equals(L"http://tizen.org/appcontrol/operation/createcontent", true))
	{
		AppLogTag("camera1", "camcam");
		if (appControlResult == APP_CTRL_RESULT_SUCCEEDED) {
			AppLogTag("camera1", "Camera capture success.");

			String pathKey = L"path";
			String *filePath = (String *)extraData->GetValue(pathKey);

			AppLogTag("camera1", "filepath: %ls", filePath->GetPointer());

			HttpMultipartEntity* userParameters = new HttpMultipartEntity();
			userParameters->Construct();
			userParameters->AddFilePart(L"avatar", *filePath);

			HttpConnection *connection = HttpConnection::userUpdatePutConnection(this, userParameters);
			connection->begin();

			// TODO: figure out when to free
			// delete userParameters;
		} else if (appControlResult == APP_CTRL_RESULT_CANCELED) {
			AppLogTag("camera1", "Camera capture canceled.");
		} else if (appControlResult == APP_CTRL_RESULT_FAILED) {
			AppLogTag("camera1", "Camera capture failed.");
		} else if (appControlResult == APP_CTRL_RESULT_TERMINATED) {
			AppLogTag("camera1", "Camera capture terminated.");
		} else if (appControlResult == APP_CTRL_RESULT_ABORTED) {
			AppLogTag("camera1", "Camera capture aborted.");
		}
	}
}
开发者ID:justinkchen,项目名称:giraffe,代码行数:60,代码来源:ProjectGiraffeTab4.cpp

示例5: AppLog

void
ProjectGiraffeTab4::updateItems()
{
	AppLog("updating items");
	HttpConnection *connection = HttpConnection::userPostsGetConnection(this,User::currentUser()->id());
	connection->begin();
}
开发者ID:justinkchen,项目名称:giraffe,代码行数:7,代码来源:ProjectGiraffeTab4.cpp

示例6: httpFinished

	virtual void httpFinished(HttpConnection*, int result) {
		if(result == 304) {	//Not Modified
			printf("Program unchanged.\n");
#ifdef MA_PROF_SUPPORT_STYLUS
			printf("Tap screen or press Fire to run.\n");
#else	// MA_PROF_SUPPORT_STYLUS
			printf("Press Fire to run.\n");
#endif	// MA_PROF_SUPPORT_STYLUS
			mState = eReady;
			return;
		}
		if(result >= 200 && result <= 299) {	//OK
			printf("HTTP %i\n", result);
			String cls;
			int res = mHttp.getResponseHeader("content-length", &cls);
			if(res < 0) {
				printf("CL error: %i\n", res);
				return;
			}
			int contentLength = stringToInteger(cls);
			printf("Content-Length: %i\n", contentLength);
			maDestroyObject(mProgram);
			if(maCreateData(mProgram, contentLength) == RES_OUT_OF_MEMORY) {
				printf("Out of memory!\n");
				return;
			}
			mHttp.readToData(mProgram, 0, contentLength);
			return;
		} else {	//error
			printf("HTTP %s %i\n", (result < 0) ? "error" : "response", result);
		}
	}
开发者ID:patrickbroman,项目名称:MoSync,代码行数:32,代码来源:OtaLoad.cpp

示例7: SYSCALL

SYSCALL(void, maHttpSetRequestHeader(MAHandle conn, const char* key, const char* value)) {
	LOGS("HttpSetRequestHeader %i %s: %s\n", conn, key, value);
	MAStreamConn& mac = getStreamConn(conn);
	HttpConnection* http = mac.conn->http();
	MYASSERT(http != NULL, ERR_CONN_NOT_HTTP);
	MYASSERT(http->mState == HttpConnection::SETUP, ERR_HTTP_NOT_SETUP);
	http->SetRequestHeader(key, value);
}
开发者ID:N00bKefka,项目名称:MoSync,代码行数:8,代码来源:networking.cpp

示例8: AppLog

void
ProjectGiraffeTab1::updateItems()
{
#if kDebugUseDummyItems
	AppLog("Creating dummy items");
	User *dummyUser = new User();
	dummyUser->setUsername(L"Username");
	for (int i = 0; i < 10; i++) {
		Graffiti *graffiti = new Graffiti();
		graffiti->setUser(dummyUser);
		graffiti->setText(L"dummy string");
		_items->Add(graffiti);
	}

#else

#if kDebugUseHttpConnection

	double latitude = ProjectGiraffeMainForm::currentLatitude;
	double longitude = ProjectGiraffeMainForm::currentLongitude;
	HttpConnection *connection = HttpConnection::graffitiNearbyGetConnection(this,latitude,longitude);
	connection->begin();

#else
	// Kick off http request for items based on location.
	// Populate item source array
	HttpSession* pHttpSession = null;
	HttpTransaction* pHttpTransaction = null;
	String* pProxyAddr = null;
	String hostAddr = L"http://ec2-54-243-69-6.compute-1.amazonaws.com/";
	String uri = L"http://ec2-54-243-69-6.compute-1.amazonaws.com/";

	AppLog("Starting the HTTP Session");
	pHttpSession = new HttpSession();

	// HttpSession construction.
	pHttpSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, pProxyAddr, hostAddr, null);

	// Open a new HttpTransaction.
	pHttpTransaction = pHttpSession->OpenTransactionN();

	// Add a listener.
	pHttpTransaction->AddHttpTransactionListener(*this);

	// Get an HTTP request.
	HttpRequest* pHttpRequest = pHttpTransaction->GetRequest();

	// Set the HTTP method and URI:
	pHttpRequest->SetMethod(NET_HTTP_METHOD_GET);
	pHttpRequest->SetUri(uri);

	// Submit the request:
	pHttpTransaction->Submit();
#endif

#endif
}
开发者ID:justinkchen,项目名称:giraffe,代码行数:57,代码来源:ProjectGiraffeTab1.cpp

示例9: composeURL

int HttpUploader::upload(const StringBuffer& luid, InputStream* inputStream) 
{
    int status = 0;

    // safe checks
    if (!inputStream || !inputStream->getTotalSize()) {
        LOG.error("upload error: no data to transfer");
        return 1;
    }
    if (luid.empty() || syncUrl.empty()  || sourceURI.empty()) {
        LOG.error("upload error: some params are not set");
        return 2;
    }
    
    StringBuffer fullUrl = composeURL();
    URL url(fullUrl.c_str());
    HttpConnection* httpConnection = getHttpConnection();
   
    httpConnection->setCompression(false);
    status = httpConnection->open(url, HttpConnection::MethodPost);
    
    if (status) { 
        delete httpConnection;

        return status;
    }

    httpConnection->setKeepAlive(keepalive);
    httpConnection->setRequestChunkSize(maxRequestChunkSize);
   
    // Set headers (use basic auth)
    HttpAuthentication* auth = new BasicAuthentication(username, password);
    httpConnection->setAuthentication(auth);
    setRequestHeaders(luid, *httpConnection, *inputStream);
    
    // Send the HTTP request
    StringOutputStream response;
    status = httpConnection->request(*inputStream, response);
    LOG.debug("response returned = %s", response.getString().c_str());
    
    // Manage response headers
    if (useSessionID) {
        // Server returns the jsessionId in the Set-Cookie header, can be used for 
        // the subsequent calls of upload().
        StringBuffer hdr = httpConnection->getResponseHeader(HTTP_HEADER_SET_COOKIE);
        sessionID = httpConnection->parseJSessionId(hdr);
    }
    
    httpConnection->close();
    
    delete auth;
    delete httpConnection;
    return status;
}
开发者ID:fieldwind,项目名称:syncsdk,代码行数:54,代码来源:HttpUploader.cpp

示例10: Q_ASSERT

/*---------------------------------------------------------------------------*/
QVariant HttpRecognizer::comment( IConnection* connection )
{
	Q_ASSERT (connection);
	if (!mConnections.contains( connection->networkInfo() ))
		return "No comment yet";

	const HttpConnection con = mConnections.value( connection->networkInfo() );
	const QHttpRequestHeader request = con.lastRequestHeader();
	const QHttpResponseHeader response = con.lastResponseHeader();

	return request.method() + " " + request.value( "host" ) + request.path()
		+ (response.isValid() ? "\nHTTP " + QString::number( response.statusCode() ) + " " + response.reasonPhrase() : "" );
}
开发者ID:houzhenggang,项目名称:netsniffer,代码行数:14,代码来源:HttpRecognizer.cpp

示例11: AP_MSG_HANDLER_METHOD

AP_MSG_HANDLER_METHOD(ServerModule, HttpServer_SendResponse)
{
  HttpConnection* pConnection = findHttpConnection(pMsg->hConnection);
  if (pConnection == 0) { throw ApException(LOG_CONTEXT, "findHttpConnection(" ApHandleFormat ") failed", ApHandlePrintf(pMsg->hConnection)); }

  String sHeader;

  if (!pMsg->sProtocol) {
    pMsg->sProtocol = "HTTP/1.1";
  }

  if (pMsg->nStatus == 0) {
    pMsg->nStatus = 200;
  }

  if (!pMsg->sMessage) {
    if (pMsg->nStatus == 200) {
      pMsg->sMessage = "OK";
    } else {
      pMsg->sMessage = "No Message";
    }
  }

  sHeader.appendf("%s %d %s\r\n", _sz(pMsg->sProtocol), pMsg->nStatus, _sz(pMsg->sMessage));
  
  {
    for (Apollo::KeyValueElem* e = 0; (e = pMsg->kvHeader.nextElem(e)) != 0; ) {
      sHeader.appendf("%s: %s\r\n", _sz(e->getKey()), _sz(e->getString()));
    }
  }

  if (pMsg->sbBody.Length() > 0) {
    if (pMsg->kvHeader.find("content-length", Apollo::KeyValueList::IgnoreCase)) {
    } else {
      sHeader.appendf("Content-length: %d\r\n", pMsg->sbBody.Length());
    }
  } else {
    sHeader.appendf("Content-length: 0\r\n");
  }

  //sHeader += "Connection: close\r\n";
  sHeader += "\r\n";
  
  pConnection->DataOut((unsigned char*) sHeader.c_str(), sHeader.bytes());

  if (pMsg->sbBody.Length() > 0) {
    pConnection->DataOut(pMsg->sbBody.Data(), pMsg->sbBody.Length());
  }

  pMsg->apStatus = ApMessage::Ok;
}
开发者ID:wolfspelz,项目名称:Apollo,代码行数:51,代码来源:ServerModule.cpp

示例12: TRACE

void HttpWorker::spawnConnection(Socket* client, ServerSocket* listener)
{
	TRACE("client connected; fd:%d", client->handle());

	++connectionLoad_;
	++connectionCount_;

	// XXX since socket has not been used so far, I might be able to defer its creation out of its socket descriptor
	// XXX so that I do not have to double-initialize libev's loop handles for this socket.
	client->setLoop(loop_);

	HttpConnection* c = new HttpConnection(this, connectionCount_/*id*/);

	connections_.push_front(c);
	ConnectionHandle i = connections_.begin();

	c->start(listener, client, i);
}
开发者ID:liveck,项目名称:x0,代码行数:18,代码来源:HttpWorker.cpp

示例13: testGET

    /**
     * Tests a GET on a specific URL, prints the response.
     */
    void testGET(const URL& testURL) 
    {
        LOG.debug("test GET on %s", testURL.fullURL);
        int ret = httpConnection.open(testURL, HttpConnection::MethodGet);
        LOG.debug("open, ret = %d", ret);
        
        BufferInputStream inputStream("");
        StringOutputStream outputStream;
        
        httpConnection.setRequestHeader(HTTP_HEADER_ACCEPT,          "*/*");
        httpConnection.setRequestHeader(HTTP_HEADER_CONTENT_LENGTH,  0);

        ret = httpConnection.request(inputStream, outputStream);
        LOG.debug("request, ret = %d", ret);
        LOG.debug("response = \n%s", outputStream.getString().c_str());
        
        httpConnection.close();
    }
开发者ID:fieldwind,项目名称:syncsdk,代码行数:21,代码来源:HttpUploader.cpp

示例14: checkConnections

void HttpServer::checkConnections()
{
	if(this->closed){
		for(vector<HttpConnection*>::iterator it = this->connections.begin();
			it!=this->connections.end(); it++)
			(*it)->close();
	}
	for(vector<HttpConnection*>::iterator it = this->connections.begin();
		it!=this->connections.end(); ){
		HttpConnection* conn = *it;
		if(conn->isClosed()){
			conn->joinThread();
			delete conn;
			this->connections.erase(it);
		}else{
			it ++;
		}
	}
}
开发者ID:SayCV,项目名称:youproxy,代码行数:19,代码来源:httpserver.cpp

示例15: no_timewait

int HttpListener::addConnection( struct conn_data * pCur, int *iCount )
{
    int fd = pCur->fd;
    if ( checkAccess( pCur ))
    {
        no_timewait( fd );
        close( fd );
        --(*iCount);
        return 0;
    }
    HttpConnection* pConn = HttpConnPool::getConnection();
    if ( !pConn )
    {
        ERR_NO_MEM( "HttpConnPool::getConnection()" );
        close( fd );
        --(*iCount);
        return -1;
    }
    VHostMap * pMap;
    if ( m_pSubIpMap )
    {
        pMap = getSubMap( fd );
    }
    else
        pMap = getVHostMap();
    pConn->setVHostMap( pMap );
    pConn->setLogger( getLogger());
    pConn->setRemotePort( ntohs( ((sockaddr_in *)(pCur->achPeerAddr))->sin_port) );
    if ( pConn->setLink( pCur->fd, pCur->pInfo, pMap->getSSLContext() ) )
    {
        HttpConnPool::recycle( pConn );
        close( fd );
        --(*iCount);
        return -1;
    }
    fcntl( fd, F_SETFD, FD_CLOEXEC );
    fcntl( fd, F_SETFL, HttpGlobals::getMultiplexer()->getFLTag() );
    //pConn->tryRead();
    return 0;
}
开发者ID:lsmichael,项目名称:openlitespeed,代码行数:40,代码来源:httplistener.cpp


注:本文中的HttpConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。