aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/uri/http_url.h
blob: 92a332a1f66dc8f8e7fae03035c8269f9d28867e (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once

#include "uri.h"
#include "other.h"
 
// XXX: use NUri::TUri directly; this whole file is for backwards compatibility

class THttpURL
   : public NUri::TUri { 
public:
    typedef TField::EFlags TFlags;
    typedef TField::EField TField;
    typedef TScheme::EKind TSchemeKind;
    typedef TState::EParsed TParsedState;

public:
    enum {
        FeatureUnescapeStandard = TFeature::FeatureDecodeStandard,
        FeatureEscSpace = TFeature::FeatureEncodeSpaceAsPlus, 
        FeatureEscapeUnescaped = TFeature::FeatureEncodeExtendedASCII, 
        FeatureNormalPath = TFeature::FeaturePathStripRootParent, 
    };

public:
    THttpURL(unsigned defaultPort = 80)
        : TUri(defaultPort)
    { 
    } 

    THttpURL(const TStringBuf& host, ui16 port, const TStringBuf& path, const TStringBuf& query = TStringBuf(), const TStringBuf& scheme = "http", unsigned defaultPort = 0) 
        : TUri(host, port, path, query, scheme, defaultPort)
    { 
    } 

    THttpURL(const TUri& url)
        : TUri(url)
    { 
    } 

public: // XXX: don't use any of these legacy methods below
public: // use TUri::GetField() instead
    /// will return null-terminated if fld is not dirty
    const char* Get(EField fld) const { 
        return GetField(fld).data();
    }

public: // use TUriUpdate class so that Rewrite() is only called once
    void Set(EField field, const TStringBuf& value) { 
        if (SetInMemory(field, value))
            Rewrite();
    }

    template <size_t size>
    void Set(EField field, const char (&value)[size]) { 
        if (SetInMemory(field, value))
            Rewrite();
    }

public: // use TUri::FldXXX methods for better control
    // Partial quick set of the field, can be called for
    // multiple fields
    bool SetInMemory(EField field, const TStringBuf& value) { 
        return FldMemSet(field, value);
    }

    // clears a field
    void Reset(EField field) { 
        FldClr(field);
    }
};

static inline const char* HttpURLParsedStateToString(const NUri::TState::EParsed& t) { 
    return NUri::ParsedStateToString(t);
}
static inline const char* HttpUrlSchemeKindToString(const NUri::TScheme::EKind& t) { 
    return NUri::SchemeKindToString(t);
}