本文整理汇总了C++中HttpSession类的典型用法代码示例。如果您正苦于以下问题:C++ HttpSession类的具体用法?C++ HttpSession怎么用?C++ HttpSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cleanUpOldSessions
HttpSession* SessionManager::startSession(const HttpRequest& request, HttpResponse& response) {
cleanUpOldSessions();
HttpSession* session = NULL;
if(mUseCookies) {
try {
const HttpCookie& sessionCookie = request.getCookie(mCookieName);
session = startSessionInternal(sessionCookie.getValue(), true, request, response);
} catch(const CookieNotFoundException& ex) {
}
}
if(!session && mUseRequest) {
try {
session = startSessionInternal(request.getAttribute(mRequestName), true, request, response);
} catch(const AttributeNotFoundException& ex) {
}
}
if(!session) {
session = startSessionInternal(generateSessionId(request, response), false, request, response);
}
if(mUseCookies && session) {
if(mCookieLifeTime > 0) {
response.addCookie(HttpCookie(mCookieName, session->getId(), mCookieLifeTime));
}
else {
response.addCookie(HttpCookie(mCookieName, session->getId()));
}
}
return session;
}
示例2: handlePost
void LoginServlet::handlePost(HttpRequest* request, HttpResponse* response) {
HttpSession* session = request->getSession();
session->setUserName(request->getParameter("username"));
session->setPassword(request->getParameter("password"));
session->setSessionIp(request->getRemoteIp());
bool authorized = WebServer::instance()->authorize(session);
if(authorized) {
response->forwardTo("/main");
return;
}
response->println("HTTP/1.1 200 OK");
response->println("Content-Type: text/html");
response->println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
response->println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
response->println(" <head>");
response->println(" <title>SWGEmu Web Server Login</title>");
response->println(" <meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\" />");
response->println(" <link rel=\"stylesheet\" type=\"text/css\" href=\"css/style.css\" />");
response->println(" </head>");
response->println(" <body>");
response->println(" <div class=\"login_box\">");
response->println(" <h1>You are not authorized</h1>");
response->println(" </div>");
response->println(" </body>");
response->println("</html>");
}
示例3: 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
}
示例4: l
HttpSession& SessionManagerImpl::newSession(long maxInactiveInterval)
{
Mutex::ScopedLock l(_mutex);
HttpSession* ps = new HttpSessionImpl(maxInactiveInterval, _pSessionListener);
if(ps)
{
_sessionMap.insert(std::make_pair(ps->getId(), ps));
return *ps;
}
else throw NullPointerException("SessionManager::newSession");
}
示例5: hostAddr2
String IRailConnection::getTrip(String &from, String &to,TrainsResultsForm *pTrainsResultsForm) {
this->pTrainsResultsForm = pTrainsResultsForm;
result r = E_SUCCESS;
String* pProxyAddr = null;
String hostAddr = L"http://api.irail.be";
String hostAddr2(L"http://api.irail.be/connections/?to=");
hostAddr2.Append(to);
hostAddr2.Append(L"&from=");
hostAddr2.Append(from);
HttpSession* pSession = null;
HttpTransaction* pTransaction = null;
pSession = new HttpSession();
r = pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, pProxyAddr ,hostAddr,null);
if (IsFailed(r))
{
AppLog("Construct Session failed. (%s)\n", GetErrorMessage(r));
}
pTransaction = pSession->OpenTransactionN();
if (null == pTransaction)
{
AppLog("Construct Session failed. \n");
}
r = pTransaction->AddHttpTransactionListener(*this);
if (IsFailed(r))
{
AppLog("AddHttpTransactionListener Session failed.\n");
}
HttpRequest* pRequest = pTransaction->GetRequest();
if(pRequest == null)
{
AppLog("GetRequest failed. \n");
}
r = pRequest->SetUri(hostAddr2);
if(IsFailed(r))
{
AppLog("SetUri failed. (%s)\n", GetErrorMessage(r));
}
r = pRequest->SetMethod(NET_HTTP_METHOD_GET);
if(IsFailed(r))
{
AppLog("SetMethod failed. (%s)\n", GetErrorMessage(r));
}
r = pTransaction->Submit();
if(IsFailed(r))
{
AppLog("Submit failed. (%s)\n", GetErrorMessage(r));
}
return hostAddr;
}
示例6: add_to_cart
void ProductDetails::add_to_cart(HttpServletRequest& request, HttpServletResponse &response) {
HttpSession* session = request.getSession(false);
if(!session) throw runtime_error("no session");
typedef vector<cart_item> shopping_cart;
shopping_cart cart = session->getAttribute<shopping_cart>("cart");
cart_item item;
item.quantity = boost::lexical_cast<int>(request.getParameter("quantity"));
item.product = fetch(request.getParameter("product_id"));
if(item.quantity <= 0)
throw runtime_error("Quantity is invalid. It must be a positive number");
cart.push_back(item);
session->setAttribute("cart",cart);
response.sendRedirect("ShoppingCart.sxx");
}
示例7: doGet
void doGet(HttpServletRequest& request, HttpServletResponse &response) {
response.setContentType("text/html");
ostream& out = response.getOutputStream();
out << "<html><body>" << endl;
HttpSession* session = request.getSession();
if(session->hasAttribute("lastVisit")) {
time_t lastVisit = session->getAttribute<time_t>("lastVisit");
out << "Witaj ponownie. Pierwszy raz odwiedziles nas: <br>"
<< ctime(&lastVisit) << endl;
}else{
out << "Witaj po raz pierszy!" << endl;
time_t lastVisit = time(NULL);
session->setAttribute("lastVisit", lastVisit);
}
out << "</body></html>" << endl;
}
示例8: hostAddr
result Chatting::RequestHttpPost(void) {
result r = E_SUCCESS;
HttpSession* pSession = null;
HttpTransaction* pTransaction = null;
HttpRequest* pRequest = null;
HttpMultipartEntity* pMultipartEntity = null;
String hostAddr(HTTP_CLIENT_HOST_ADDRESS);
// Creates an HTTP session.
pSession = new HttpSession();
r = pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, null, hostAddr, null);
pTransaction = pSession->OpenTransactionN();
r = pTransaction->AddHttpTransactionListener(*this);
// r = pTransaction->SetHttpProgressListener(*this);
pRequest = pTransaction->GetRequest();
pRequest->SetMethod(NET_HTTP_METHOD_POST);
r = pRequest->SetUri(HTTP_CLIENT_REQUEST_URI);
pMultipartEntity = new HttpMultipartEntity();
r = pMultipartEntity->Construct();
String me = __pEditField->GetText();
Tizen::Text::Encoding* pEnc = Tizen::Text::Encoding::GetEncodingN(L"UTF-8");
pMultipartEntity->AddStringPart(L"message", me, L"text/plain", L"UTF-8",
*pEnc);
r = pMultipartEntity->AddStringPart(L"friendIdRegId", resultRegId);
r = pRequest->SetEntity(*pMultipartEntity);
r = pTransaction->Submit();
return r;
}
示例9: removeSession
/** Delete a session */
void HttpSessionStore::removeSession(HttpSession session) {
mutex.lock();
sessions.remove(session.getId());
mutex.unlock();
}
示例10: doGet
void doGet(HttpServletRequest& req, HttpServletResponse &res) {
//dbg_stop();
res.setContentType("text/html");
ostream& out = res.getOutputStream();
out << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\""
"\"http://www.w3.org/TR/html4/loose.dtd\">" << endl;
out << "<html><head><title>test</title></head><body>" << endl;
out << "PID: " << getpid() << "<hr>" << endl;
auto_ptr< vector<string> > names = req.getHeaderNames();
out << "<div style='border: solid black'>" << endl;
out << "Headers:<ul>" << endl;
for(unsigned i=0; i< names->size();++i) {
out << "<li>" << (*names)[i] << "<ul>";
auto_ptr< vector<string> > values = req.getHeaders((*names)[i]);
for(unsigned j=0; j < values->size();++j) {
out << "<li>" << (*values)[j] << "</li>";
}
out << "</ul>\n";
}
out << "</ul></div><br>\n";
out << "<div style='border: solid black'>" << endl;
out << "Cookies:<ul>" << endl;
auto_ptr< vector<Cookie> > cookies = req.getCookies();
for(unsigned i=0;i<cookies->size();++i)
out << "<li><u>" << (*cookies)[i].getName() << "</u> "
<< (*cookies)[i].getValue() << "</li>\n" << endl;
out << "</ul></div><br>\n";
out << "<div style='border: solid black'>" << endl;
out << "Parameters:<ul>" << endl;
names = req.getParameterNames();
for(unsigned i=0; i< names->size();++i) {
out << "<li>" << (*names)[i] << "<ul>";
auto_ptr< vector<string> > values = req.getParameterValues((*names)[i]);
for(unsigned j=0; j < values->size();++j) {
out << "<li>" << (*values)[j] << "</li>\n";
// Cookie c(names[i], req.getParameter(names[i]));
// res.addCookie(c);
}
out << "</ul>\n";
}
out << "</ul></div><br>";
HttpSession* session = req.getSession();
if(session){
int cnt;
if(session->isNew()){
cnt = 1;
session->setAttribute("cnt",cnt);
}else{
cnt = session->getAttribute<int>("cnt");
cnt++;
session->setAttribute("cnt",cnt);
}
out << "Your counter: " << cnt << endl;
out << "<br>ID: " << session->getId() << endl;
}else
out << "<h4>No session</h4>";
out << "</body></html>" << endl;
}
示例11: OnTransactionHeaderCompleted
void HttpThread::OnTransactionHeaderCompleted(HttpSession & httpSession,
HttpTransaction & httpTransaction,
int headerLen, bool bAuthRequired)
{
result r = E_SUCCESS;
HttpResponse * pResponse = httpTransaction.GetResponse();
if ((r = GetLastResult()) != E_SUCCESS)
{
LOG(LWARNING, ("httpTransaction.GetResponse error", r));
httpSession.CancelTransaction(httpTransaction);
httpSession.CloseTransaction(httpTransaction);
m_callback.OnFinish(-1, m_begRange, m_endRange);
return;
}
int const httpStatusCode = pResponse->GetHttpStatusCode();
// When we didn't ask for chunks, code should be 200
// When we asked for a chunk, code should be 206
bool const isChunk = !(m_begRange == 0 && m_endRange < 0);
if ((isChunk && httpStatusCode != 206) || (!isChunk && httpStatusCode != 200))
{
LOG(LWARNING, ("Http request to", m_url, " aborted with HTTP code", httpStatusCode));
httpSession.CancelTransaction(httpTransaction);
r = httpSession.CloseTransaction(httpTransaction);
m_callback.OnFinish(-4, m_begRange, m_endRange);
LOG(LDEBUG, ("CloseTransaction result", r));
return;
}
else if (m_expectedSize > 0)
{
bool bGoodSize = false;
// try to get content length from Content-Range header first
HttpHeader * pHeader = pResponse->GetHeader();
LOG(LDEBUG, ("Header:", FromTizenString(*pHeader->GetRawHeaderN())));
IEnumerator * pValues = pHeader->GetFieldValuesN("Content-Range");
if (GetLastResult() == E_SUCCESS)
{
bGoodSize = true;
pValues->MoveNext(); // strange, but works
String const * pString = dynamic_cast<String const *>(pValues->GetCurrent());
if (pString->GetLength())
{
int lastInd;
pString->LastIndexOf ('/', pString->GetLength()-1, lastInd);
int64_t value = -1;
String tail;
pString->SubString(lastInd + 1, tail);
LOG(LDEBUG, ("tail value:",FromTizenString(tail)));
LongLong::Parse(tail, value);
if (value != m_expectedSize)
{
LOG(LWARNING, ("Http request to", m_url,
"aborted - invalid Content-Range:", value, " expected:", m_expectedSize ));
httpSession.CancelTransaction(httpTransaction);
r = httpSession.CloseTransaction(httpTransaction);
m_callback.OnFinish(-2, m_begRange, m_endRange);
LOG(LDEBUG, ("CloseTransaction result", r));
}
}
}
else
{
pValues = pHeader->GetFieldValuesN("Content-Length");
if (GetLastResult() == E_SUCCESS)
{
bGoodSize = true;
pValues->MoveNext(); // strange, but works
String const * pString = dynamic_cast<String const *>(pValues->GetCurrent());
if (pString)
{
int64_t value = -1;
LongLong::Parse(*pString, value);
if (value != m_expectedSize)
{
LOG(LWARNING, ("Http request to", m_url,
"aborted - invalid Content-Length:", value, " expected:", m_expectedSize));
httpSession.CancelTransaction(httpTransaction);
r = httpSession.CloseTransaction(httpTransaction);
m_callback.OnFinish(-2, m_begRange, m_endRange);
LOG(LDEBUG, ("CloseTransaction result", r));
}
}
}
}
if (!bGoodSize)
{
LOG(LWARNING, ("Http request to", m_url,
"aborted, server didn't send any valid file size"));
httpSession.CancelTransaction(httpTransaction);
r = httpSession.CloseTransaction(httpTransaction);
m_callback.OnFinish(-2, m_begRange, m_endRange);
LOG(LDEBUG, ("CloseTransaction result", r));
}
}
}
示例12: processEvent
int HttpAioSendFile::processEvent(Aiosfcb *event)
{
HttpSession *pSession = (HttpSession *)event->getUData();
pSession->handleAioSFEvent(event);
return 0;
}
示例13: getConnector
int CgidConn::buildSSIExecHeader()
{
static unsigned int s_id = 0;
HttpSession *pSession = getConnector()->getHttpSession();
HttpReq * pReq = pSession->getReq();
const char * pReal;
const AutoStr2 * psChroot;
const char * pChroot;
int ret;
uid_t uid;
gid_t gid;
pReal = pReq->getRealPath()->c_str();
ret = pReq->getUGidChroot( &uid, &gid, &psChroot );
if ( ret )
return ret;
// if ( D_ENABLED( DL_LESS ) )
// LOG_D(( getLogger(),
// "[%s] UID: %d, GID: %d",
// getLogId(), pHeader->m_uid, pHeader->m_gid ));
if ( psChroot )
{
// if ( D_ENABLED( DL_LESS ) )
// LOG_D(( getLogger(),
// "[%s] chroot: %s, real path: %s",
// getLogId(), pChroot->c_str(), pReal ));
pChroot = psChroot->c_str();
ret = psChroot->len();
}
else
{
pChroot = NULL;
ret = 0;
}
char achBuf[4096];
memccpy( achBuf, pReal, 0, 4096 );
char * argv[256];
char ** p;
char * pDir ;
SUExec::buildArgv( achBuf, &pDir, argv, 256 );
if ( pDir )
*(argv[0]-1) = '/';
else
pDir = argv[0];
int priority = ((CgidWorker *)getWorker())->getConfig().getPriority();
m_req.buildReqHeader( uid, gid, priority, pChroot, ret, pDir,
strlen( pDir ),
((CgidWorker *)getWorker())->getConfig().getRLimits() );
p = &argv[1];
while( *p )
{
m_req.appendArgv( *p, strlen( *p ) );
++p;
}
m_req.appendArgv( NULL, 0 );
HttpCgiTool::buildEnv( &m_req, pSession );
m_req.finalize( s_id++, ((CgidWorker *)getWorker())->getConfig().getSecret(),
LSCGID_TYPE_CGI );
return 0;
}
示例14: getConnector
int ProxyConn::sendReqHeader()
{
m_iovec.clear();
HttpSession *pSession = getConnector()->getHttpSession();
HttpReq *pReq = pSession->getReq();
//remove the trailing "\r\n" before adding our headers
const char *pBegin = pReq->getOrgReqLine();
m_iTotalPending = pReq->getHttpHeaderLen();
int newReqLineLen = 0;
int headerLen = 17;
char *pExtraHeader = &m_extraHeader[23];
const char *pForward = pReq->getHeader(HttpHeader::H_X_FORWARDED_FOR);
int len;
if (*pForward != '\0')
{
len = pReq->getHeaderLen(HttpHeader::H_X_FORWARDED_FOR);
if (len > 160)
len = 160;
memmove(&pExtraHeader[headerLen], pForward, len);
headerLen += len;
pExtraHeader[headerLen++] = ',';
}
//add "X-Forwarded-For" header
memmove(&pExtraHeader[headerLen], pSession->getPeerAddrString(),
pSession->getPeerAddrStrLen());
headerLen += pSession->getPeerAddrStrLen();
pExtraHeader[headerLen++] = '\r';
pExtraHeader[headerLen++] = '\n';
#if 1 //always set "Accept-Encoding" header to "gzip"
char *pAE = (char *)pReq->getHeader(HttpHeader::H_ACC_ENCODING);
if (*pAE)
{
int len = pReq->getHeaderLen(HttpHeader::H_ACC_ENCODING);
if (len >= 4)
{
memmove(pAE, "gzip", 4);
memset(pAE + 4, ' ', len - 4);
}
}
else
{
pExtraHeader = m_extraHeader;
headerLen += 23;
}
#endif
if (*(pBegin + --m_iTotalPending - 1) == '\r')
--m_iTotalPending;
if (*pForward)
{
if ((pBegin + m_iTotalPending) -
(pForward + pReq->getHeaderLen(HttpHeader::H_X_FORWARDED_FOR)) == 2)
{
const char *p = pForward -= 16;
while (*(p - 1) != '\n')
--p;
m_iTotalPending = p - pBegin;
}
}
//reconstruct request line if URL has been rewritten
if (pReq->getRedirects() > 0)
{
const char *pReqLine = pReq->encodeReqLine(newReqLineLen);
if (newReqLineLen > 0)
{
m_iovec.append(pReqLine, newReqLineLen);
pBegin += pReq->getOrgReqLineLen() - 9;
m_iTotalPending -= pReq->getOrgReqLineLen() - 9;
}
}
int newHostLen = pReq->getNewHostLen();
char *pHost = (char *)pReq->getHeader(HttpHeader::H_HOST);
int hostLen = pReq->getHeaderLen(HttpHeader::H_HOST);
if (newHostLen > 0)
{
if (*pHost)
{
m_iovec.append(pBegin, pHost - pBegin);
m_iovec.append(pReq->getNewHost(), newHostLen);
m_iovec.append(pHost + hostLen,
pBegin + m_iTotalPending - pHost - hostLen);
m_iTotalPending += (newHostLen - hostLen);
}
else
{
m_iovec.append(pBegin, m_iTotalPending);
m_iovec.append("Host: ", 6);
m_iovec.append(pReq->getNewHost(), newHostLen);
m_iovec.append("\r\n", 2);
m_iTotalPending += newHostLen + 8;
}
}
else
m_iovec.append(pBegin, m_iTotalPending);
m_iTotalPending += newReqLineLen;
//.........这里部分代码省略.........
示例15: HioChainStream
HttpSession *HttpSession::newSubSession(SubSessInfo_t *pSubSessInfo)
{
//for subsession, we intentionally turn off
// keepalive
// chunk
// gzip compression
// security
//detect loop subsessions
int depth = 1;
if (m_pParent)
{
depth = 1 + ((HioChainStream *)getStream())->getDepth();
if (depth > 9)
return NULL;
}
if (detectLoopSubSession(pSubSessInfo) == 1)
return NULL;
HttpSession *pSession = HttpSessionPool::getSession();
if (! pSession)
return NULL;
//pSession->setSsiRuntime( m_pSsiRuntime );
HioChainStream *pStream = new HioChainStream();
pStream->setHandler(pSession);
pSession->setStream(pStream);
pSession->getReq()->setILog(pStream);
pSession->m_pClientInfo = m_pClientInfo;
pSession->m_pSslConn = m_pSslConn;
pStream->setDepth(depth);
pSession->getReq()->setMethod(pSubSessInfo->m_method);
if (pSession->getReq()->clone(getReq(), pSubSessInfo))
{
pStream->setHandler(NULL);
delete pStream;
HttpSessionPool::recycle(pSession);
return NULL;
}
pSession->setFlag(HSF_SEC_CLEARED | HSF_SEC_RESP_CLEARED |
HSF_SUB_SESSION);
pSession->getResp()->reset();
#ifdef _ENTERPRISE_
pSession->getResp()->setCacheStore(getCacheStore());
#endif
LS_DBG_M(getLogSession(), "Create SUB SESSION: %d, flag: %d, "
"method: %s, URI: %s, len: %d, QS: %s, len: %d",
m_iSubReqSeq, pSubSessInfo->m_flag,
HttpMethod::get(pSubSessInfo->m_method),
pSubSessInfo->m_cacheKey.m_pUri,
pSubSessInfo->m_cacheKey.m_iUriLen,
pSubSessInfo->m_cacheKey.m_pQs ? pSubSessInfo->m_cacheKey.m_pQs : "",
pSubSessInfo->m_cacheKey.m_iQsLen);
HttpSession *parent = NULL;
if (pSubSessInfo->m_flag & SUB_REQ_DETACHED)
{
pStream->setParentSession(NULL);
//set Stream to black hole mode,
pStream->setFlag(HIO_FLAG_BLACK_HOLE, 1);
//parent = getBackGroundSession();
}
else
{
pStream->setSequence(m_iSubReqSeq++);
parent = this;
}
if (pSubSessInfo->m_flag & SUB_REQ_NOABORT)
pSession->setFlag(HSF_NO_ABORT, 1);
if (pSubSessInfo->m_flag & SUB_REQ_NOCACHE)
pSession->setFlag(HSF_NOCACHE, 1);
pSession->m_pParent = parent;
return pSession;
}