Merge lp:~stolowski/unity-scopes-api/user-agent into lp:unity-scopes-api/devel
- user-agent
- Merge into devel
Status: | Merged |
---|---|
Approved by: | Michi Henning |
Approved revision: | 261 |
Merged at revision: | 495 |
Proposed branch: | lp:~stolowski/unity-scopes-api/user-agent |
Merge into: | lp:unity-scopes-api/devel |
Prerequisite: | lp:~michihenning/unity-scopes-api/fix-amd64-symbol |
Diff against target: |
383 lines (+113/-17) 11 files modified
STRUCTS (+19/-0) include/unity/scopes/internal/smartscopes/HttpClientInterface.h (+6/-1) include/unity/scopes/internal/smartscopes/HttpClientQt.h (+4/-2) include/unity/scopes/internal/smartscopes/HttpClientQtThread.h (+4/-1) include/unity/scopes/internal/smartscopes/SmartScopesClient.h (+3/-1) src/scopes/internal/smartscopes/HttpClientQt.cpp (+7/-5) src/scopes/internal/smartscopes/HttpClientQtThread.cpp (+6/-1) src/scopes/internal/smartscopes/SmartScope.cpp (+16/-3) src/scopes/internal/smartscopes/SmartScopesClient.cpp (+18/-2) test/gtest/scopes/internal/smartscopes/SmartScopesClient/FakeSss.py (+3/-0) test/gtest/scopes/internal/smartscopes/SmartScopesClient/SmartScopesClient_test.cpp (+27/-1) |
To merge this branch: | bzr merge lp:~stolowski/unity-scopes-api/user-agent |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Michi Henning (community) | Approve | ||
Pete Woods | Pending | ||
Review via email: mp+235913@code.launchpad.net |
This proposal supersedes a proposal from 2014-09-24.
Commit message
Pass User-Agent http header to SSS if recieved with SearchMetadata or PreviewMetadata.
Description of the change
Pass User-Agent http header to SSS if recieved with SearchMetadata or PreviewMetadata.
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal | # |
Pete Woods (pete-woods) wrote : Posted in a previous version of this proposal | # |
LGTM
Pete Woods (pete-woods) wrote : Posted in a previous version of this proposal | # |
Apart from the symbols file stuff. This could be another example of the compiler producing amd64-only symbols.
i.e. (c++|arch=amd64) should be used as the symbol tag
Michi Henning (michihenning) wrote : Posted in a previous version of this proposal | # |
BIG problem here: there is a redundant semicolon ;-)
247 - }
248 + };
I think the user-agent attribute should be documented in the STRUCTS file?
Other than that, this looks good!
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:259
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Paweł Stołowski (stolowski) wrote : Posted in a previous version of this proposal | # |
> BIG problem here: there is a redundant semicolon ;-)
>
> 247 - }
> 248 + };
>
> I think the user-agent attribute should be documented in the STRUCTS file?
>
Right, I noticed we were missing descriptions of the 3 *metadata structures that. I fixed that, however this particular value as well as e.g. session-id are transported using general hints container, and we don't really care what's there in the API, so these are not documented.
Paweł Stołowski (stolowski) wrote : Posted in a previous version of this proposal | # |
I've merged Michi's symbols fix into this branch and am trying to resubmit it with new prerequisite branch, but LP gives me OOPses all the time. Setting to WIP till it succeeds.
Paweł Stołowski (stolowski) wrote : | # |
Ok, it finally worked, it;s ready for review again.
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal | # |
PASSED: Continuous integration, rev:260
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:261
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Michi Henning (michihenning) wrote : | # |
Looking good, thanks!
PS Jenkins bot (ps-jenkins) : | # |
Preview Diff
1 | === modified file 'STRUCTS' | |||
2 | --- STRUCTS 2014-06-26 05:59:38 +0000 | |||
3 | +++ STRUCTS 2014-09-25 08:50:05 +0000 | |||
4 | @@ -154,3 +154,22 @@ | |||
5 | 154 | ============================================ | 154 | ============================================ |
6 | 155 | 'status' : int (corresponds to ActivationResponse::Status enum) | 155 | 'status' : int (corresponds to ActivationResponse::Status enum) |
7 | 156 | 'scope_data' : variant | 156 | 'scope_data' : variant |
8 | 157 | |||
9 | 158 | QueryMetadata (returned by serialize()) | ||
10 | 159 | ======================================= | ||
11 | 160 | 'type' : string (metadata type) | ||
12 | 161 | 'locale' : string | ||
13 | 162 | 'form_factor' : string | ||
14 | 163 | 'hints' : dict | ||
15 | 164 | 'internet_connectivity' : bool (optional) | ||
16 | 165 | |||
17 | 166 | SearchMetadata (returned by serialize()) | ||
18 | 167 | ======================================== | ||
19 | 168 | all QueryMetadata attributes | ||
20 | 169 | 'cardinality' : int | ||
21 | 170 | 'location' : dict | ||
22 | 171 | |||
23 | 172 | ActionMetadata (returned by serialize()) | ||
24 | 173 | ======================================== | ||
25 | 174 | all QueryMetadata attributes | ||
26 | 175 | 'scope_data' : variant | ||
27 | 157 | 176 | ||
28 | === modified file 'include/unity/scopes/internal/smartscopes/HttpClientInterface.h' | |||
29 | --- include/unity/scopes/internal/smartscopes/HttpClientInterface.h 2014-08-28 15:27:19 +0000 | |||
30 | +++ include/unity/scopes/internal/smartscopes/HttpClientInterface.h 2014-09-25 08:50:05 +0000 | |||
31 | @@ -25,6 +25,8 @@ | |||
32 | 25 | #include <future> | 25 | #include <future> |
33 | 26 | #include <string> | 26 | #include <string> |
34 | 27 | #include <functional> | 27 | #include <functional> |
35 | 28 | #include <list> | ||
36 | 29 | #include <tuple> | ||
37 | 28 | 30 | ||
38 | 29 | namespace unity | 31 | namespace unity |
39 | 30 | { | 32 | { |
40 | @@ -40,6 +42,8 @@ | |||
41 | 40 | 42 | ||
42 | 41 | class HttpResponseHandle; | 43 | class HttpResponseHandle; |
43 | 42 | 44 | ||
44 | 45 | typedef std::list<std::pair<std::string, std::string>> HttpHeaders; | ||
45 | 46 | |||
46 | 43 | class HttpClientInterface : public std::enable_shared_from_this<HttpClientInterface> | 47 | class HttpClientInterface : public std::enable_shared_from_this<HttpClientInterface> |
47 | 44 | { | 48 | { |
48 | 45 | public: | 49 | public: |
49 | @@ -50,7 +54,8 @@ | |||
50 | 50 | virtual ~HttpClientInterface() = default; | 54 | virtual ~HttpClientInterface() = default; |
51 | 51 | 55 | ||
52 | 52 | virtual std::shared_ptr<HttpResponseHandle> get(std::string const& request_url, | 56 | virtual std::shared_ptr<HttpResponseHandle> get(std::string const& request_url, |
54 | 53 | std::function<void(std::string const&)> const& lineData = [](std::string const&) {}) = 0; | 57 | std::function<void(std::string const&)> const& lineData = [](std::string const&) {}, |
55 | 58 | HttpHeaders const& headers = HttpHeaders()) = 0; | ||
56 | 54 | 59 | ||
57 | 55 | virtual std::string to_percent_encoding(std::string const& string) = 0; | 60 | virtual std::string to_percent_encoding(std::string const& string) = 0; |
58 | 56 | 61 | ||
59 | 57 | 62 | ||
60 | === modified file 'include/unity/scopes/internal/smartscopes/HttpClientQt.h' | |||
61 | --- include/unity/scopes/internal/smartscopes/HttpClientQt.h 2014-09-02 11:58:04 +0000 | |||
62 | +++ include/unity/scopes/internal/smartscopes/HttpClientQt.h 2014-09-25 08:50:05 +0000 | |||
63 | @@ -44,7 +44,8 @@ | |||
64 | 44 | explicit HttpClientQt(unsigned int no_reply_timeout); | 44 | explicit HttpClientQt(unsigned int no_reply_timeout); |
65 | 45 | ~HttpClientQt(); | 45 | ~HttpClientQt(); |
66 | 46 | 46 | ||
68 | 47 | HttpResponseHandle::SPtr get(std::string const& request_url, std::function<void(std::string const&)> const& lineData = [](std::string const&) {}) override; | 47 | HttpResponseHandle::SPtr get(std::string const& request_url, std::function<void(std::string const&)> const& lineData = [](std::string const&) {}, |
69 | 48 | HttpHeaders const& headers = HttpHeaders()) override; | ||
70 | 48 | 49 | ||
71 | 49 | std::string to_percent_encoding(std::string const& string) override; | 50 | std::string to_percent_encoding(std::string const& string) override; |
72 | 50 | 51 | ||
73 | @@ -55,7 +56,8 @@ | |||
74 | 55 | class HttpSession | 56 | class HttpSession |
75 | 56 | { | 57 | { |
76 | 57 | public: | 58 | public: |
78 | 58 | HttpSession(std::string const& request_url, unsigned int timeout, std::function<void(std::string const&)> const& lineData); | 59 | HttpSession(std::string const& request_url, unsigned int timeout, std::function<void(std::string const&)> const& lineData, HttpHeaders const& headers = |
79 | 60 | HttpHeaders()); | ||
80 | 59 | ~HttpSession(); | 61 | ~HttpSession(); |
81 | 60 | 62 | ||
82 | 61 | std::future<void> get_future(); | 63 | std::future<void> get_future(); |
83 | 62 | 64 | ||
84 | === modified file 'include/unity/scopes/internal/smartscopes/HttpClientQtThread.h' | |||
85 | --- include/unity/scopes/internal/smartscopes/HttpClientQtThread.h 2014-08-26 12:17:18 +0000 | |||
86 | +++ include/unity/scopes/internal/smartscopes/HttpClientQtThread.h 2014-09-25 08:50:05 +0000 | |||
87 | @@ -36,6 +36,7 @@ | |||
88 | 36 | #include <QUrl> | 36 | #include <QUrl> |
89 | 37 | #endif | 37 | #endif |
90 | 38 | 38 | ||
91 | 39 | #include <unity/scopes/internal/smartscopes/HttpClientInterface.h> | ||
92 | 39 | #include <unity/util/NonCopyable.h> | 40 | #include <unity/util/NonCopyable.h> |
93 | 40 | 41 | ||
94 | 41 | #include <mutex> | 42 | #include <mutex> |
95 | @@ -62,7 +63,8 @@ | |||
96 | 62 | public: | 63 | public: |
97 | 63 | NONCOPYABLE(HttpClientQtThread); | 64 | NONCOPYABLE(HttpClientQtThread); |
98 | 64 | 65 | ||
100 | 65 | HttpClientQtThread(const QUrl& url, unsigned int timeout, std::function<void(std::string const&)> const& lineData); | 66 | HttpClientQtThread(const QUrl& url, unsigned int timeout, std::function<void(std::string const&)> const& lineData, const HttpHeaders& headers = |
101 | 67 | HttpHeaders()); | ||
102 | 66 | ~HttpClientQtThread(); | 68 | ~HttpClientQtThread(); |
103 | 67 | 69 | ||
104 | 68 | bool get_reply(std::string& reply); | 70 | bool get_reply(std::string& reply); |
105 | @@ -82,6 +84,7 @@ | |||
106 | 82 | private: | 84 | private: |
107 | 83 | QUrl url_; | 85 | QUrl url_; |
108 | 84 | const std::function<void(std::string const&)> lineDataCallback_; | 86 | const std::function<void(std::string const&)> lineDataCallback_; |
109 | 87 | HttpHeaders headers_; | ||
110 | 85 | unsigned int timeout_; | 88 | unsigned int timeout_; |
111 | 86 | std::mutex reply_mutex_; | 89 | std::mutex reply_mutex_; |
112 | 87 | 90 | ||
113 | 88 | 91 | ||
114 | === modified file 'include/unity/scopes/internal/smartscopes/SmartScopesClient.h' | |||
115 | --- include/unity/scopes/internal/smartscopes/SmartScopesClient.h 2014-09-03 14:34:14 +0000 | |||
116 | +++ include/unity/scopes/internal/smartscopes/SmartScopesClient.h 2014-09-25 08:50:05 +0000 | |||
117 | @@ -174,6 +174,7 @@ | |||
118 | 174 | VariantMap const& filter_state = VariantMap(), | 174 | VariantMap const& filter_state = VariantMap(), |
119 | 175 | std::string const& locale = "", | 175 | std::string const& locale = "", |
120 | 176 | std::string const& country = "", | 176 | std::string const& country = "", |
121 | 177 | std::string const& user_agent_hdr = "", | ||
122 | 177 | const unsigned int limit = 0); | 178 | const unsigned int limit = 0); |
123 | 178 | 179 | ||
124 | 179 | PreviewHandle::UPtr preview(PreviewReplyHandler const& handler, | 180 | PreviewHandle::UPtr preview(PreviewReplyHandler const& handler, |
125 | @@ -184,7 +185,8 @@ | |||
126 | 184 | const unsigned int widgets_api_version, | 185 | const unsigned int widgets_api_version, |
127 | 185 | VariantMap const& settings = VariantMap(), | 186 | VariantMap const& settings = VariantMap(), |
128 | 186 | std::string const& locale = "", | 187 | std::string const& locale = "", |
130 | 187 | std::string const& country = ""); | 188 | std::string const& country = "", |
131 | 189 | std::string const& user_agent_hdr = ""); | ||
132 | 188 | 190 | ||
133 | 189 | private: | 191 | private: |
134 | 190 | friend class SearchHandle; | 192 | friend class SearchHandle; |
135 | 191 | 193 | ||
136 | === modified file 'src/scopes/internal/smartscopes/HttpClientQt.cpp' | |||
137 | --- src/scopes/internal/smartscopes/HttpClientQt.cpp 2014-09-02 11:58:04 +0000 | |||
138 | +++ src/scopes/internal/smartscopes/HttpClientQt.cpp 2014-09-25 08:50:05 +0000 | |||
139 | @@ -48,12 +48,13 @@ | |||
140 | 48 | { | 48 | { |
141 | 49 | } | 49 | } |
142 | 50 | 50 | ||
144 | 51 | HttpResponseHandle::SPtr HttpClientQt::get(std::string const& request_url, std::function<void(std::string const&)> const& lineData) | 51 | HttpResponseHandle::SPtr HttpClientQt::get(std::string const& request_url, std::function<void(std::string const&)> const& lineData, |
145 | 52 | HttpHeaders const& headers) | ||
146 | 52 | { | 53 | { |
147 | 53 | std::lock_guard<std::mutex> lock(sessions_mutex_); | 54 | std::lock_guard<std::mutex> lock(sessions_mutex_); |
148 | 54 | 55 | ||
149 | 55 | // start new session | 56 | // start new session |
151 | 56 | auto session = std::make_shared<HttpSession>(request_url, no_reply_timeout_, lineData); | 57 | auto session = std::make_shared<HttpSession>(request_url, no_reply_timeout_, lineData, headers); |
152 | 57 | sessions_[session_index_] = session; | 58 | sessions_[session_index_] = session; |
153 | 58 | 59 | ||
154 | 59 | return std::make_shared<HttpResponseHandle>(shared_from_this(), session_index_++, session->get_future()); | 60 | return std::make_shared<HttpResponseHandle>(shared_from_this(), session_index_++, session->get_future()); |
155 | @@ -79,17 +80,18 @@ | |||
156 | 79 | 80 | ||
157 | 80 | //-- HttpClientQt::HttpSession | 81 | //-- HttpClientQt::HttpSession |
158 | 81 | 82 | ||
160 | 82 | HttpClientQt::HttpSession::HttpSession(std::string const& request_url, uint timeout, std::function<void(std::string const&)> const& lineData) | 83 | HttpClientQt::HttpSession::HttpSession(std::string const& request_url, uint timeout, std::function<void(std::string const&)> const& lineData, |
161 | 84 | HttpHeaders const& headers) | ||
162 | 83 | : qt_thread_(nullptr) | 85 | : qt_thread_(nullptr) |
163 | 84 | { | 86 | { |
164 | 85 | get_thread_ = | 87 | get_thread_ = |
166 | 86 | std::thread([this, request_url, timeout, lineData]() | 88 | std::thread([this, request_url, headers, timeout, lineData]() |
167 | 87 | { | 89 | { |
168 | 88 | QUrl url(request_url.c_str()); | 90 | QUrl url(request_url.c_str()); |
169 | 89 | 91 | ||
170 | 90 | { | 92 | { |
171 | 91 | std::lock_guard<std::mutex> lock(qt_thread_mutex_); | 93 | std::lock_guard<std::mutex> lock(qt_thread_mutex_); |
173 | 92 | qt_thread_ = std::unique_ptr<HttpClientQtThread>(new HttpClientQtThread(url, timeout, lineData)); | 94 | qt_thread_ = std::unique_ptr<HttpClientQtThread>(new HttpClientQtThread(url, timeout, lineData, headers)); |
174 | 93 | } | 95 | } |
175 | 94 | 96 | ||
176 | 95 | QEventLoop loop; | 97 | QEventLoop loop; |
177 | 96 | 98 | ||
178 | === modified file 'src/scopes/internal/smartscopes/HttpClientQtThread.cpp' | |||
179 | --- src/scopes/internal/smartscopes/HttpClientQtThread.cpp 2014-08-28 15:51:48 +0000 | |||
180 | +++ src/scopes/internal/smartscopes/HttpClientQtThread.cpp 2014-09-25 08:50:05 +0000 | |||
181 | @@ -38,10 +38,11 @@ | |||
182 | 38 | namespace smartscopes | 38 | namespace smartscopes |
183 | 39 | { | 39 | { |
184 | 40 | 40 | ||
186 | 41 | HttpClientQtThread::HttpClientQtThread(const QUrl& url, uint timeout, std::function<void(std::string const&)> const& lineData) | 41 | HttpClientQtThread::HttpClientQtThread(const QUrl& url, uint timeout, std::function<void(std::string const&)> const& lineData, HttpHeaders const& headers) |
187 | 42 | : QThread() | 42 | : QThread() |
188 | 43 | , url_(url) | 43 | , url_(url) |
189 | 44 | , lineDataCallback_(lineData) | 44 | , lineDataCallback_(lineData) |
190 | 45 | , headers_(headers) | ||
191 | 45 | , timeout_(timeout) | 46 | , timeout_(timeout) |
192 | 46 | , success_(false) | 47 | , success_(false) |
193 | 47 | { | 48 | { |
194 | @@ -67,6 +68,10 @@ | |||
195 | 67 | QNetworkAccessManager* manager = new QNetworkAccessManager(); | 68 | QNetworkAccessManager* manager = new QNetworkAccessManager(); |
196 | 68 | 69 | ||
197 | 69 | QNetworkRequest request(url_); | 70 | QNetworkRequest request(url_); |
198 | 71 | for (auto const& hdr: headers_) | ||
199 | 72 | { | ||
200 | 73 | request.setRawHeader(QString::fromStdString(hdr.first).toUtf8(), QString::fromStdString(hdr.second).toUtf8()); | ||
201 | 74 | } | ||
202 | 70 | 75 | ||
203 | 71 | QNetworkReply* reply = manager->get(request); | 76 | QNetworkReply* reply = manager->get(request); |
204 | 72 | reply->setReadBufferSize(0); // unlimited buffer | 77 | reply->setReadBufferSize(0); // unlimited buffer |
205 | 73 | 78 | ||
206 | === modified file 'src/scopes/internal/smartscopes/SmartScope.cpp' | |||
207 | --- src/scopes/internal/smartscopes/SmartScope.cpp 2014-09-03 14:34:14 +0000 | |||
208 | +++ src/scopes/internal/smartscopes/SmartScope.cpp 2014-09-25 08:50:05 +0000 | |||
209 | @@ -163,6 +163,7 @@ | |||
210 | 163 | ///! TODO: country (+location data) | 163 | ///! TODO: country (+location data) |
211 | 164 | int query_id = 0; | 164 | int query_id = 0; |
212 | 165 | std::string session_id; | 165 | std::string session_id; |
213 | 166 | std::string agent; | ||
214 | 166 | auto const metadata = search_metadata(); | 167 | auto const metadata = search_metadata(); |
215 | 167 | if (metadata.contains_hint("session-id") && metadata["session-id"].which() == Variant::String) | 168 | if (metadata.contains_hint("session-id") && metadata["session-id"].which() == Variant::String) |
216 | 168 | { | 169 | { |
217 | @@ -181,8 +182,13 @@ | |||
218 | 181 | { | 182 | { |
219 | 182 | std::cout << "SmartScope: missing or invalid query id for \"" << scope_id_ << "\": \"" << query_.query_string() << "\"" << std::endl; | 183 | std::cout << "SmartScope: missing or invalid query id for \"" << scope_id_ << "\": \"" << query_.query_string() << "\"" << std::endl; |
220 | 183 | } | 184 | } |
221 | 185 | if (metadata.contains_hint("user-agent") && metadata["user-agent"].which() == Variant::String) | ||
222 | 186 | { | ||
223 | 187 | agent = metadata["user-agent"].get_string(); | ||
224 | 188 | } | ||
225 | 184 | 189 | ||
227 | 185 | search_handle_ = ss_client_->search(handler, base_url_, query_.query_string(), query_.department_id(), session_id, query_id, hints_.form_factor(), settings(), query_.filter_state().serialize(), hints_.locale(), "", hints_.cardinality()); | 190 | search_handle_ = ss_client_->search(handler, base_url_, query_.query_string(), query_.department_id(), session_id, query_id, hints_.form_factor(), |
228 | 191 | settings(), query_.filter_state().serialize(), hints_.locale(), "", agent, hints_.cardinality()); | ||
229 | 186 | search_handle_->wait(); | 192 | search_handle_->wait(); |
230 | 187 | 193 | ||
231 | 188 | std::cout << "SmartScope: query for \"" << scope_id_ << "\": \"" << query_.query_string() << "\" complete" << std::endl; | 194 | std::cout << "SmartScope: query for \"" << scope_id_ << "\": \"" << query_.query_string() << "\" complete" << std::endl; |
232 | @@ -250,8 +256,9 @@ | |||
233 | 250 | } | 256 | } |
234 | 251 | }; | 257 | }; |
235 | 252 | 258 | ||
237 | 253 | ///! TODO: widgets_api_version, country (+location data) | 259 | ///! TODO: country (+location data) |
238 | 254 | std::string session_id; | 260 | std::string session_id; |
239 | 261 | std::string agent; | ||
240 | 255 | auto const metadata = action_metadata(); | 262 | auto const metadata = action_metadata(); |
241 | 256 | if (metadata.contains_hint("session-id") && metadata["session-id"].which() == Variant::String) | 263 | if (metadata.contains_hint("session-id") && metadata["session-id"].which() == Variant::String) |
242 | 257 | { | 264 | { |
243 | @@ -263,7 +270,13 @@ | |||
244 | 263 | std::cout << "SmartScope: missing or invalid session id for \"" << scope_id_ << "\" preview: \"" << result().uri() << "\"" << std::endl; | 270 | std::cout << "SmartScope: missing or invalid session id for \"" << scope_id_ << "\" preview: \"" << result().uri() << "\"" << std::endl; |
245 | 264 | } | 271 | } |
246 | 265 | 272 | ||
248 | 266 | preview_handle_ = ss_client_->preview(handler, base_url_, result_["result_json"].get_string(), session_id, hints_.form_factor(), 0, settings(), hints_.locale(), ""); | 273 | if (metadata.contains_hint("user-agent") && metadata["user-agent"].which() == Variant::String) |
249 | 274 | { | ||
250 | 275 | agent = metadata["user-agent"].get_string(); | ||
251 | 276 | } | ||
252 | 277 | |||
253 | 278 | preview_handle_ = ss_client_->preview(handler, base_url_, result_["result_json"].get_string(), session_id, hints_.form_factor(), 0, settings(), | ||
254 | 279 | hints_.locale(), "", agent); | ||
255 | 267 | 280 | ||
256 | 268 | preview_handle_->wait(); | 281 | preview_handle_->wait(); |
257 | 269 | 282 | ||
258 | 270 | 283 | ||
259 | === modified file 'src/scopes/internal/smartscopes/SmartScopesClient.cpp' | |||
260 | --- src/scopes/internal/smartscopes/SmartScopesClient.cpp 2014-09-03 14:34:14 +0000 | |||
261 | +++ src/scopes/internal/smartscopes/SmartScopesClient.cpp 2014-09-25 08:50:05 +0000 | |||
262 | @@ -335,6 +335,7 @@ | |||
263 | 335 | VariantMap const& filter_state, | 335 | VariantMap const& filter_state, |
264 | 336 | std::string const& locale, | 336 | std::string const& locale, |
265 | 337 | std::string const& country, | 337 | std::string const& country, |
266 | 338 | std::string const& user_agent_hdr, | ||
267 | 338 | uint limit) | 339 | uint limit) |
268 | 339 | { | 340 | { |
269 | 340 | std::ostringstream search_uri; | 341 | std::ostringstream search_uri; |
270 | @@ -381,6 +382,14 @@ | |||
271 | 381 | uint search_id = ++query_counter_; | 382 | uint search_id = ++query_counter_; |
272 | 382 | 383 | ||
273 | 383 | std::cout << "SmartScopesClient.search(): GET " << search_uri.str() << std::endl; | 384 | std::cout << "SmartScopesClient.search(): GET " << search_uri.str() << std::endl; |
274 | 385 | |||
275 | 386 | HttpHeaders headers; | ||
276 | 387 | if (!user_agent_hdr.empty()) | ||
277 | 388 | { | ||
278 | 389 | std::cout << "User agent: " << user_agent_hdr; | ||
279 | 390 | headers.push_back(std::make_pair("User-Agent", user_agent_hdr)); | ||
280 | 391 | } | ||
281 | 392 | |||
282 | 384 | query_results_[search_id] = http_client_->get(search_uri.str(), [this, handler](std::string const& lineData) { | 393 | query_results_[search_id] = http_client_->get(search_uri.str(), [this, handler](std::string const& lineData) { |
283 | 385 | try | 394 | try |
284 | 386 | { | 395 | { |
285 | @@ -390,7 +399,7 @@ | |||
286 | 390 | { | 399 | { |
287 | 391 | std::cerr << "Failed to parse: " << e.what() << std::endl; | 400 | std::cerr << "Failed to parse: " << e.what() << std::endl; |
288 | 392 | } | 401 | } |
290 | 393 | }); | 402 | }, headers); |
291 | 394 | 403 | ||
292 | 395 | return SearchHandle::UPtr(new SearchHandle(search_id, shared_from_this())); | 404 | return SearchHandle::UPtr(new SearchHandle(search_id, shared_from_this())); |
293 | 396 | } | 405 | } |
294 | @@ -403,6 +412,7 @@ | |||
295 | 403 | const uint widgets_api_version, | 412 | const uint widgets_api_version, |
296 | 404 | VariantMap const& settings, | 413 | VariantMap const& settings, |
297 | 405 | std::string const& locale, | 414 | std::string const& locale, |
298 | 415 | std::string const& user_agent_hdr, | ||
299 | 406 | std::string const& country) | 416 | std::string const& country) |
300 | 407 | { | 417 | { |
301 | 408 | std::ostringstream preview_uri; | 418 | std::ostringstream preview_uri; |
302 | @@ -415,6 +425,12 @@ | |||
303 | 415 | preview_uri << "&platform=" << platform; | 425 | preview_uri << "&platform=" << platform; |
304 | 416 | preview_uri << "&widgets_api_version=" << std::to_string(widgets_api_version); | 426 | preview_uri << "&widgets_api_version=" << std::to_string(widgets_api_version); |
305 | 417 | 427 | ||
306 | 428 | HttpHeaders headers; | ||
307 | 429 | if (!user_agent_hdr.empty()) | ||
308 | 430 | { | ||
309 | 431 | headers.push_back(std::make_pair("User-Agent", user_agent_hdr)); | ||
310 | 432 | } | ||
311 | 433 | |||
312 | 418 | // optional parameters | 434 | // optional parameters |
313 | 419 | 435 | ||
314 | 420 | if (!settings.empty()) | 436 | if (!settings.empty()) |
315 | @@ -447,7 +463,7 @@ | |||
316 | 447 | { | 463 | { |
317 | 448 | std::cerr << "Failed to parse: " << e.what() << std::endl; | 464 | std::cerr << "Failed to parse: " << e.what() << std::endl; |
318 | 449 | } | 465 | } |
320 | 450 | }); | 466 | }, headers); |
321 | 451 | 467 | ||
322 | 452 | return PreviewHandle::UPtr(new PreviewHandle(preview_id, shared_from_this())); | 468 | return PreviewHandle::UPtr(new PreviewHandle(preview_id, shared_from_this())); |
323 | 453 | } | 469 | } |
324 | 454 | 470 | ||
325 | === modified file 'test/gtest/scopes/internal/smartscopes/SmartScopesClient/FakeSss.py' | |||
326 | --- test/gtest/scopes/internal/smartscopes/SmartScopesClient/FakeSss.py 2014-08-05 15:08:30 +0000 | |||
327 | +++ test/gtest/scopes/internal/smartscopes/SmartScopesClient/FakeSss.py 2014-09-25 08:50:05 +0000 | |||
328 | @@ -32,6 +32,9 @@ | |||
329 | 32 | if environ['PATH_INFO'] == '/remote-scopes' and (environ['QUERY_STRING'] == '' or environ['QUERY_STRING'] == 'locale=test_TEST'): | 32 | if environ['PATH_INFO'] == '/remote-scopes' and (environ['QUERY_STRING'] == '' or environ['QUERY_STRING'] == 'locale=test_TEST'): |
330 | 33 | return [remote_scopes_response] | 33 | return [remote_scopes_response] |
331 | 34 | 34 | ||
332 | 35 | if environ['PATH_INFO'] == '/demo/search' and environ['QUERY_STRING'].find('test_user_agent_header') >= 0: | ||
333 | 36 | return [search_response + '\r\n{"result": {"cat_id": "cat1", "art": "https://dash.ubuntu.com/imgs/cat.png", "uri": "URI", "title": "' + environ['HTTP_USER_AGENT'] + '"}}'] | ||
334 | 37 | |||
335 | 35 | if environ['PATH_INFO'] == '/demo/search' and environ['QUERY_STRING'] != '': | 38 | if environ['PATH_INFO'] == '/demo/search' and environ['QUERY_STRING'] != '': |
336 | 36 | return [search_response] | 39 | return [search_response] |
337 | 37 | 40 | ||
338 | 38 | 41 | ||
339 | === modified file 'test/gtest/scopes/internal/smartscopes/SmartScopesClient/SmartScopesClient_test.cpp' | |||
340 | --- test/gtest/scopes/internal/smartscopes/SmartScopesClient/SmartScopesClient_test.cpp 2014-08-28 15:51:48 +0000 | |||
341 | +++ test/gtest/scopes/internal/smartscopes/SmartScopesClient/SmartScopesClient_test.cpp 2014-09-25 08:50:05 +0000 | |||
342 | @@ -140,7 +140,7 @@ | |||
343 | 140 | dept = deptinfo; | 140 | dept = deptinfo; |
344 | 141 | }; | 141 | }; |
345 | 142 | 142 | ||
347 | 143 | auto search_handle = ssc_->search(handler, sss_url_ + "/demo", "stuff", "", "session_id", 0, "platform"); | 143 | auto search_handle = ssc_->search(handler, sss_url_ + "/demo", "stuff", "", "session_id", 0, "platform", VariantMap(), VariantMap(), "en_US", "", "ThisIsUserAgentHeader"); |
348 | 144 | search_handle->wait(); | 144 | search_handle->wait(); |
349 | 145 | 145 | ||
350 | 146 | ASSERT_EQ(3u, results.size()); | 146 | ASSERT_EQ(3u, results.size()); |
351 | @@ -221,6 +221,32 @@ | |||
352 | 221 | EXPECT_EQ(active_option->id(), "salesrank"); | 221 | EXPECT_EQ(active_option->id(), "salesrank"); |
353 | 222 | } | 222 | } |
354 | 223 | 223 | ||
355 | 224 | TEST_F(SmartScopesClientTest, userAgentHeader) | ||
356 | 225 | { | ||
357 | 226 | std::vector<SearchResult> results; | ||
358 | 227 | |||
359 | 228 | SearchReplyHandler handler; | ||
360 | 229 | handler.filters_handler = [](Filters const &) { | ||
361 | 230 | }; | ||
362 | 231 | handler.filter_state_handler = [](FilterState const&) { | ||
363 | 232 | }; | ||
364 | 233 | handler.category_handler = [](std::shared_ptr<SearchCategory> const&) { | ||
365 | 234 | }; | ||
366 | 235 | handler.result_handler = [&results](SearchResult const& result) { | ||
367 | 236 | results.push_back(result); | ||
368 | 237 | }; | ||
369 | 238 | handler.departments_handler = [](std::shared_ptr<DepartmentInfo> const&) { | ||
370 | 239 | }; | ||
371 | 240 | |||
372 | 241 | auto search_handle = ssc_->search(handler, sss_url_ + "/demo", "test_user_agent_header", "", "session_id", 0, "platform", VariantMap(), VariantMap(), "en_US", "", "ThisIsUserAgentHeader"); | ||
373 | 242 | search_handle->wait(); | ||
374 | 243 | |||
375 | 244 | ASSERT_EQ(4u, results.size()); | ||
376 | 245 | |||
377 | 246 | // user agent string is expected in the result title | ||
378 | 247 | EXPECT_EQ("ThisIsUserAgentHeader", results[3].other_params["title"]->as_string()); | ||
379 | 248 | } | ||
380 | 249 | |||
381 | 224 | TEST_F(SmartScopesClientTest, preview) | 250 | TEST_F(SmartScopesClientTest, preview) |
382 | 225 | { | 251 | { |
383 | 226 | PreviewReplyHandler handler; | 252 | PreviewReplyHandler handler; |
FAILED: Continuous integration, rev:258 jenkins. qa.ubuntu. com/job/ unity-scopes- api-devel- ci/1190/ jenkins. qa.ubuntu. com/job/ unity-scopes- api-devel- utopic- amd64-ci/ 748 jenkins. qa.ubuntu. com/job/ unity-scopes- api-devel- utopic- armhf-ci/ 743/console jenkins. qa.ubuntu. com/job/ unity-scopes- api-devel- utopic- i386-ci/ 742/console
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- scopes- api-devel- ci/1190/ rebuild
http://