diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/uri/http_url.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/uri/http_url.h')
-rw-r--r-- | library/cpp/uri/http_url.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/library/cpp/uri/http_url.h b/library/cpp/uri/http_url.h new file mode 100644 index 0000000000..7c8e8d844d --- /dev/null +++ b/library/cpp/uri/http_url.h @@ -0,0 +1,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); +} |