fastdo  0.6.16
http_Url.hpp
浏览该文件的文档.
1 #ifndef __HTTP_URL_HPP__
2 #define __HTTP_URL_HPP__
3 
4 namespace http
5 {
7 enum UrlFlags
8 {
9  urlSimple = 0,
16 };
17 
20 {
21 public:
23  explicit Url( winux::uint flags = urlDefault ) : _flags(flags), _isRelative(false)
24  {
25  }
26 
28  Url( winux::String const & url, winux::uint flags = urlDefault ) : _flags(flags), _isRelative(false)
29  {
30  this->parse(url);
31  }
32 
34  virtual ~Url()
35  {
36  }
37 
38  // attributes -------------------------------------------------------------------------
39 
41  winux::uint getFlags() const { return _flags; }
42 
46  bool isRelative() const { return _isRelative; }
47 
51  winux::String const & getScheme() const { return _scheme; }
52 
54  winux::String const & getUser() const { return _user; }
55 
57  winux::String const & getPwd() const { return _pwd; }
58 
60  winux::String const & getHost() const { return _host; }
61 
63  winux::String const & getPort() const { return _port; }
64 
68  winux::String const & getRawPathStr() const { return _rawPathStr; }
69 
74  size_t getPathCompsCount() const { return _pathComps.getCount(); }
75 
79  winux::String getPath() const;
80 
82  winux::Mixed const & getPathMatrixParams( int iPathComp ) const;
83 
85  winux::Mixed const & getPathMatrixParam( int iPathComp, winux::String const & name ) const;
86 
88  winux::String const & getRawQueryStr() const { return _rawQueryStr; }
89 
91  winux::Mixed const & getQueryParams() const { return _query; }
92 
94  winux::Mixed const & getQueryParam( winux::String const & name ) const { return _query[name]; }
95 
97  winux::String const & getFragment() const { return _fragment; }
98 
99  // methods ----------------------------------------------------------------------------
100 
102  Url & clear()
103  {
104  // scheme segment
105  _scheme.clear();
106  // host segment
107  _user.clear();
108  _pwd.clear();
109  _host.clear();
110  _port.clear();
111  // path segment
112  _rawPathStr.clear(); // 首不含'/'
113  //[ { pathname:{ a:1, b:2 } }, { pathname1:{ a:1, b:2 } }, ... ]
114  _pathComps.free();
115  // query segment
116  _rawQueryStr.clear(); // 首不含'?'
117  _query.free();
118  // fragment segment
119  _fragment.clear(); // 首不含'#'
120  return *this;
121  }
122 
124  winux::String toString() const;
125 
127  bool assembleSchemeSegment( winux::String * urlSegment ) const;
128 
130  bool assembleHostSegment( winux::String * urlSegment, bool hasSchemeSegment ) const;
131 
133  bool assemblePathSegment( winux::String * urlSegment, bool hasHostSegment, bool hasQuerySegment, bool hasFragmentSegment ) const;
134 
136  bool assembleQuerySegment( winux::String * urlSegment, bool incStartChar ) const;
137 
139  bool assembleFragmentSegment( winux::String * urlSegment, bool incStartChar ) const;
140 
142  winux::Mixed dump() const;
143 
145  Url & parse( winux::String const & url, bool hasSchemeSegment = true, bool hasHostSegment = true, bool hasPathSegment = true, bool hasQuerySegment = true, bool hasFragmentSegment = true );
146 
148  Url & setFlags( winux::uint flags ) { _flags = flags; return *this; }
149 
153  Url & setRelative( bool relative ) { _isRelative = relative; return *this; }
154 
156  Url & setScheme( winux::String const & scheme ) { _scheme = scheme; return *this; }
157 
159  Url & setUser( winux::String const & user ) { _user = user; return *this; }
160 
162  Url & setPwd( winux::String const & pwd ) { _pwd = pwd; return *this; }
163 
165  Url & setHost( winux::String const & host ) { _host = host; return *this; }
166 
168  Url & setPort( winux::String const & port ) { _port = port; return *this; }
169 
171  Url & setRawPathStr( winux::String const & rawPathStr );
172 
176  Url & setPathComps( winux::Mixed const & pathComps );
177 
179  Url & setRawQueryStr( winux::String const & rawQueryStr );
180 
182  Url & setQuery( winux::Mixed const & query );
183 
185  Url & setFragment( winux::String const & fragment ) { _fragment = fragment; return *this; }
186 
187 private:
188  winux::uint _flags;
189  bool _isRelative;
190  // scheme segment
191  winux::String _scheme;
192  // host segment
193  winux::String _user;
194  winux::String _pwd;
195  winux::String _host;
196  winux::String _port;
197  // path segment
198  winux::String _rawPathStr; // 首不含'/'
199  //[ { pathname:{ a:1, b:2 } }, { pathname1:{ a:1, b:2 } }, ... ]
200  winux::Mixed _pathComps;
201  // query segment
202  winux::String _rawQueryStr; // 首不含'?'
203  winux::Mixed _query;
204  // fragment segment
205  winux::String _fragment; // 首不含'#'
206 
207  friend class UrlParser;
208 };
209 
210 
211 } // namespace http
212 
213 #endif // __HTTP_URL_HPP__
#define HTTPWRAPPER_DLL
Definition: http_base.hpp:24
Url & setUser(winux::String const &user)
设置URL主机段的用户名(可选)
Definition: http_Url.hpp:159
Url & setRelative(bool relative)
设置URL是否为相对
Definition: http_Url.hpp:153
Url & setScheme(winux::String const &scheme)
设置URL方案
Definition: http_Url.hpp:156
bool isRelative() const
是否为相对URL
Definition: http_Url.hpp:46
Url & setPort(winux::String const &port)
设置URL主机段的端口号(可选)
Definition: http_Url.hpp:168
解析路径部分的MatrixURIs参数。当指定此flag时 urlPathComp 强制启用
Definition: http_Url.hpp:12
XString< tchar > String
Definition: utilities.hpp:261
winux::uint getFlags() const
获取URL解析和使用标志
Definition: http_Url.hpp:41
Url & setFragment(winux::String const &fragment)
设置URL Fragment段
Definition: http_Url.hpp:185
HTTP协议的相关简单类封装
Definition: http_base.hpp:32
UrlFlags
URL旗标
Definition: http_Url.hpp:7
winux::String const & getRawQueryStr() const
获取未解析的查询段字符串。不以&#39;?&#39;开头
Definition: http_Url.hpp:88
URL类
Definition: http_Url.hpp:19
Url & clear()
清空
Definition: http_Url.hpp:102
winux::Mixed const & getQueryParam(winux::String const &name) const
获取指定的查询参数
Definition: http_Url.hpp:94
全部 urlPathComp | urlPathMatrixParams | urlQueryVars | urlCanRelative
Definition: http_Url.hpp:15
解析查询部分的变量
Definition: http_Url.hpp:10
Url & setPwd(winux::String const &pwd)
设置URL主机段的密码(可选)
Definition: http_Url.hpp:162
将路径部分解析成PathComp数组
Definition: http_Url.hpp:11
winux::String const & getScheme() const
获取URL方案
Definition: http_Url.hpp:51
size_t getPathCompsCount() const
获取路径部件数
Definition: http_Url.hpp:74
winux::String const & getRawPathStr() const
获取未解析的路径段字符串。不以&#39;/&#39;开头
Definition: http_Url.hpp:68
Url(winux::uint flags=urlDefault)
构造函数1
Definition: http_Url.hpp:23
简单的分段
Definition: http_Url.hpp:9
unsigned int uint
Definition: utilities.hpp:215
winux::String const & getPort() const
获取端口号。如果不指定则为scheme默认决定的端口
Definition: http_Url.hpp:63
winux::String const & getHost() const
获取主机名(域名)
Definition: http_Url.hpp:60
URL解析器
winux::String const & getPwd() const
获取密码
Definition: http_Url.hpp:57
winux::String const & getUser() const
获取用户名
Definition: http_Url.hpp:54
Url & setHost(winux::String const &host)
设置URL主机段的主机名
Definition: http_Url.hpp:165
混合体,能表示多种类型的值
Definition: utilities.hpp:1440
Url & setFlags(winux::uint flags)
设置URL解析和使用标志
Definition: http_Url.hpp:148
可以是相对URL。 eg. &#39;www.abc.com/aa/bb/cc&#39;这种URL的&#39;www.abc.com&#39;不会解析成host部分,而是path部分 ...
Definition: http_Url.hpp:13
winux::String const & getFragment() const
获取文章分段名
Definition: http_Url.hpp:97
Url(winux::String const &url, winux::uint flags=urlDefault)
构造函数2
Definition: http_Url.hpp:28
默认 urlQueryVars | urlCanRelative
Definition: http_Url.hpp:14
virtual ~Url()
析构函数
Definition: http_Url.hpp:34
winux::Mixed const & getQueryParams() const
获取查询参数集合的常引用
Definition: http_Url.hpp:91