Пример #1
0
BUrl::BUrl(const BUrl& base, const BString& location)
	:
	fUrlString(),
	fProtocol(),
	fUser(),
	fPassword(),
	fHost(),
	fPort(0),
	fPath(),
	fRequest(),
	fAuthorityValid(false),
	fUserInfoValid(false),
	fHasUserName(false),
	fHasPassword(false),
	fHasHost(false),
	fHasPort(false),
	fHasFragment(false)
{
	// This implements the algorithm in RFC3986, Section 5.2.

	BUrl relative(location);
	if (relative.HasProtocol()) {
		SetProtocol(relative.Protocol());
		if (relative.HasAuthority())
			SetAuthority(relative.Authority());
		SetPath(relative.Path());
		SetRequest(relative.Request());
	} else {
		if (relative.HasAuthority()) {
			SetAuthority(relative.Authority());
			SetPath(relative.Path());
			SetRequest(relative.Request());
		} else {
			if (relative.Path().IsEmpty()) {
				_SetPathUnsafe(base.Path());
				if (relative.HasRequest())
					SetRequest(relative.Request());
				else
					SetRequest(base.Request());
			} else {
				if (relative.Path()[0] == '/')
					SetPath(relative.Path());
				else {
					BString path = base._MergePath(relative.Path());
					SetPath(path);
				}
				SetRequest(relative.Request());
			}

			if (base.HasAuthority())
				SetAuthority(base.Authority());
		}
		SetProtocol(base.Protocol());
	}

	if (relative.HasFragment())
		SetFragment(relative.Fragment());
}
Пример #2
0
BUrl::BUrl(const BUrl& base, const BString& location)
	:
	fUrlString(),
	fProtocol(),
	fUser(),
	fPassword(),
	fHost(),
	fPort(0),
	fPath(),
	fRequest(),
	fHasAuthority(false)
{
	// This implements the algorithm in RFC3986, Section 5.2.

	BUrl relative(location);
	if (relative.HasProtocol()) {
		SetProtocol(relative.Protocol());
		SetAuthority(relative.Authority());
		SetPath(relative.Path()); // TODO _RemoveDotSegments()
		SetRequest(relative.Request());
	} else {
		if (relative.HasAuthority()) {
			SetAuthority(relative.Authority());
			SetPath(relative.Path()); // TODO _RemoveDotSegments()
			SetRequest(relative.Request());
		} else {
			if (relative.Path().IsEmpty()) {
				SetPath(base.Path());
				if (relative.HasRequest())
					SetRequest(relative.Request());
				else
					SetRequest(Request());
			} else {
				if (relative.Path()[0] == '/')
					SetPath(relative.Path());
				else {
					BString path = base.Path();
					// Remove last part of path (the file, if any) so we get the
					// "current directory"
					path.Truncate(path.FindLast('/') + 1);
					path += relative.Path();
					// TODO _RemoveDotSegments()
					SetPath(path);
				}
				SetRequest(relative.Request());
			}
			SetAuthority(base.Authority());
		}
		SetProtocol(base.Protocol());
	}

	SetFragment(relative.Fragment());
}