Ejemplo n.º 1
0
bool operator == (const URI& lhs, const URI& rhs) noexcept {
  return icase_equal(lhs.scheme(), rhs.scheme())
         and (lhs.userinfo() == rhs.userinfo())
         and icase_equal(lhs.host(), rhs.host())
         and lhs.port() == rhs.port()
         and lhs.path() == rhs.path()
         and lhs.query() == rhs.query()
         and lhs.fragment() == rhs.fragment();
}
Variant BaseVariantAppProtocolHandler::GetScaffold(string uriString) {
	//1. Search in the cache first
	if (_urlCache.HasKey(uriString)) {
		return _urlCache[uriString];
	}

	//2. Build it
	Variant result;

	//3. Split the URL into components
	URI uri;
	if (!URI::FromString(uriString, true, uri)) {
		FATAL("Invalid url: %s", STR(uriString));
		return Variant();
	}

	//6. build the end result
	result["username"] = uri.userName();
	result["password"] = uri.password();
	result["host"] = uri.host();
	result["ip"] = uri.ip();
	result["port"] = uri.port();
	result["document"] = uri.fullDocumentPath();
	result["applicationName"] = GetApplication()->GetName();

	//7. Save it in the cache
	_urlCache[uriString] = result;

	//8. Done
	return result;
}
Ejemplo n.º 3
0
  void Client::request(Method method, URI url, Header_set hfields, std::string data, Response_handler cb, Options options)
  {
    using namespace std;
    tcp_.stack().resolve(
      url.host().to_string(),
      ResolveCallback::make_packed(
      [
        this,
        method,
        url{move(url)},
        hfields{move(hfields)},
        data{move(data)},
        cb{move(cb)},
        opt{move(options)}
      ] (auto ip)
      {
        // Host resolved
        if(ip != 0)
        {
          // setup request with method and headers
          auto req = create_request(method);
          *req << hfields;

          // Set Host & path from url
          populate_from_url(*req, url);

          // Add data and content length
          add_data(*req, data);

          // Default to port 80 if non given
          const uint16_t port = (url.port() != 0xFFFF) ? url.port() : 80;

          send(move(req), {ip, port}, move(cb), move(opt));
        }
        else
        {
          cb({Error::RESOLVE_HOST}, nullptr);
        }
      })
    );
  }
Ejemplo n.º 4
0
  void Client::populate_from_url(Request& req, const URI& url)
  {
    // Set uri path (default "/")
    req.set_uri((!url.path().empty()) ? URI{url.path()} : URI{"/"});

    // Set Host: host(:port)
    const auto port = url.port();
    req.header().set_field(header::Host,
      (port != 0xFFFF and port != 80) ?
      url.host().to_string() + ":" + std::to_string(port)
      : url.host().to_string()); // to_string madness
  }