Example #1
0
    /* The parse function is invoked after the loadFinished signal is received 
     * from  the webkit code upon successfully parsing a page. From here, the 
     * entire DOM can be manipulated and traversed really conveniently. The 
     * code right now just traverses the DOM looking for link tags, and queues 
     * them if they are valid, but this function is where all of the 
     * interesting development will take place in the future. 
     */
   void Parser::parse() {
      QUrl currentUrl;
      QWebElementCollection linkTags =
         page->mainFrame()->findAllElements("a");

      foreach(QWebElement current, linkTags) {
         currentUrl = QUrl(current.attribute("href"));
         /* This discards the fragment. It is useless in this context and
          * will complicate our visited hashtable.
          */
         currentUrl.setEncodedFragment(QByteArray());

         if (currentUrl.isEmpty()) {
            continue;
         }

         /* Prepend the parent URL if we have a relative link in an attempt
          * to validate it for retrieval.
          */
         if (currentUrl.isRelative() &&
            currentUrl.host() == "" && currentUrl.path() != "") {
            qDebug() << currentUrl << " is relative path. prepending host";
            currentUrl.setHost(url.host());
            currentUrl.setScheme(url.scheme());
            qDebug() << "with host fix: " << currentUrl;
         }

         /* Finally, check to make sure it's valid before queueing it */
         if (validateUrl(currentUrl)) {
            parsedUrls.push_back(currentUrl);
         }
      }
Example #2
0
bool Pillow::HttpHandlerProxy::handleRequest(Pillow::HttpConnection *request)
{
	if (_proxiedUrl.isEmpty()) return false;

	QUrl targetUrl = _proxiedUrl;
	targetUrl.setEncodedPath(request->requestPath());
	if (!request->requestQueryString().isEmpty()) targetUrl.setEncodedQuery(request->requestQueryString());
	if (!request->requestFragment().isEmpty()) targetUrl.setEncodedFragment(request->requestFragment());

	QNetworkRequest proxiedRequest(targetUrl);
	foreach (const Pillow::HttpHeader& header, request->requestHeaders())
		proxiedRequest.setRawHeader(header.first, header.second);

	createPipe(request, createProxiedReply(request, proxiedRequest));

	return true;
}
Example #3
0
void QUrlProto::setEncodedFragment(const QByteArray &fragment)
{
  QUrl *item = qscriptvalue_cast<QUrl*>(thisObject());
  if (item)
    item->setEncodedFragment(fragment);
}