diff options
author | Dominique Leuenberger <dimstar@opensuse.org> | 2016-09-19 19:32:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-19 19:32:09 +0200 |
commit | 2c5725a9945449b2c68e2aca64d77b2bcf95d5ff (patch) | |
tree | 7e293a946d587e1c5bdc683eb4223607144bb6e4 | |
parent | cc3f7033bb473ab82a5a9c340233717f61eba98b (diff) | |
parent | 3b5b0d0f8140627f63b08e3412e0d810f92e1ee6 (diff) | |
download | libproxy-git-2c5725a9945449b2c68e2aca64d77b2bcf95d5ff.tar.gz |
Merge pull request #39 from paulvt/add-query-params-for-PAC-get
Use the query string (parameters) when requesting PAC files
-rw-r--r-- | libproxy/test/get-pac-test.cpp | 9 | ||||
-rw-r--r-- | libproxy/url.cpp | 22 | ||||
-rw-r--r-- | libproxy/url.hpp | 2 |
3 files changed, 29 insertions, 4 deletions
diff --git a/libproxy/test/get-pac-test.cpp b/libproxy/test/get-pac-test.cpp index a20690b..232898a 100644 --- a/libproxy/test/get-pac-test.cpp +++ b/libproxy/test/get-pac-test.cpp @@ -145,6 +145,9 @@ class TestServer { sendChunked(csock); } else if (strstr(buffer, "without_content_length")) { sendWithoutContentLength(csock); + } else if (strstr(buffer, "parameterized")) { + assert(strstr(buffer, "?arg1=foo&arg2=bar") != NULL); + sendBasic(csock); } else { assert(!"Unsupported request"); } @@ -258,6 +261,7 @@ int main() url overflow("http://localhost:1983/overflow.js"); url chunked("http://localhost:1983/chunked.js"); url without_content_length("http://localhost:1983/without_content_length.js"); + url parameterized("http://localhost:1983/parameterized.js?arg1=foo&arg2=bar"); server.start(); @@ -283,6 +287,11 @@ int main() return 5; // Test failed, exit with error code delete[] pac; + pac = parameterized.get_pac(); + if (!(pac != NULL && strlen(pac) == 10 && !strcmp("0123456789", pac))) + return 5; // Test failed, exit with error code + delete[] pac; + server.stop(); return 0; diff --git a/libproxy/url.cpp b/libproxy/url.cpp index 6176482..b61a9bc 100644 --- a/libproxy/url.cpp +++ b/libproxy/url.cpp @@ -119,6 +119,7 @@ url::url(const string &url) throw(parse_error) : m_orig(url), m_port(0), m_ips(NULL) { size_t idx = 0; size_t hier_part_start, hier_part_end; + size_t query_part_start; size_t path_start, path_end; string hier_part; @@ -151,9 +152,17 @@ url::url(const string &url) throw(parse_error) transform(m_scheme.begin(), m_scheme.end(), m_scheme.begin(), ::tolower); hier_part_start = idx; - hier_part_end = url.find('?', idx); - if (hier_part_end == string::npos) - hier_part_end = url.find('#', idx); + hier_part_end = url.find('#', idx); + query_part_start = url.find('?', idx); + if (query_part_start != string::npos) + { + if (hier_part_end == string::npos) + m_query = url.substr(query_part_start); + else { + m_query = url.substr(query_part_start, hier_part_end - query_part_start); + } + hier_part_end = query_part_start; + } hier_part = url.substr(hier_part_start, hier_part_end == string::npos ? @@ -269,6 +278,7 @@ url& url::operator=(const url& url) { m_orig = url.m_orig; m_pass = url.m_pass; m_path = url.m_path; + m_query = url.m_query; m_port = url.m_port; m_scheme = url.m_scheme; m_user = url.m_user; @@ -356,6 +366,10 @@ string url::get_path() const { return m_path; } +string url::get_query() const { + return m_query; +} + uint16_t url::get_port() const { return m_port; } @@ -434,7 +448,7 @@ char* url::get_pac() { if (sock < 0) return NULL; // Build the request string - request = "GET " + (m_path.size() > 0 ? m_path : "/") + " HTTP/1.1\r\n"; + request = "GET " + (m_path.size() > 0 ? m_path : "/") + m_query + " HTTP/1.1\r\n"; request += "Host: " + m_host + "\r\n"; request += "Accept: " + string(PAC_MIME_TYPE) + "\r\n"; request += "Connection: close\r\n"; diff --git a/libproxy/url.hpp b/libproxy/url.hpp index 2fd6c34..33ac256 100644 --- a/libproxy/url.hpp +++ b/libproxy/url.hpp @@ -59,6 +59,7 @@ public: sockaddr const* const* get_ips(bool usedns); string get_password() const; string get_path() const; + string get_query() const; uint16_t get_port() const; string get_scheme() const; string get_username() const; @@ -75,6 +76,7 @@ private: string m_host; uint16_t m_port; string m_path; + string m_query; sockaddr** m_ips; }; |