atscppapi  1.0.9
C++ wrapper for Apache Traffic Server API
 All Classes Files Functions Enumerations Enumerator Macros
Url.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 LinkedIn Corp. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4  * except in compliance with the License. You may obtain a copy of the license at
5  * http://www.apache.org/licenses/LICENSE-2.0
6  *
7  * Unless required by applicable law or agreed to in writing, software distributed under the
8  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
9  * either express or implied.
10  *
11  */
12 
13 /**
14  * @file Url.h
15  * @author Brian Geffon
16  * @author Manjesh Nilange
17  */
18 
19 #pragma once
20 #ifndef ATSCPPAPI_URL_H_
21 #define ATSCPPAPI_URL_H_
22 
23 #include <string>
24 #include <stdint.h>
25 #include <atscppapi/noncopyable.h>
26 
27 namespace atscppapi {
28 
29 class UrlState;
30 
31 /**
32  * @brief This class contains all properties of a Url.
33  *
34  * You can use a Url object to get and set any property of a url.
35  *
36  * @warning Url objects should never be constructed by the user.
37  * If a user needs to create an unbound Url then they should create a Request
38  * object using Request::Request(string) which will construct a Url object for them
39  * and it can be retrieved via Request::getUrl(). A full example of this
40  * is available in examples/detachedrequest/.
41  */
42 class Url: noncopyable {
43 public:
44  /**
45  * @warning Url objects should never be constructed by the user.
46  * If a user needs to create an unbound Url then they should create a Request
47  * object using Request::Request(string) which will construct a Url object for them
48  * and it can be retrieved via Request::getUrl(). A full example of this
49  * is available in examples/detachedrequest/.
50  *
51  * @private
52  */
53  Url();
54 
55  /**
56  * @warning Url objects should never be constructed by the user.
57  * If a user needs to create an unbound Url then they should create a Request
58  * object using Request::Request(string) which will construct a Url object for them
59  * and it can be retrieved via Request::getUrl(). A full example of this
60  * is available in examples/detachedrequest/.
61  *
62  * @private
63  */
64  Url(void *hdr_buf, void *url_loc);
65  ~Url();
66 
67  /**
68  * @return The full url as a string, such a url might be http://www.linkedin.com/profile/view?id=2941
69  */
70  const std::string &getUrlString() const;
71 
72  /**
73  * @return The path only portion of the url, such as /profile/view
74  */
75  const std::string &getPath() const;
76 
77  /**
78  * @return The query only portion of the url, which might be id=1234
79  */
80  const std::string &getQuery() const;
81 
82  /**
83  * @return The scheme of the url, this will be either http or https.
84  */
85  const std::string &getScheme() const;
86 
87  /**
88  * @return The host only of the url, this might be www.linkedin.com
89  */
90  const std::string &getHost() const;
91 
92  /**
93  * @return The port only portion of the url, this will likely be 80 or 443.
94  */
95  uint16_t getPort() const;
96 
97  /**
98  * Set the path of the url.
99  * @param path the path portion of the url to set, this might be something like /foo/bar
100  */
101  void setPath(const std::string &);
102 
103  /**
104  * Set the query param of the url.
105  * @param query the query portion of the url, this might be something like foo=bar&blah=baz.
106  */
107  void setQuery(const std::string &);
108 
109  /**
110  * Set the scheme of the url
111  * @param scheme this might be either http or https.
112  */
113  void setScheme(const std::string &);
114 
115  /**
116  * Set the host of the url
117  * @param host this might be something such as www.linkedin.com or www.apache.org
118  */
119  void setHost(const std::string &);
120 
121  /**
122  * Set the port portion of the url.
123  * @param port this is a uint16_t which represents the port (in host order, there is no need to conver to network order). You
124  * might use a value such as 80 or 8080.
125  */
126  void setPort(const uint16_t);
127 
128  /**
129  * This method allows you to reset the url, this will force the Url to fully re-read all cached values.
130  * If this method is used on a Detached Requests' Url object it will completely destroy the values.
131  *
132  * \note This method should rarely be used.
133  */
134  void reset();
135 private:
136  bool isInitialized() const;
137  void init(void *hdr_buf, void *url_loc);
138  UrlState *state_;
139  friend class Request;
140  friend class ClientRequest;
141  friend class RemapPlugin;
142 };
143 
144 }
145 
146 #endif /* ATSCPPAPI_URL_H_ */