http_url.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include "uri.h"
  3. #include "other.h"
  4. // XXX: use NUri::TUri directly; this whole file is for backwards compatibility
  5. class THttpURL
  6. : public NUri::TUri {
  7. public:
  8. typedef TField::EFlags TFlags;
  9. typedef TField::EField TField;
  10. typedef TScheme::EKind TSchemeKind;
  11. typedef TState::EParsed TParsedState;
  12. public:
  13. enum {
  14. FeatureUnescapeStandard = TFeature::FeatureDecodeStandard,
  15. FeatureEscSpace = TFeature::FeatureEncodeSpaceAsPlus,
  16. FeatureEscapeUnescaped = TFeature::FeatureEncodeExtendedASCII,
  17. FeatureNormalPath = TFeature::FeaturePathStripRootParent,
  18. };
  19. public:
  20. THttpURL(unsigned defaultPort = 80)
  21. : TUri(defaultPort)
  22. {
  23. }
  24. THttpURL(const TStringBuf& host, ui16 port, const TStringBuf& path, const TStringBuf& query = TStringBuf(), const TStringBuf& scheme = "http", unsigned defaultPort = 0, const TStringBuf& hashbang = TStringBuf())
  25. : TUri(host, port, path, query, scheme, defaultPort, hashbang)
  26. {
  27. }
  28. THttpURL(const TUri& url)
  29. : TUri(url)
  30. {
  31. }
  32. public: // XXX: don't use any of these legacy methods below
  33. public: // use TUri::GetField() instead
  34. /// will return null-terminated if fld is not dirty
  35. const char* Get(EField fld) const {
  36. return GetField(fld).data();
  37. }
  38. public: // use TUriUpdate class so that Rewrite() is only called once
  39. void Set(EField field, const TStringBuf& value) {
  40. if (SetInMemory(field, value))
  41. Rewrite();
  42. }
  43. template <size_t size>
  44. void Set(EField field, const char (&value)[size]) {
  45. if (SetInMemory(field, value))
  46. Rewrite();
  47. }
  48. public: // use TUri::FldXXX methods for better control
  49. // Partial quick set of the field, can be called for
  50. // multiple fields
  51. bool SetInMemory(EField field, const TStringBuf& value) {
  52. return FldMemSet(field, value);
  53. }
  54. // clears a field
  55. void Reset(EField field) {
  56. FldClr(field);
  57. }
  58. };
  59. static inline const char* HttpURLParsedStateToString(const NUri::TState::EParsed& t) {
  60. return NUri::ParsedStateToString(t);
  61. }
  62. static inline const char* HttpUrlSchemeKindToString(const NUri::TScheme::EKind& t) {
  63. return NUri::SchemeKindToString(t);
  64. }