void TestRecordedRequest::accessors() { QList<QString> headers; headers << "User-Agent: qt" << "Cookie: q=1" << "Cookie: t=2" << "X-Whitespace: left" << "X-Whitespace:right " << "X-Whitespace: both "; QList<int> chunkSizes; QByteArray body("ABC"); QString requestLine("GET / HTTP/1.1"); RecordedRequest request(requestLine, headers, chunkSizes, body.length(), body, 0); QCOMPARE(request.path(), QString("/")); QCOMPARE(request.header("cookie"), QString("q=1")); QList<QString> cookieHeaders = QList<QString>() << "q=1" << "t=2"; QCOMPARE(request.headers("cookie"), cookieHeaders); QCOMPARE(request.header("x-whitespace"), QString("left")); QList<QString> wsHeaders = QList<QString>() << "left" << "right" << "both"; QCOMPARE(request.headers("x-whitespace"), wsHeaders); QCOMPARE(request.body(), body); }
void GameClient::initialise(const std::string& nm){ std::cout<<"Loading...\n"; std::string map = requestLine("/init map"); std::cout<<"Contacted Server, loading map..\n"; wl.readString(map); readerThread.start(); //Loading player! mainPlayer = new Player(&wl); mainPlayer->setTextureManager(wl.getTextureManager()); mainPlayer->setTexturePrefix("cube_box"); mainPlayer->setName(nm); std::stringstream ss; ss<<requestLine("/init main_player_config " + nm); std::string str; ss>>str; if (str != "/object") std::cout<<"Bad response from the server: "<<str<<" "<<ss.str()<<std::endl; ss>>str; if (str != "player") std::cout<<"Bad response from the server: /object"<<str<<" "<<ss.str()<<std::endl; ss>>str; mainPlayer->setObjectID(str); mainPlayer->updateFromString(ss); std::cout<<"Main player loaded!\n"; str = requestLine("/init ready"); if (str != "ACK"){ std::cout<<"Error. Bad response from the server!\n"; ::exit(1); } //attach mouse.. void mouseMovement(int,int); glfwSetMousePosCallback(mouseMovement); }
am_status_t BaseService::sendRequest(Connection& conn, const BodyChunk& headerPrefix, const std::string& uri, const std::string& uriParameters, const Http::HeaderList& headerList, const Http::CookieList& cookieList, const BodyChunk& contentLine, const BodyChunk& headerSuffix, const BodyChunkList& bodyChunkList) const { am_status_t status; std::string requestLine(headerPrefix.data); requestLine.append(uri); requestLine.append(uriParameters); requestLine.append(HTTP_VERSION_SUFFIX); Log::log(logModule, Log::LOG_MAX_DEBUG, "BaseService::sendRequest " "Request line: %s", requestLine.c_str()); status = sendChunk(conn, BodyChunk(requestLine)); if (AM_SUCCESS == status) { std::string cookieLine; // XXX - Need to send cookies here. size_t hListSize = headerList.size(); Http::Cookie theCookie; for(size_t idx = 0; idx < hListSize; idx++) { theCookie = headerList[idx]; cookieLine.append(theCookie.name); cookieLine.append(": "); cookieLine.append(theCookie.value); cookieLine.append("\r\n"); } size_t listSize = cookieList.size(); if(listSize > 0) { cookieLine.append("Cookie: "); for (size_t iii=0; iii < listSize; iii++) { theCookie = cookieList[iii]; cookieLine.append(theCookie.name); cookieLine.append("="); cookieLine.append(theCookie.value); if (iii == listSize-1) { cookieLine.append("\r\n"); } else { cookieLine.append(";"); } } } Log::log(logModule, Log::LOG_DEBUG, "BaseService::sendRequest " "Cookie and Headers =%s ", cookieLine.c_str()); if (cookieLine.size() > 0) { status = sendChunk(conn, BodyChunk(cookieLine)); } Log::log(logModule, Log::LOG_DEBUG, "BaseService::sendRequest " "Content-Length =%s.", contentLine.data.c_str()); if (AM_SUCCESS == status) { status = sendChunk(conn, contentLine); } Log::log(logModule, Log::LOG_DEBUG, "BaseService::sendRequest " "Header Suffix =%s ", headerSuffix.data.c_str()); if (AM_SUCCESS == status) { status = sendChunk(conn, headerSuffix); if (AM_SUCCESS == status) { Log::log(logModule, Log::LOG_MAX_DEBUG, "BaseService::sendRequest(): " "Total chunks: %ld.", bodyChunkList.size()); std::size_t i = 0; for (i = 0; i < bodyChunkList.size(); ++i) { status = sendChunk(conn, bodyChunkList[i]); if (AM_SUCCESS != status) { Log::log(logModule, Log::LOG_ERROR, "BaseService::sendRequest " "Sending chunk %ld failed with error: %s", i, am_status_to_string(status)); break; } } Log::log(logModule, Log::LOG_MAX_DEBUG, "BaseService::sendRequest(): " "Sent %ld chunks.", i); } } } return status; }