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


C++ HttpResponse::generateResponse方法代码示例

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


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

示例1: mod_ffeadcpp_method_handler

static int mod_ffeadcpp_method_handler (request_rec *r)
{
	string port = CastUtil::lexical_cast<string>(r->server->port);

	//signal(SIGSEGV,signalSIGSEGV);
	string content;

	apr_bucket_brigade *bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
	for ( ; ; ) {
		apr_bucket* b ;
		bool done = false;
		ap_get_brigade(r->input_filters, bb, AP_MODE_READBYTES, APR_BLOCK_READ, HUGE_STRING_LEN);
		for ( b = APR_BRIGADE_FIRST(bb);b != APR_BRIGADE_SENTINEL(bb);b = APR_BUCKET_NEXT(b) )
		{
			size_t bytes ;
			const char* buf = "\0";
			if ( APR_BUCKET_IS_EOS(b) )
			{
				done = true;
			}
			else if (apr_bucket_read(b, &buf, &bytes, APR_BLOCK_READ)== APR_SUCCESS )
			{
				content += string(buf, 0, bytes);
			}
		}

		if (done)
		  break;
		else
		  apr_brigade_cleanup(bb) ;
	}
	apr_brigade_destroy(bb) ;

	HttpRequest* hreq= new HttpRequest();
	string cntpath = serverRootDirectory + "web/";
	string webpath = "URL" + cntpath;
	MyReq* req = new MyReq();
	req->r = r;
	req->htreq = hreq;

	apr_table_do(iterate_func, req, r->headers_in, NULL);

	ip_address = hreq->getHeader(HttpRequest::Host);
	string tipaddr = ip_address;
	if(port!="80")
		tipaddr += (":" + port);
	ConfigurationData::getInstance()->ip_address = tipaddr;

	string contret;
	if(content!="")
	{
		contret = hreq->buildRequest("Content",content.c_str());
		fprintf(stderr,contret.c_str());
		fflush(stderr);
	}
	hreq->buildRequest(webpath.c_str(),r->uri);
	hreq->buildRequest("Method",r->method);
	if(r->args != NULL && r->args[0] != '\0')
	{
		hreq->buildRequest("GetArguments",r->args);
	}
	hreq->buildRequest("HttpVersion", r->protocol);

	HttpResponse respo = service(hreq);
	string h1 = respo.generateResponse(hreq->getMethod(), hreq, false);

	for (int var = 0; var < (int)respo.getCookies().size(); var++)
	{
		apr_table_add(r->headers_out, "Set-cookie", respo.getCookies().at(var).c_str());
	}

	r->status_line = respo.getStatusLine().c_str();
	if(respo.getHeader(HttpResponse::ContentType)!="")
	{
		r->content_type = respo.getHeader(HttpResponse::ContentType).c_str();
	}
	r->clength = h1.length();

	fprintf(stderr,"\n\n\n\n--------------------------------------------\n");
	fprintf(stderr,hreq->getUrl().c_str());
	fprintf(stderr,"\n");
	string star =  hreq->toString();
	fprintf(stderr,star.c_str());
	fprintf(stderr,"\n--------------------------------------------\n");
	fprintf(stderr,contret.c_str());
	fflush(stderr);
	fprintf(stderr,"\n\n");
	fprintf(stderr,content.c_str());
	fprintf(stderr,"\n");
	fprintf(stderr,"ip_address = %s", tipaddr.c_str());
	fprintf(stderr,"\n");
	fprintf(stderr,"\n--------------------------------------------\n\n\n\n");
	fflush(stderr);
	fprintf(stderr, h1.c_str());
	fflush(stderr);
	delete hreq;
	delete req;

	if(h1!="")
	{
//.........这里部分代码省略.........
开发者ID:cddypang,项目名称:ffead-cpp,代码行数:101,代码来源:mod_ffeadcpp.cpp

示例2: run


//.........这里部分代码省略.........
					res.setStatusMsg("OK");
					if(res.getContent_type()=="")res.setContent_type(configData.props[ext]);
					res.setContent_str(content);
					//res.setContent_len(CastUtil::lexical_cast<string>(content.length()));
					//sess.setAttribute("CURR",req->getUrl());
				}
			}

			filterHandler.handleOut(req, res, configData.filterMap, dlib, ext);
		}

		alldatlg += "--processed data";
		string h1;
		bool sessionchanged = !req->hasCookie();
		sessionchanged |= req->getSession()->isDirty();
		if(req->getConnection()!="")
			res.setConnection("close");
		createResponse(res,sessionchanged,req->getSession()->getSessionAttributes(),req->getCookieInfoAttribute("FFEADID"), sessionTimeoutVar, configData.sessatserv);
		//Head should behave exactly as Get but there should be no entity body
		if(req->getMethod()=="HEAD")
		{
			h1 = res.generateHeadResponse();
		}
		else if(req->getMethod()=="OPTIONS")
		{
			h1 = res.generateOptionsResponse();
		}
		else if(req->getMethod()=="TRACE")
		{
			h1 = res.generateTraceResponse(req);
		}
		else
		{
			h1 = res.generateResponse();
		}
		//logger << h1 << endl;
		if(isSSLEnabled)
		{
			int r;
			/* Now perform renegotiation if requested */
			if(configData.client_auth==CLIENT_AUTH_REHANDSHAKE){
			  SSL_set_verify(ssl,SSL_VERIFY_PEER |
				SSL_VERIFY_FAIL_IF_NO_PEER_CERT,0);

			  /* Stop the client from just resuming the
				 un-authenticated session */
			  SSL_set_session_id_context(ssl,
				(const unsigned char*)&SSLHandler::s_server_auth_session_id_context,
				sizeof(SSLHandler::s_server_auth_session_id_context));

			  if(SSL_renegotiate(ssl)<=0)
			  {
				  sslHandler.error_occurred((char*)"SSL renegotiation error",fd,ssl);
				  if(io!=NULL)BIO_free(io);
				  return;
			  }
			  if(SSL_do_handshake(ssl)<=0)
			  {
				  sslHandler.error_occurred((char*)"SSL renegotiation error",fd,ssl);
				  if(io!=NULL)BIO_free(io);
				  return;
			  }
			  ssl->state=SSL_ST_ACCEPT;
			  if(SSL_do_handshake(ssl)<=0)
			  {
				  sslHandler.error_occurred((char*)"SSL renegotiation error",fd,ssl);
开发者ID:greenbaum,项目名称:ffead-cpp,代码行数:67,代码来源:ServiceTask.cpp

示例3: ngx_http_ffeadcpp_module_handler_post_read

static ngx_int_t ngx_http_ffeadcpp_module_handler_post_read(ngx_http_request_t *r)
{
string cntpath = "";
	cntpath.append(ffeadcpp_path.data, ffeadcpp_path.len);
	cntpath += "/web/";
	HttpRequest* req = new HttpRequest(cntpath);

	//cerr << "FFEAD in ngx_http_ffeadcpp_module_handler " << cntpath << r->uri.data << endl;
    ngx_int_t    rc;
    ngx_buf_t   *b;
    ngx_chain_t  out;

	ngx_list_part_t            *part;
    ngx_table_elt_t            *h;
    ngx_uint_t                  i;

    /*
    Get the first part of the list. There is usual only one part.
    */
    part = &r->headers_in.headers.part;
    h = part->elts;

    /*
    Headers list array may consist of more than one part,
    so loop through all of it
    */
    for (i = 0; /* void */ ; i++) {
        if (i >= part->nelts) {
            if (part->next == NULL) {
                /* The last part, search is done. */
                break;
            }

            part = part->next;
            h = part->elts;
            i = 0;
        }
//	cerr << "header -> " << string(h[i].key.data, h[i].key.len) << " = " << string(h[i].value.data, h[i].value.len) << endl;
	req->buildRequest(string(h[i].key.data, h[i].key.len), string(h[i].value.data, h[i].value.len));
    }

    string content;
	ngx_http_read_input_data(r, content);
	//cerr << "Input Request Data\n " << content << "\n======================\n" << endl;
	//cerr << "URL -> " << string(r->uri.data,r->uri.len) << endl;
	//cerr << "Method -> " << string(r->main->method_name.data, r->main->method_name.len) << endl;
	if(content!="")
	{
		req->buildRequest("Content", content.c_str());
	}
	req->buildRequest("URL",  string(r->uri.data,r->uri.len));
	req->buildRequest("Method", string(r->main->method_name.data, r->main->method_name.len));
	if(r->args.len > 0)
	{
		req->buildRequest("GetArguments", string(r->args.data,r->args.len));
	}
	req->buildRequest("HttpVersion", CastUtil::lexical_cast<string>(r->http_version));

	HttpResponse* respo = new HttpResponse;
	ServiceTask* task = new ServiceTask;
	task->handle(req, respo);
	delete task;
cerr << req->toString() << endl;
	if(respo->isDone()) {
		for (int var = 0; var < (int)respo->getCookies().size(); var++)
		{
			set_custom_header_in_headers_out(r, "Set-Cookie", respo->getCookies().at(var));
		}

		/* allocate a buffer for your response body */
		b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
		if (b == NULL) {
			return NGX_HTTP_INTERNAL_SERVER_ERROR;
		}

		/* attach this buffer to the buffer chain */
		out.buf = b;
		out.next = NULL;

		string data = respo->generateResponse(false);
		//cerr << "OUT -> " << data << endl;
		map<string,string>::const_iterator it;
		for(it=respo->getHeaders().begin();it!=respo->getHeaders().end();it++) {
			if(StringUtil::toLowerCopy(it->first)==StringUtil::toLowerCopy(HttpResponse::ContentLength)) {
				r->headers_out.content_length_n = CastUtil::lexical_cast<int>(it->second);
			} else {
				set_custom_header_in_headers_out(r, it->first, it->second);
			}
		}
		//cerr << "done writing headers" << endl;		
/* adjust the pointers of the buffer */
		b->pos = data.c_str();
		b->last = data.length();
		b->memory = 1;    /* this buffer is in memory */
		b->last_buf = 1;  /* this is the last buffer in the buffer chain */

		/* set the status line */
		r->headers_out.status = CastUtil::lexical_cast<int>(respo->getStatusCode());

		delete respo;
//.........这里部分代码省略.........
开发者ID:sumeetchhetri,项目名称:ffead-cpp,代码行数:101,代码来源:works_ngx_http_ffeadcpp_module.cpp


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