int ZnsHelper::loadChecks(const SourceT& srcInfo, ChecksT& checks, const QString& filterValue, ngrt4n::RequestFilterT filterType) { setBaseUrl(srcInfo.mon_url); // Log in if not yet the case if (! m_isLogged && openSession(srcInfo) != 0) return -1; if (! m_isLogged) return -1; checks.clear(); QNetworkReply* response = NULL; setRouterEndpoint(Device); if (filterType == ngrt4n::GroupFilter) { response = postRequest(Device, ngrt4n::toByteArray(ReqPatterns[Device].arg("groups", filterValue, QString::number(Device)))); } else { response = postRequest(Device, ngrt4n::toByteArray(ReqPatterns[Device].arg("name", filterValue, QString::number(Device)))); } if (! response || processDeviceReply(response, checks) !=0) { return -1; } return 0; }
int ZnsHelper::processDeviceReply(QNetworkReply* reply, ChecksT& checks) { if (parseReply(reply) != 0) return -1; if (! checkRPCResultStatus()) return -1; // check weird reponse qint32 tid = m_replyJsonData.getProperty("tid").toInt32(); if (tid != ZnsHelper::Device) { m_lastError = tr("Weird transaction type set for device (%1)").arg(tid); return -1; } QScriptValueIterator devices(m_replyJsonData.getProperty("result").property("devices")); while (devices.hasNext()) { devices.next(); if (devices.flags()&QScriptValue::SkipInEnumeration) continue; QScriptValue curDevice = devices.value(); QString deviceUid = curDevice.property("uid").toString(); QNetworkReply* response = NULL; response = postRequest(Component, ngrt4n::toByteArray(ReqPatterns[Component].arg(deviceUid, QString::number(Component)))); processComponentReply(response, checks); //retrieve ping info response = postRequest(DeviceInfo, ngrt4n::toByteArray(ReqPatterns[DeviceInfo].arg(deviceUid, QString::number(DeviceInfo)))); processDeviceInfoReply(response, checks); } return 0; }
void WebUploader::uploadNext() { if(!arenaCards.isEmpty()) { uploadArenaCards(); } else if(!gameResultPostList->isEmpty()) { GameResultPost gamePost = gameResultPostList->first(); gameResultPostList->removeFirst(); if(!gamePost.postData.hasQueryItem("arena")) { gamePost.postData.addQueryItem("arena", QString::number(arenaCurrentID)); } postRequest(gamePost.request, gamePost.postData); qDebug() << "WebUploader: " << "Juego nuevo uploaded."; emit sendLog(tr("Web: New game uploaded.")); webState = reloadArenaCurrent1; } else if(rewardsPost != NULL) { if(!rewardsPost->postData.hasQueryItem("arena")) { rewardsPost->postData.addQueryItem("arena", QString::number(arenaCurrentID)); } postRequest(rewardsPost->request, rewardsPost->postData); qDebug() << "WebUploader: " << "Rewards uploaded."; emit sendLog(tr("Web: New rewards uploaded.")); webState = checkArenaCurrentReload1; delete rewardsPost; rewardsPost = NULL; } }
void QNetworkAccessHttpBackend::open() { QUrl url = request().url(); bool encrypt = url.scheme() == QLatin1String("https"); setAttribute(QNetworkRequest::ConnectionEncryptedAttribute, encrypt); // set the port number in the reply if it wasn't set url.setPort(url.port(encrypt ? DefaultHttpsPort : DefaultHttpPort)); // check if we have an open connection to this host QByteArray cacheKey = makeCacheKey(this->url()); QNetworkAccessCache *cache = QNetworkAccessManagerPrivate::getCache(this); if ((http = static_cast<QNetworkAccessHttpBackendCache *>(cache->requestEntryNow(cacheKey))) == 0) { // no entry in cache; create an object http = new QNetworkAccessHttpBackendCache(url.host(), url.port(), encrypt); #ifndef QT_NO_NETWORKPROXY QNetworkProxy networkProxy = proxy(); if (encrypt || networkProxy.type() == QNetworkProxy::HttpProxy) http->setTransparentProxy(networkProxy); else http->setCacheProxy(networkProxy); #endif cache->addEntry(cacheKey, http); } setupConnection(); postRequest(); }
int main(int argc, char * argv[]) { if (argc < 3) { printHelp(); exit(1); } printf("Client is running...\n"); char help_cmd[] = "help"; char req_cmd[] = "req"; while (true) { printf("Command: "); char * command = getCommand(); if (strcmp(command, help_cmd)==0) { printf("Possible commands:\n"); printf("- help : help\n"); printf("- req : post a request.\n"); printf("-- 1. [query]\n"); printf("-- 2. [answer|...]\n"); } else if (strcmp(command, req_cmd)==0) { char msg[128]; printf("Request: "); scanf("%s", msg); char * result = postRequest(msg, argv[1], argv[2]); printf("[Server] : %s\n", result); delete result; } else { printf("Unknown command\n"); } delete command; } return 0; }
void QPushbulletHandler::requestPush(Push &push, QString deviceID, QString email) { /* [x] Note * [x] Link * [x] Address * [x] List * [] File */ QJsonDocument jsonDocument; QJsonObject jsonObject; if (push.type == PUSH_TYPE::ADDRESS) jsonObject["type"] = "address"; else if (push.type == PUSH_TYPE::FILE) jsonObject["type"] = "file"; else if (push.type == PUSH_TYPE::LINK) jsonObject["type"] = "link"; else if (push.type == PUSH_TYPE::LIST) jsonObject["type"] = "list"; else if (push.type == PUSH_TYPE::NOTE) jsonObject["type"] = "note"; if (!deviceID.isEmpty()) jsonObject["device_iden"] = deviceID; else if (!email.isEmpty()) jsonObject["email"] = email; if (push.type == PUSH_TYPE::NOTE) { jsonObject["title"] = push.title; jsonObject["body"] = push.body; } else if (push.type == PUSH_TYPE::LINK) { jsonObject["url"] = push.url; jsonObject["title"] = push.title; jsonObject["body"] = push.body; } else if (push.type == PUSH_TYPE::ADDRESS) { jsonObject["name"] = push.addressName; jsonObject["address"] = push.address; } else if (push.type == PUSH_TYPE::LIST) { jsonObject["type"] = "list"; jsonObject["title"] = push.title; QJsonArray jsonArray; for (QString item : push.listItems) { jsonArray.append(QJsonValue(item)); } jsonObject["items"] = jsonArray; } else if (push.type == PUSH_TYPE::FILE) { jsonObject["file_name"] = push.fileName; jsonObject["file_type"] = push.fileType; jsonObject["file_url"] = push.fileURL; jsonObject["body"] = push.body; } m_CurrentOperation = CURRENT_OPERATION::PUSH; jsonDocument.setObject(jsonObject); qDebug() << QString(jsonDocument.toJson()); postRequest(m_URLPushes, jsonDocument.toJson()); }
void Copy::file(const Items::Data &source, const QString &destination) { sourceData = source; postData = queries.getCopyFileData(source.name, destination); queries.setRawHeader(SettingsManager().accessToken(), request); postRequest(queries.constructCopyFileUrl(source.self)); }
void QPushbulletHandler::requestCreateContact(QString name, QString email) { QUrlQuery query; query.addQueryItem("name", name); query.addQueryItem("email", email); m_CurrentOperation = CURRENT_OPERATION::CREATE_CONTACT; postRequest(m_URLContacts, query.toString(QUrl::FullyEncoded).toUtf8()); }
void AmMediaProcessorThread::processAudio(unsigned long long ts) { // receiving for(set<AmMediaSession*>::iterator it = sessions.begin(); it != sessions.end(); it++) { if ((*it)->readStreams(ts, buffer) < 0) postRequest(new SchedRequest(AmMediaProcessor::ClearSession, *it)); } // sending for(set<AmMediaSession*>::iterator it = sessions.begin(); it != sessions.end(); it++) { if ((*it)->writeStreams(ts, buffer) < 0) postRequest(new SchedRequest(AmMediaProcessor::ClearSession, *it)); } }
void YouTube::addToFavourites(const QString &videoId) { QUrl url("http://gdata.youtube.com/feeds/api/users/default/favorites"); QByteArray xml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \ "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" \ "<id>" + videoId.toAscii() + "</id>\n" \ "</entry>"); postRequest(url, xml); connect(this, SIGNAL(postSuccessful()), this, SIGNAL(addedToFavourites())); connect(this, SIGNAL(postFailed()), this, SIGNAL(videoInFavourites())); }
void YouTube::addToPlaylist(const QString &videoId, const QString &playlistId) { QUrl url("http://gdata.youtube.com/feeds/api/playlists/" + playlistId); QByteArray xml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \ "<entry xmlns=\"http://www.w3.org/2005/Atom\"\n" \ "xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">\n" \ "<id>" + videoId.toAscii() + "</id>\n" \ "</entry>"); postRequest(url, xml); connect(this, SIGNAL(postSuccessful()), this, SIGNAL(addedToPlaylist())); }
void MainWindow::tooOldButtonClicked() { QNetworkRequest postRequest(QUrl("http://bash.im/quote/" + QString::number(currentID))); postRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); QNetworkAccessManager *postManager = new QNetworkAccessManager(this); postManager->post(postRequest, "/bayan"); loadNewPage(); delete postManager; }
void YouTube::addComment(const QString &videoId, const QString &comment) { QUrl url("http://gdata.youtube.com/feeds/api/videos/" + videoId + "/comments"); QByteArray xml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \ "<entry xmlns=\"http://www.w3.org/2005/Atom\"\n" \ "xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">\n" \ "<content>" + comment.toAscii().toPercentEncoding(" \n\t#[]{}=+$&*()<>@|',/!\":;?") + "</content>\n" \ "</entry>"); postRequest(url, xml); connect(this, SIGNAL(postSuccessful()), this, SIGNAL(commentAdded())); }
void QPushbulletHandler::requestPushUpdate(QString pushID, bool dismissed) { QUrlQuery query; query.addQueryItem("dismissed", dismissed ? "true" : "false"); QString url = m_URLPushes.toString(); url.append("/"); url.append(pushID); QUrl modifiedURL(url); m_CurrentOperation = CURRENT_OPERATION::PUSH_UPDATE; postRequest(modifiedURL, query.toString(QUrl::FullyEncoded).toUtf8()); }
void QPushbulletHandler::requestContactUpdate(QString contactID, QString newName) { QString url = m_URLContacts.toString(); url.append("/"); url.append(contactID); QUrl modifiedURL(url); QUrlQuery query; query.addQueryItem("name", newName); m_CurrentOperation = CURRENT_OPERATION::UPDATE_CONTACT; postRequest(modifiedURL, query.toString(QUrl::FullyEncoded).toUtf8()); }
void QPushbulletHandler::requestDeviceUpdate(QString deviceID, QString newNickname) { QString url = m_URLDevices.toString(); url.append("/"); url.append(deviceID); QUrl modifiedURL(url); QUrlQuery query; query.addQueryItem("nickname", newNickname); m_CurrentOperation = CURRENT_OPERATION::UPDATE_DEVICE; postRequest(modifiedURL, query.toString(QUrl::FullyEncoded).toUtf8()); }
void YouTube::rateVideo(const QString &videoId, const QString &likeOrDislike) { QUrl url("http://gdata.youtube.com/feeds/api/videos/" + videoId + "/ratings"); QByteArray xml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \ "<entry xmlns=\"http://www.w3.org/2005/Atom\"\n" \ "xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">\n" \ "<yt:rating value=\"" + likeOrDislike.toAscii() + "\"/>\n" \ "</entry>"); postRequest(url, xml); connect(this, SIGNAL(postSuccessful()), this, SIGNAL(videoRated())); connect(this, SIGNAL(postFailed()), this, SIGNAL(cannotRate())); }
void Messages::writeMessage(const char* mode, const char* from, const char* msg) { if (!msg) return; uptr<UStr> text = null; uptr<UStr> prefix = null; uptr<UColor> prefix_color = null; if (from) { std::string result; postRequest(msg, result); text = new UStr(result); prefix = new UStr("from "); prefix->append(from); prefix->append("> "); prefix_color = &::g.theme.chatColor; } else if (mode) { text = new UStr(msg); if (! strcmp(mode, "notice")) { prefix = new UStr(mode); prefix->append("> "); prefix_color = ::g.theme.noticeColor; } else if (! strcmp(mode, "progress")) { prefix = new UStr(""); prefix_color = ::g.theme.noticeColor; messages.add(uhbox(ugroup(UFont::bold + prefix_color) + text)); } else if (! strcmp(mode, "request")) { prefix = new UStr(mode); prefix->append("> "); prefix_color = ::g.theme.requestColor; } else { prefix = new UStr(mode); prefix->append("> "); prefix_color = ::g.theme.warningColor; } } else { text = new UStr(msg); prefix = new UStr("> "); prefix_color = ::g.theme.messColor; } messages.add(uhbox(ugroup(UFont::bold + prefix_color + prefix) + text)); return; }
void QPushbulletHandler::requestDeviceDelete(QString deviceID) { QString url = m_URLDevices.toString(); url.append("/"); url.append(deviceID); QUrl modifiedURL(url); m_CurrentOperation = CURRENT_OPERATION::DELETE_DEVICE; QUrlQuery query; query.setQueryDelimiters(' ', '&'); query.addQueryItem("-X", "DELETE"); postRequest(modifiedURL, query.toString(QUrl::FullyEncoded).toUtf8()); }
void YouTube::subscribeToChannel(const QString &username) { QUrl url("http://gdata.youtube.com/feeds/api/users/default/subscriptions"); QByteArray xml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \ "<entry xmlns=\"http://www.w3.org/2005/Atom\"\n" \ "xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">\n" \ "<category scheme=\"http://gdata.youtube.com/schemas/2007/subscriptiontypes.cat\"\n" \ "term=\"channel\"/>\n" \ "<yt:username>" + username.toAscii() + "</yt:username>\n" \ "</entry>"); postRequest(url, xml); connect(this, SIGNAL(postSuccessful()), this, SIGNAL(subscribed())); }
void YouTube::replyToComment(const QString &videoId, const QString &commentId, const QString &comment) { QUrl url("http://gdata.youtube.com/feeds/api/videos/" + videoId + "/comments"); QByteArray xml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \ "<entry xmlns=\"http://www.w3.org/2005/Atom\"\n" \ "xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">\n" \ "<link rel=\"http://gdata.youtube.com/schemas/2007#in-reply-to\"\n" \ "type=\"application/atom+xml\"\n" \ "href=\"http://gdata.youtube.com/feeds/api/videos/" + videoId.toAscii() + "/comments/" + commentId.toAscii() + "\"/>\n" \ "<content>" + comment.toAscii().toPercentEncoding(" \n\t#[]{}=+$&*()<>@|',/!\":;?") + "</content>\n" \ "</entry>"); postRequest(url, xml); }
void QPushbulletHandler::requestCreateDevice(QString deviceName, QString model) { QJsonDocument doc; QJsonObject obj; obj["nickname"] = deviceName; obj["type"] = "stream"; if (!model.isEmpty()) obj["manufacturer"] = model; doc.setObject(obj); m_CurrentOperation = CURRENT_OPERATION::CREATE_DEVICE; postRequest(m_URLDevices, doc.toJson()); }
ResponseCode MuHttpServer::HandleRequest(HttpRequest *pHttpRequest, HttpResponse *pHttpResponse) { debug(pHttpRequest); if (!mAllowNonLocal && pHttpRequest->RemoteAddress() != "127.0.0.1") { QString errorString = QString("<html><body><h1>Forbidden</h1>" "Connection from %1 has been blocked. Only localhost connections are allowed.</body></html>") .arg(QString::fromStdString(pHttpRequest->RemoteAddress())); pHttpResponse->SetBody(errorString.toAscii(), errorString.size()); warning(errorString); return HTTPRESPONSECODE_403_FORBIDDEN; } QString uri = QString::fromStdString(pHttpRequest->Uri()).split("?")[0]; if (pHttpRequest->Method() == REQUESTMETHOD_GET || pHttpRequest->Method() == REQUESTMETHOD_POST) { QString contentType = pHttpRequest->Headers("content-type").c_str(); QString body = pHttpRequest->Body().c_str(); Response rsp = (pHttpRequest->Method() == REQUESTMETHOD_GET) ? getRequest(uri, contentType, body, pHttpRequest->FormValues()) : postRequest(uri, contentType, body, pHttpRequest->FormValues()); if (rsp.mCode != HTTPRESPONSECODE_INVALID && rsp.mEncoding.isValid()) { switch (rsp.mEncoding) { case Response::ASCII: pHttpResponse->SetBody(rsp.mBody.toAscii(), rsp.mBody.toAscii().length()); break; case Response::UTF8: pHttpResponse->SetBody(rsp.mBody.toUtf8(), rsp.mBody.toUtf8().length()); break; case Response::OCTET: pHttpResponse->SetBody(rsp.mOctets.constData(), rsp.mOctets.length()); break; } QMapIterator<QString,QString> headerIt(rsp.mHeaders); while (headerIt.hasNext()) { headerIt.next(); pHttpResponse->SetHeader(headerIt.key().toStdString(), headerIt.value().toStdString()); } return rsp.mCode; } } // default to responding with an internal server error std::string errorString = "<html><body><h1>Internal server error</h1>An unknown error occured.</body></html>"; pHttpResponse->SetBody(errorString.c_str(), errorString.size()); warning(QString::fromStdString(errorString)); return HTTPRESPONSECODE_500_INTERNALSERVERERROR; }
void YouTube::createNewPlaylist(const QString &title, const QString &description, const bool &isPrivate) { QUrl url("http://gdata.youtube.com/feeds/api/users/default/playlists"); QByteArray xml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \ "<entry xmlns=\"http://www.w3.org/2005/Atom\"\n" \ "xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">\n" \ "<title>" + title.toAscii().toPercentEncoding(" \n\t#[]{}=+$&*()<>@|',/!\":;?") + "</title>\n" \ "<summary>" + description.toAscii().toPercentEncoding(" \n\t#[]{}=+$&*()<>@|',/!\":;?") + "</summary>\n" \ "</entry>"); if (isPrivate) { int index = xml.lastIndexOf("<"); xml.insert(index, "<yt:private/>\n"); } postRequest(url, xml); connect(this, SIGNAL(postSuccessful()), this, SIGNAL(playlistCreated())); }
int ZnsHelper::openSession(const SourceT& srcInfo) { setBaseUrl(srcInfo.mon_url); QStringList authInfo = ngrt4n::getAuthInfo(srcInfo.auth); if (authInfo.size() != 2) { m_lastError = tr("Bad auth string, should be in the form of login:password"); return -1; } setBaseUrl(srcInfo.mon_url); #if QT_VERSION < QT_VERSION_CHECK(5,0,0) QUrl params; #else QUrlQuery params; #endif params.addQueryItem("__ac_name", authInfo[0]); params.addQueryItem("__ac_password", authInfo[1]); params.addQueryItem("submitted", "true"); params.addQueryItem("came_from", getApiContextEndpoint()); setSslPeerVerification(srcInfo.verify_ssl_peer != 0); QNetworkReply* response = NULL; #if QT_VERSION < QT_VERSION_CHECK(5,0,0) response = postRequest(ZnsHelper::Login, params.encodedQuery()); #else response = postRequest(ZnsHelper::Login, params.query(QUrl::FullyEncoded).toUtf8()); #endif if (! response || processLoginReply(response) != 0) { return -1; } return 0; }
void WebUploader::connectWeb() { QString playerEmail, password; readSettings(playerEmail, password); QURL postData; postData.addQueryItem("signin", "1"); postData.addQueryItem("playerEmail", playerEmail); postData.addQueryItem("password", password); QNetworkRequest request(QUrl(WEB_URL + "index.php")); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); postRequest(request, postData); }
void WebUploader::uploadArenaCards() { QURL postData; postData.addQueryItem("batchImportPwn", "1"); postData.addQueryItem("importReviewed", "1"); postData.addQueryItem("importDataBlock", arenaCards); QNetworkRequest request(QUrl(WEB_URL + "import_cards.php?arena=" + QString::number(arenaCurrentID))); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); postRequest(request, postData); arenaCards = ""; deckInWeb = true; qDebug() << "WebUploader: " << "Complete deck uploaded."; emit sendLog(tr("Web: Complete deck uploaded.")); }
TEST_F(FrameFetchContextTest, MainResource) { // Default case ResourceRequest request("http://www.example.com"); EXPECT_EQ(UseProtocolCachePolicy, fetchContext->resourceRequestCachePolicy(request, Resource::MainResource)); // Post ResourceRequest postRequest("http://www.example.com"); postRequest.setHTTPMethod("POST"); EXPECT_EQ(ReloadIgnoringCacheData, fetchContext->resourceRequestCachePolicy(postRequest, Resource::MainResource)); // Re-post document->frame()->loader().setLoadType(FrameLoadTypeBackForward); EXPECT_EQ(ReturnCacheDataDontLoad, fetchContext->resourceRequestCachePolicy(postRequest, Resource::MainResource)); // Enconding overriden document->frame()->loader().setLoadType(FrameLoadTypeStandard); document->frame()->host()->setOverrideEncoding("foo"); EXPECT_EQ(ReturnCacheDataElseLoad, fetchContext->resourceRequestCachePolicy(request, Resource::MainResource)); document->frame()->host()->setOverrideEncoding(AtomicString()); // FrameLoadTypeSame document->frame()->loader().setLoadType(FrameLoadTypeSame); EXPECT_EQ(ReloadIgnoringCacheData, fetchContext->resourceRequestCachePolicy(request, Resource::MainResource)); // Conditional request document->frame()->loader().setLoadType(FrameLoadTypeStandard); ResourceRequest conditional("http://www.example.com"); conditional.setHTTPHeaderField("If-Modified-Since", "foo"); EXPECT_EQ(ReloadIgnoringCacheData, fetchContext->resourceRequestCachePolicy(conditional, Resource::MainResource)); // Set up a child frame FrameFetchContext* childFetchContext = createChildFrame(); // Child frame as part of back/forward document->frame()->loader().setLoadType(FrameLoadTypeBackForward); EXPECT_EQ(ReturnCacheDataElseLoad, childFetchContext->resourceRequestCachePolicy(request, Resource::MainResource)); // Child frame as part of reload document->frame()->loader().setLoadType(FrameLoadTypeReload); EXPECT_EQ(ReloadIgnoringCacheData, childFetchContext->resourceRequestCachePolicy(request, Resource::MainResource)); // Child frame as part of end to end reload document->frame()->loader().setLoadType(FrameLoadTypeReloadFromOrigin); EXPECT_EQ(ReloadBypassingCache, childFetchContext->resourceRequestCachePolicy(request, Resource::MainResource)); }
TEST_F(FrameFetchContextTest, MainResource) { // Default case ResourceRequest request("http://www.example.com"); EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, fetchContext->resourceRequestCachePolicy(request, Resource::MainResource, FetchRequest::NoDefer)); // Post ResourceRequest postRequest("http://www.example.com"); postRequest.setHTTPMethod("POST"); EXPECT_EQ(WebCachePolicy::ValidatingCacheData, fetchContext->resourceRequestCachePolicy(postRequest, Resource::MainResource, FetchRequest::NoDefer)); // Re-post document->frame()->loader().setLoadType(FrameLoadTypeBackForward); EXPECT_EQ(WebCachePolicy::ReturnCacheDataDontLoad, fetchContext->resourceRequestCachePolicy(postRequest, Resource::MainResource, FetchRequest::NoDefer)); // Enconding overriden document->frame()->loader().setLoadType(FrameLoadTypeStandard); document->frame()->host()->setOverrideEncoding("foo"); EXPECT_EQ(WebCachePolicy::ReturnCacheDataElseLoad, fetchContext->resourceRequestCachePolicy(request, Resource::MainResource, FetchRequest::NoDefer)); document->frame()->host()->setOverrideEncoding(AtomicString()); // FrameLoadTypeReloadMainResource document->frame()->loader().setLoadType(FrameLoadTypeReloadMainResource); EXPECT_EQ(WebCachePolicy::ValidatingCacheData, fetchContext->resourceRequestCachePolicy(request, Resource::MainResource, FetchRequest::NoDefer)); // Conditional request document->frame()->loader().setLoadType(FrameLoadTypeStandard); ResourceRequest conditional("http://www.example.com"); conditional.setHTTPHeaderField(HTTPNames::If_Modified_Since, "foo"); EXPECT_EQ(WebCachePolicy::ValidatingCacheData, fetchContext->resourceRequestCachePolicy(conditional, Resource::MainResource, FetchRequest::NoDefer)); // Set up a child frame FrameFetchContext* childFetchContext = createChildFrame(); // Child frame as part of back/forward document->frame()->loader().setLoadType(FrameLoadTypeBackForward); EXPECT_EQ(WebCachePolicy::ReturnCacheDataElseLoad, childFetchContext->resourceRequestCachePolicy(request, Resource::MainResource, FetchRequest::NoDefer)); // Child frame as part of reload document->frame()->loader().setLoadType(FrameLoadTypeReload); EXPECT_EQ(WebCachePolicy::ValidatingCacheData, childFetchContext->resourceRequestCachePolicy(request, Resource::MainResource, FetchRequest::NoDefer)); // Child frame as part of reload bypassing cache document->frame()->loader().setLoadType(FrameLoadTypeReloadBypassingCache); EXPECT_EQ(WebCachePolicy::BypassingCache, childFetchContext->resourceRequestCachePolicy(request, Resource::MainResource, FetchRequest::NoDefer)); }
/** * @brief Handles what request was instantiated and the corrensponding action * * @param handler The EntityHandler * @param resource Base resource * * @return the result of the request */ OCEntityHandlerResult requestHandler(OCEntityHandlerRequest *ehRequest, OCBaseResourceT *resource, OCRepPayload **payload) { OCEntityHandlerResult ehResult = OC_EH_ERROR; // Prepare the payload OCRepPayload *constructedPayload = getPayload(ehRequest, resource); if(!constructedPayload) { OIC_LOG(ERROR, TAG, "Unable to construct a payload."); return OC_EH_ERROR; } // Check what request was instantiated switch(ehRequest->method) { case OC_REST_GET: OIC_LOG(DEBUG, TAG, "GET Request"); ehResult = getRequest(resource, constructedPayload); break; case OC_REST_PUT: OIC_LOG(DEBUG, TAG, "PUT Request"); ehResult = putRequest(ehRequest, constructedPayload, resource); break; case OC_REST_POST: OIC_LOG(DEBUG, TAG, "POST Request"); ehResult = postRequest(ehRequest, constructedPayload, resource); break; case OC_REST_DELETE: //ehResult = deleteRequest(resource); break; case OC_REST_DISCOVER: OIC_LOG(DEBUG, TAG, "Request is discover!"); break; default: ehResult = OC_EH_ERROR; } *payload = constructedPayload; return ehResult; }