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