location.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. #include "location.h"
  2. #include "uri.h"
  3. namespace NUri {
  4. static const ui64 URI_PARSE_FLAGS =
  5. (TFeature::FeaturesRecommended | TFeature::FeatureConvertHostIDN | TFeature::FeatureEncodeExtendedDelim | TFeature::FeatureEncodePercent) & ~TFeature::FeatureHashBangToEscapedFragment;
  6. TString ResolveRedirectLocation(const TStringBuf& baseUrl,
  7. const TStringBuf& location) {
  8. TUri baseUri;
  9. TUri locationUri;
  10. // Parse base URL.
  11. if (baseUri.Parse(baseUrl, URI_PARSE_FLAGS) != NUri::TState::ParsedOK) {
  12. return "";
  13. }
  14. // Parse location with respect to the base URL.
  15. if (locationUri.Parse(location, baseUri, URI_PARSE_FLAGS) != NUri::TState::ParsedOK) {
  16. return "";
  17. }
  18. // Inherit fragment.
  19. if (!locationUri.GetField(NUri::TField::FieldFragment)) {
  20. NUri::TUriUpdate update(locationUri);
  21. update.Set(NUri::TField::FieldFragment, baseUri.GetField(NUri::TField::FieldFragment));
  22. }
  23. TString res;
  24. locationUri.Print(res, NUri::TField::FlagAllFields);
  25. return res;
  26. }
  27. }