Mercurial > hg > orthanc
annotate OrthancFramework/UnitTestsSources/RestApiTests.cpp @ 4236:5639ffda467b
preparing merging InternalNode with ResourcesNode
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 09 Oct 2020 09:52:16 +0200 |
parents | 318c16cfccab |
children | b96aedfa8cc1 |
rev | line source |
---|---|
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
1 /** |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1064
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3399
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
6 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4072
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4072
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4072
diff
changeset
|
10 * the License, or (at your option) any later version. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
11 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4072
diff
changeset
|
15 * Lesser General Public License for more details. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4072
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4072
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4072
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
20 **/ |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
21 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
22 |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3853
diff
changeset
|
23 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1 |
4063
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
24 // Must be the first to be sure to use the Orthanc framework shared library |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3992
diff
changeset
|
25 # include <OrthancFramework.h> |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3853
diff
changeset
|
26 #endif |
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3853
diff
changeset
|
27 |
4062 | 28 #include <gtest/gtest.h> |
209 | 29 |
4045 | 30 #include "../Sources/ChunkedBuffer.h" |
31 #include "../Sources/HttpClient.h" | |
32 #include "../Sources/Logging.h" | |
33 #include "../Sources/SystemToolbox.h" | |
34 #include "../Sources/RestApi/RestApi.h" | |
35 #include "../Sources/OrthancException.h" | |
36 #include "../Sources/Compression/ZlibCompressor.h" | |
37 #include "../Sources/RestApi/RestApiHierarchy.h" | |
38 #include "../Sources/HttpServer/HttpContentNegociation.h" | |
39 #include "../Sources/HttpServer/MultipartStreamReader.h" | |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
40 |
4062 | 41 #include <ctype.h> |
42 #include <boost/lexical_cast.hpp> | |
43 #include <algorithm> | |
44 | |
209 | 45 |
46 using namespace Orthanc; | |
47 | |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
48 #if !defined(UNIT_TESTS_WITH_HTTP_CONNEXIONS) |
4063
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
49 # error UNIT_TESTS_WITH_HTTP_CONNEXIONS is not defined |
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
50 #endif |
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
51 |
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
52 #if !defined(ORTHANC_ENABLE_SSL) |
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
53 # error ORTHANC_ENABLE_SSL is not defined |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
54 #endif |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
55 |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
56 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
57 |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
58 TEST(HttpClient, Basic) |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
59 { |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
60 HttpClient c; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
61 ASSERT_FALSE(c.IsVerbose()); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
62 c.SetVerbose(true); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
63 ASSERT_TRUE(c.IsVerbose()); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
64 c.SetVerbose(false); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
65 ASSERT_FALSE(c.IsVerbose()); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
66 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
67 #if UNIT_TESTS_WITH_HTTP_CONNEXIONS == 1 |
2386
883387e2b379
remove dependendy upon ULg Montefiore Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2363
diff
changeset
|
68 // The "http://www.orthanc-server.com/downloads/third-party/" does |
883387e2b379
remove dependendy upon ULg Montefiore Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2363
diff
changeset
|
69 // not automatically redirect to HTTPS, so we cas use it even if the |
883387e2b379
remove dependendy upon ULg Montefiore Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2363
diff
changeset
|
70 // OpenSSL/HTTPS support is disabled in curl |
883387e2b379
remove dependendy upon ULg Montefiore Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2363
diff
changeset
|
71 const std::string BASE = "http://www.orthanc-server.com/downloads/third-party/"; |
2363
f8ef157f2d73
fix unit tests given www.orthanc-server.com now mandatory uses HTTPS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
72 |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
73 Json::Value v; |
2363
f8ef157f2d73
fix unit tests given www.orthanc-server.com now mandatory uses HTTPS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
74 c.SetUrl(BASE + "Product.json"); |
f8ef157f2d73
fix unit tests given www.orthanc-server.com now mandatory uses HTTPS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
75 |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
76 c.Apply(v); |
2187
ad72fbd700b7
move of third party downloads to the main server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2143
diff
changeset
|
77 ASSERT_TRUE(v.type() == Json::objectValue); |
ad72fbd700b7
move of third party downloads to the main server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2143
diff
changeset
|
78 ASSERT_TRUE(v.isMember("Description")); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
79 #endif |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
80 } |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
81 |
1532 | 82 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
83 #if UNIT_TESTS_WITH_HTTP_CONNEXIONS == 1 && ORTHANC_ENABLE_SSL == 1 |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
84 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
85 /** |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
86 The HTTPS CA certificates for BitBucket were extracted as follows: |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
87 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
88 (1) We retrieve the certification chain of BitBucket: |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
89 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
90 # echo | openssl s_client -showcerts -connect www.bitbucket.org:443 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
91 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
92 (2) We see that the certification authority (CA) is |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
93 "www.digicert.com", and the root certificate is "DigiCert High |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
94 Assurance EV Root CA". As a consequence, we navigate to DigiCert to |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
95 find the URL to this CA certificate: |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
96 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
97 firefox https://www.digicert.com/digicert-root-certificates.htm |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
98 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
99 (3) Once we get the URL to the CA certificate, we convert it to a C |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
100 macro that can be used by libcurl: |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
101 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
102 # cd UnitTestsSources |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
103 # ../Resources/RetrieveCACertificates.py BITBUCKET_CERTIFICATES https://www.digicert.com/CACerts/DigiCertHighAssuranceEVRootCA.crt > BitbucketCACertificates.h |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
104 **/ |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
105 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
106 #include "BitbucketCACertificates.h" |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
107 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1532
diff
changeset
|
108 TEST(HttpClient, Ssl) |
1532 | 109 { |
2140 | 110 SystemToolbox::WriteFile(BITBUCKET_CERTIFICATES, "UnitTestsResults/bitbucket.cert"); |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
111 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
112 /*{ |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
113 std::string s; |
2140 | 114 SystemToolbox::ReadFile(s, "/usr/share/ca-certificates/mozilla/WoSign.crt"); |
115 SystemToolbox::WriteFile(s, "UnitTestsResults/bitbucket.cert"); | |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
116 }*/ |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
117 |
1532 | 118 HttpClient c; |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
119 c.SetHttpsVerifyPeers(true); |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
120 c.SetHttpsCACertificates("UnitTestsResults/bitbucket.cert"); |
3853 | 121 |
122 // Test file modified on 2020-04-20, in order to use a git | |
123 // repository on BitBucket instead of a Mercurial repository | |
124 // (because Mercurial support disappears on 2020-05-31) | |
125 c.SetUrl("https://bitbucket.org/osimis/orthanc-setup-samples/raw/master/docker/serve-folders/orthanc/serve-folders.json"); | |
1532 | 126 |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
127 Json::Value v; |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
128 c.Apply(v); |
3853 | 129 ASSERT_TRUE(v.isMember("ServeFolders")); |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
130 } |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1532
diff
changeset
|
131 |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
132 TEST(HttpClient, SslNoVerification) |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
133 { |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
134 HttpClient c; |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
135 c.SetHttpsVerifyPeers(false); |
3853 | 136 c.SetUrl("https://bitbucket.org/osimis/orthanc-setup-samples/raw/master/docker/serve-folders/orthanc/serve-folders.json"); |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
137 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
138 Json::Value v; |
1532 | 139 c.Apply(v); |
3853 | 140 ASSERT_TRUE(v.isMember("ServeFolders")); |
1532 | 141 } |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
142 |
1532 | 143 #endif |
144 | |
145 | |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
146 TEST(ChunkedBuffer, Basic) |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
147 { |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
148 for (unsigned int i = 0; i < 2; i++) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
149 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
150 ChunkedBuffer b; |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
151 |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
152 if (i == 0) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
153 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
154 b.SetPendingBufferSize(0); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
155 ASSERT_EQ(0u, b.GetPendingBufferSize()); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
156 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
157 else |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
158 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
159 ASSERT_EQ(16u * 1024u, b.GetPendingBufferSize()); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
160 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
161 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
162 ASSERT_EQ(0u, b.GetNumBytes()); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
163 |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
164 b.AddChunk("hello", 5); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
165 ASSERT_EQ(5u, b.GetNumBytes()); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
166 |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
167 b.AddChunk("world", 5); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
168 ASSERT_EQ(10u, b.GetNumBytes()); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
169 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
170 std::string s; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
171 b.Flatten(s); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
172 ASSERT_EQ("helloworld", s); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
173 } |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
174 } |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
175 |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
176 |
330 | 177 TEST(RestApi, ParseCookies) |
178 { | |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1419
diff
changeset
|
179 IHttpHandler::Arguments headers; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1419
diff
changeset
|
180 IHttpHandler::Arguments cookies; |
330 | 181 |
332 | 182 headers["cookie"] = "a=b;c=d;;;e=f;;g=h;"; |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1419
diff
changeset
|
183 HttpToolbox::ParseCookies(cookies, headers); |
330 | 184 ASSERT_EQ(4u, cookies.size()); |
185 ASSERT_EQ("b", cookies["a"]); | |
186 ASSERT_EQ("d", cookies["c"]); | |
187 ASSERT_EQ("f", cookies["e"]); | |
188 ASSERT_EQ("h", cookies["g"]); | |
189 | |
332 | 190 headers["cookie"] = " name = value ; name2=value2"; |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1419
diff
changeset
|
191 HttpToolbox::ParseCookies(cookies, headers); |
330 | 192 ASSERT_EQ(2u, cookies.size()); |
193 ASSERT_EQ("value", cookies["name"]); | |
194 ASSERT_EQ("value2", cookies["name2"]); | |
195 | |
332 | 196 headers["cookie"] = " ;;; "; |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1419
diff
changeset
|
197 HttpToolbox::ParseCookies(cookies, headers); |
330 | 198 ASSERT_EQ(0u, cookies.size()); |
199 | |
332 | 200 headers["cookie"] = " ; n=v ;; "; |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1419
diff
changeset
|
201 HttpToolbox::ParseCookies(cookies, headers); |
330 | 202 ASSERT_EQ(1u, cookies.size()); |
203 ASSERT_EQ("v", cookies["n"]); | |
204 } | |
205 | |
209 | 206 TEST(RestApi, RestApiPath) |
207 { | |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1419
diff
changeset
|
208 IHttpHandler::Arguments args; |
209 | 209 UriComponents trail; |
210 | |
211 { | |
212 RestApiPath uri("/coucou/{abc}/d/*"); | |
213 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d/e/f/g")); | |
214 ASSERT_EQ(1u, args.size()); | |
215 ASSERT_EQ(3u, trail.size()); | |
216 ASSERT_EQ("moi", args["abc"]); | |
217 ASSERT_EQ("e", trail[0]); | |
218 ASSERT_EQ("f", trail[1]); | |
219 ASSERT_EQ("g", trail[2]); | |
220 | |
221 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi/f")); | |
222 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d/")); | |
223 ASSERT_FALSE(uri.Match(args, trail, "/a/moi/d")); | |
224 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi")); | |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
225 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
226 ASSERT_EQ(3u, uri.GetLevelCount()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
227 ASSERT_TRUE(uri.IsUniversalTrailing()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
228 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
229 ASSERT_EQ("coucou", uri.GetLevelName(0)); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
230 ASSERT_THROW(uri.GetWildcardName(0), OrthancException); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
231 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
232 ASSERT_EQ("abc", uri.GetWildcardName(1)); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
233 ASSERT_THROW(uri.GetLevelName(1), OrthancException); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
234 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
235 ASSERT_EQ("d", uri.GetLevelName(2)); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
236 ASSERT_THROW(uri.GetWildcardName(2), OrthancException); |
209 | 237 } |
238 | |
239 { | |
240 RestApiPath uri("/coucou/{abc}/d"); | |
241 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi/d/e/f/g")); | |
242 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d")); | |
243 ASSERT_EQ(1u, args.size()); | |
244 ASSERT_EQ(0u, trail.size()); | |
245 ASSERT_EQ("moi", args["abc"]); | |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
246 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
247 ASSERT_EQ(3u, uri.GetLevelCount()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
248 ASSERT_FALSE(uri.IsUniversalTrailing()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
249 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
250 ASSERT_EQ("coucou", uri.GetLevelName(0)); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
251 ASSERT_THROW(uri.GetWildcardName(0), OrthancException); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
252 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
253 ASSERT_EQ("abc", uri.GetWildcardName(1)); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
254 ASSERT_THROW(uri.GetLevelName(1), OrthancException); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
255 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
256 ASSERT_EQ("d", uri.GetLevelName(2)); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
257 ASSERT_THROW(uri.GetWildcardName(2), OrthancException); |
209 | 258 } |
259 | |
260 { | |
261 RestApiPath uri("/*"); | |
262 ASSERT_TRUE(uri.Match(args, trail, "/a/b/c")); | |
263 ASSERT_EQ(0u, args.size()); | |
264 ASSERT_EQ(3u, trail.size()); | |
265 ASSERT_EQ("a", trail[0]); | |
266 ASSERT_EQ("b", trail[1]); | |
267 ASSERT_EQ("c", trail[2]); | |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
268 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
269 ASSERT_EQ(0u, uri.GetLevelCount()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
270 ASSERT_TRUE(uri.IsUniversalTrailing()); |
209 | 271 } |
272 } | |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
273 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
274 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
275 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
276 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
277 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
278 |
968 | 279 static int testValue; |
280 | |
281 template <int value> | |
974 | 282 static void SetValue(RestApiGetCall& get) |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
283 { |
968 | 284 testValue = value; |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
285 } |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
286 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
287 |
969 | 288 static bool GetDirectory(Json::Value& target, |
289 RestApiHierarchy& hierarchy, | |
290 const std::string& uri) | |
291 { | |
292 UriComponents p; | |
293 Toolbox::SplitUriComponents(p, uri); | |
294 return hierarchy.GetDirectory(target, p); | |
295 } | |
296 | |
297 | |
978 | 298 |
299 namespace | |
300 { | |
301 class MyVisitor : public RestApiHierarchy::IVisitor | |
302 { | |
303 public: | |
304 virtual bool Visit(const RestApiHierarchy::Resource& resource, | |
305 const UriComponents& uri, | |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1419
diff
changeset
|
306 const IHttpHandler::Arguments& components, |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2824
diff
changeset
|
307 const UriComponents& trailing) ORTHANC_OVERRIDE |
978 | 308 { |
2543 | 309 return resource.Handle(*(RestApiGetCall*) NULL); |
978 | 310 } |
311 }; | |
312 } | |
313 | |
314 | |
969 | 315 static bool HandleGet(RestApiHierarchy& hierarchy, |
316 const std::string& uri) | |
317 { | |
318 UriComponents p; | |
319 Toolbox::SplitUriComponents(p, uri); | |
978 | 320 MyVisitor visitor; |
321 return hierarchy.LookupResource(p, visitor); | |
969 | 322 } |
323 | |
324 | |
968 | 325 TEST(RestApi, RestApiHierarchy) |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
326 { |
968 | 327 RestApiHierarchy root; |
970 | 328 root.Register("/hello/world/test", SetValue<1>); |
329 root.Register("/hello/world/test2", SetValue<2>); | |
330 root.Register("/hello/{world}/test3/test4", SetValue<3>); | |
331 root.Register("/hello2/*", SetValue<4>); | |
968 | 332 |
333 Json::Value m; | |
334 root.CreateSiteMap(m); | |
335 std::cout << m; | |
336 | |
337 Json::Value d; | |
969 | 338 ASSERT_FALSE(GetDirectory(d, root, "/hello")); |
968 | 339 |
969 | 340 ASSERT_TRUE(GetDirectory(d, root, "/hello/a")); |
968 | 341 ASSERT_EQ(1u, d.size()); |
342 ASSERT_EQ("test3", d[0].asString()); | |
343 | |
969 | 344 ASSERT_TRUE(GetDirectory(d, root, "/hello/world")); |
968 | 345 ASSERT_EQ(2u, d.size()); |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
346 |
969 | 347 ASSERT_TRUE(GetDirectory(d, root, "/hello/a/test3")); |
968 | 348 ASSERT_EQ(1u, d.size()); |
349 ASSERT_EQ("test4", d[0].asString()); | |
350 | |
1064 | 351 ASSERT_TRUE(GetDirectory(d, root, "/hello/world/test")); |
352 ASSERT_TRUE(GetDirectory(d, root, "/hello/world/test2")); | |
969 | 353 ASSERT_FALSE(GetDirectory(d, root, "/hello2")); |
968 | 354 |
355 testValue = 0; | |
969 | 356 ASSERT_TRUE(HandleGet(root, "/hello/world/test")); |
968 | 357 ASSERT_EQ(testValue, 1); |
969 | 358 ASSERT_TRUE(HandleGet(root, "/hello/world/test2")); |
968 | 359 ASSERT_EQ(testValue, 2); |
969 | 360 ASSERT_TRUE(HandleGet(root, "/hello/b/test3/test4")); |
968 | 361 ASSERT_EQ(testValue, 3); |
969 | 362 ASSERT_FALSE(HandleGet(root, "/hello/b/test3/test")); |
968 | 363 ASSERT_EQ(testValue, 3); |
969 | 364 ASSERT_TRUE(HandleGet(root, "/hello2/a/b")); |
968 | 365 ASSERT_EQ(testValue, 4); |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
366 } |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
367 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
368 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
369 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
370 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
371 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
372 namespace |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
373 { |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
374 class AcceptHandler : public HttpContentNegociation::IHandler |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
375 { |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
376 private: |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
377 std::string type_; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
378 std::string subtype_; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
379 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
380 public: |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
381 AcceptHandler() |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
382 { |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
383 Reset(); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
384 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
385 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
386 void Reset() |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
387 { |
1782 | 388 Handle("nope", "nope"); |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
389 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
390 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
391 const std::string& GetType() const |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
392 { |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
393 return type_; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
394 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
395 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
396 const std::string& GetSubType() const |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
397 { |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
398 return subtype_; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
399 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
400 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
401 virtual void Handle(const std::string& type, |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2824
diff
changeset
|
402 const std::string& subtype) ORTHANC_OVERRIDE |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
403 { |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
404 type_ = type; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
405 subtype_ = subtype; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
406 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
407 }; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
408 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
409 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
410 |
1782 | 411 TEST(RestApi, HttpContentNegociation) |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
412 { |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
413 // Reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
414 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
415 AcceptHandler h; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
416 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
417 { |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
418 HttpContentNegociation d; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
419 d.Register("audio/mp3", h); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
420 d.Register("audio/basic", h); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
421 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
422 ASSERT_TRUE(d.Apply("audio/*; q=0.2, audio/basic")); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
423 ASSERT_EQ("audio", h.GetType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
424 ASSERT_EQ("basic", h.GetSubType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
425 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
426 ASSERT_TRUE(d.Apply("audio/*; q=0.2, audio/nope")); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
427 ASSERT_EQ("audio", h.GetType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
428 ASSERT_EQ("mp3", h.GetSubType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
429 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
430 ASSERT_FALSE(d.Apply("application/*; q=0.2, application/pdf")); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
431 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
432 ASSERT_TRUE(d.Apply("*/*; application/*; q=0.2, application/pdf")); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
433 ASSERT_EQ("audio", h.GetType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
434 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
435 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
436 // "This would be interpreted as "text/html and text/x-c are the |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
437 // preferred media types, but if they do not exist, then send the |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
438 // text/x-dvi entity, and if that does not exist, send the |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
439 // text/plain entity."" |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
440 const std::string T1 = "text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c"; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
441 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
442 { |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
443 HttpContentNegociation d; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
444 d.Register("text/plain", h); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
445 d.Register("text/html", h); |
1782 | 446 d.Register("text/x-dvi", h); |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
447 ASSERT_TRUE(d.Apply(T1)); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
448 ASSERT_EQ("text", h.GetType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
449 ASSERT_EQ("html", h.GetSubType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
450 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
451 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
452 { |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
453 HttpContentNegociation d; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
454 d.Register("text/plain", h); |
1782 | 455 d.Register("text/x-dvi", h); |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
456 d.Register("text/x-c", h); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
457 ASSERT_TRUE(d.Apply(T1)); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
458 ASSERT_EQ("text", h.GetType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
459 ASSERT_EQ("x-c", h.GetSubType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
460 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
461 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
462 { |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
463 HttpContentNegociation d; |
1782 | 464 d.Register("text/plain", h); |
465 d.Register("text/x-dvi", h); | |
466 d.Register("text/x-c", h); | |
467 d.Register("text/html", h); | |
468 ASSERT_TRUE(d.Apply(T1)); | |
469 ASSERT_EQ("text", h.GetType()); | |
470 ASSERT_TRUE(h.GetSubType() == "x-c" || h.GetSubType() == "html"); | |
471 } | |
472 | |
473 { | |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
474 HttpContentNegociation d; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
475 d.Register("text/plain", h); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
476 d.Register("text/x-dvi", h); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
477 ASSERT_TRUE(d.Apply(T1)); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
478 ASSERT_EQ("text", h.GetType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
479 ASSERT_EQ("x-dvi", h.GetSubType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
480 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
481 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
482 { |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
483 HttpContentNegociation d; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
484 d.Register("text/plain", h); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
485 ASSERT_TRUE(d.Apply(T1)); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
486 ASSERT_EQ("text", h.GetType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
487 ASSERT_EQ("plain", h.GetSubType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
488 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
489 } |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
490 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
491 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
492 TEST(WebServiceParameters, Serialization) |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
493 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
494 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
495 Json::Value v = Json::arrayValue; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
496 v.append("http://localhost:8042/"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
497 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
498 WebServiceParameters p(v); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
499 ASSERT_FALSE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
500 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
501 Json::Value v2; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
502 p.Serialize(v2, false, true); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
503 ASSERT_EQ(v, v2); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
504 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
505 WebServiceParameters p2(v2); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
506 ASSERT_EQ("http://localhost:8042/", p2.GetUrl()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
507 ASSERT_TRUE(p2.GetUsername().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
508 ASSERT_TRUE(p2.GetPassword().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
509 ASSERT_TRUE(p2.GetCertificateFile().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
510 ASSERT_TRUE(p2.GetCertificateKeyFile().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
511 ASSERT_TRUE(p2.GetCertificateKeyPassword().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
512 ASSERT_FALSE(p2.IsPkcs11Enabled()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
513 } |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
514 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
515 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
516 Json::Value v = Json::arrayValue; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
517 v.append("http://localhost:8042/"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
518 v.append("user"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
519 v.append("pass"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
520 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
521 WebServiceParameters p(v); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
522 ASSERT_FALSE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
523 ASSERT_EQ("http://localhost:8042/", p.GetUrl()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
524 ASSERT_EQ("user", p.GetUsername()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
525 ASSERT_EQ("pass", p.GetPassword()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
526 ASSERT_TRUE(p.GetCertificateFile().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
527 ASSERT_TRUE(p.GetCertificateKeyFile().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
528 ASSERT_TRUE(p.GetCertificateKeyPassword().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
529 ASSERT_FALSE(p.IsPkcs11Enabled()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
530 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
531 Json::Value v2; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
532 p.Serialize(v2, false, true); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
533 ASSERT_EQ(v, v2); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
534 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
535 p.Serialize(v2, false, false /* no password */); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
536 ASSERT_EQ(Json::arrayValue, v2.type()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
537 ASSERT_EQ(3u, v2.size()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
538 ASSERT_EQ("http://localhost:8042/", v2[0u].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
539 ASSERT_EQ("user", v2[1u].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
540 ASSERT_TRUE(v2[2u].asString().empty()); |
4204 | 541 |
542 WebServiceParameters p2(v2); // Test decoding | |
543 ASSERT_EQ("http://localhost:8042/", p2.GetUrl()); | |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
544 } |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
545 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
546 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
547 Json::Value v = Json::arrayValue; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
548 v.append("http://localhost:8042/"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
549 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
550 WebServiceParameters p(v); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
551 ASSERT_FALSE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
552 p.SetPkcs11Enabled(true); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
553 ASSERT_TRUE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
554 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
555 Json::Value v2; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
556 p.Serialize(v2, false, true); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
557 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
558 ASSERT_EQ(Json::objectValue, v2.type()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
559 ASSERT_EQ(3u, v2.size()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
560 ASSERT_EQ("http://localhost:8042/", v2["Url"].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
561 ASSERT_TRUE(v2["Pkcs11"].asBool()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
562 ASSERT_EQ(Json::objectValue, v2["HttpHeaders"].type()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
563 ASSERT_EQ(0u, v2["HttpHeaders"].size()); |
4204 | 564 |
565 WebServiceParameters p2(v2); // Test decoding | |
566 ASSERT_EQ("http://localhost:8042/", p2.GetUrl()); | |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
567 } |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
568 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
569 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
570 Json::Value v = Json::arrayValue; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
571 v.append("http://localhost:8042/"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
572 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
573 WebServiceParameters p(v); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
574 ASSERT_FALSE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
575 p.SetClientCertificate("a", "b", "c"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
576 ASSERT_TRUE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
577 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
578 Json::Value v2; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
579 p.Serialize(v2, false, true); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
580 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
581 ASSERT_EQ(Json::objectValue, v2.type()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
582 ASSERT_EQ(6u, v2.size()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
583 ASSERT_EQ("http://localhost:8042/", v2["Url"].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
584 ASSERT_EQ("a", v2["CertificateFile"].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
585 ASSERT_EQ("b", v2["CertificateKeyFile"].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
586 ASSERT_EQ("c", v2["CertificateKeyPassword"].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
587 ASSERT_FALSE(v2["Pkcs11"].asBool()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
588 ASSERT_EQ(Json::objectValue, v2["HttpHeaders"].type()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
589 ASSERT_EQ(0u, v2["HttpHeaders"].size()); |
4204 | 590 |
591 WebServiceParameters p2(v2); // Test decoding | |
592 ASSERT_EQ("http://localhost:8042/", p2.GetUrl()); | |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
593 } |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
594 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
595 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
596 Json::Value v = Json::arrayValue; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
597 v.append("http://localhost:8042/"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
598 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
599 WebServiceParameters p(v); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
600 ASSERT_FALSE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
601 p.AddHttpHeader("a", "b"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
602 p.AddHttpHeader("c", "d"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
603 ASSERT_TRUE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
604 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
605 Json::Value v2; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
606 p.Serialize(v2, false, true); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
607 WebServiceParameters p2(v2); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
608 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
609 ASSERT_EQ(Json::objectValue, v2.type()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
610 ASSERT_EQ(3u, v2.size()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
611 ASSERT_EQ("http://localhost:8042/", v2["Url"].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
612 ASSERT_FALSE(v2["Pkcs11"].asBool()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
613 ASSERT_EQ(Json::objectValue, v2["HttpHeaders"].type()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
614 ASSERT_EQ(2u, v2["HttpHeaders"].size()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
615 ASSERT_EQ("b", v2["HttpHeaders"]["a"].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
616 ASSERT_EQ("d", v2["HttpHeaders"]["c"].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
617 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
618 std::set<std::string> a; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
619 p2.ListHttpHeaders(a); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
620 ASSERT_EQ(2u, a.size()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
621 ASSERT_TRUE(a.find("a") != a.end()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
622 ASSERT_TRUE(a.find("c") != a.end()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
623 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
624 std::string s; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
625 ASSERT_TRUE(p2.LookupHttpHeader(s, "a")); ASSERT_EQ("b", s); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
626 ASSERT_TRUE(p2.LookupHttpHeader(s, "c")); ASSERT_EQ("d", s); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
627 ASSERT_FALSE(p2.LookupHttpHeader(s, "nope")); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
628 } |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
629 } |
2823
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
630 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
631 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
632 TEST(WebServiceParameters, UserProperties) |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
633 { |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
634 Json::Value v = Json::nullValue; |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
635 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
636 { |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
637 WebServiceParameters p; |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
638 p.SetUrl("http://localhost:8042/"); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
639 ASSERT_FALSE(p.IsAdvancedFormatNeeded()); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
640 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
641 ASSERT_THROW(p.AddUserProperty("Url", "nope"), OrthancException); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
642 p.AddUserProperty("Hello", "world"); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
643 p.AddUserProperty("a", "b"); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
644 ASSERT_TRUE(p.IsAdvancedFormatNeeded()); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
645 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
646 p.Serialize(v, false, true); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
647 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
648 p.ClearUserProperties(); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
649 ASSERT_FALSE(p.IsAdvancedFormatNeeded()); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
650 } |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
651 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
652 { |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
653 WebServiceParameters p(v); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
654 ASSERT_TRUE(p.IsAdvancedFormatNeeded()); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
655 ASSERT_TRUE(p.GetHttpHeaders().empty()); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
656 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
657 std::set<std::string> tmp; |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
658 p.ListUserProperties(tmp); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
659 ASSERT_EQ(2u, tmp.size()); |
2824 | 660 ASSERT_TRUE(tmp.find("a") != tmp.end()); |
661 ASSERT_TRUE(tmp.find("Hello") != tmp.end()); | |
662 ASSERT_TRUE(tmp.find("hello") == tmp.end()); | |
2823
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
663 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
664 std::string s; |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
665 ASSERT_TRUE(p.LookupUserProperty(s, "a")); ASSERT_TRUE(s == "b"); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
666 ASSERT_TRUE(p.LookupUserProperty(s, "Hello")); ASSERT_TRUE(s == "world"); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
667 ASSERT_FALSE(p.LookupUserProperty(s, "hello")); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
668 } |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
669 } |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
670 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
671 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
672 TEST(StringMatcher, Basic) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
673 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
674 StringMatcher matcher("---"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
675 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
676 ASSERT_THROW(matcher.GetMatchBegin(), OrthancException); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
677 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
678 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
679 const std::string s = ""; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
680 ASSERT_FALSE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
681 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
682 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
683 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
684 const std::string s = "abc----def"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
685 ASSERT_TRUE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
686 ASSERT_EQ(3, std::distance(s.begin(), matcher.GetMatchBegin())); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
687 ASSERT_EQ("---", std::string(matcher.GetMatchBegin(), matcher.GetMatchEnd())); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
688 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
689 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
690 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
691 const std::string s = "abc---"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
692 ASSERT_TRUE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
693 ASSERT_EQ(3, std::distance(s.begin(), matcher.GetMatchBegin())); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
694 ASSERT_EQ(s.end(), matcher.GetMatchEnd()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
695 ASSERT_EQ("---", std::string(matcher.GetMatchBegin(), matcher.GetMatchEnd())); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
696 ASSERT_EQ("", std::string(matcher.GetMatchEnd(), s.end())); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
697 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
698 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
699 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
700 const std::string s = "abc--def"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
701 ASSERT_FALSE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
702 ASSERT_THROW(matcher.GetMatchBegin(), OrthancException); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
703 ASSERT_THROW(matcher.GetMatchEnd(), OrthancException); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
704 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
705 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
706 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
707 std::string s(10u, '\0'); // String with null values |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
708 ASSERT_EQ(10u, s.size()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
709 ASSERT_EQ(10u, s.size()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
710 ASSERT_FALSE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
711 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
712 s[9] = '-'; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
713 ASSERT_FALSE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
714 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
715 s[8] = '-'; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
716 ASSERT_FALSE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
717 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
718 s[7] = '-'; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
719 ASSERT_TRUE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
720 ASSERT_EQ(s.c_str() + 7, matcher.GetPointerBegin()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
721 ASSERT_EQ(s.c_str() + 10, matcher.GetPointerEnd()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
722 ASSERT_EQ(s.end() - 3, matcher.GetMatchBegin()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
723 ASSERT_EQ(s.end(), matcher.GetMatchEnd()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
724 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
725 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
726 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
727 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
728 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
729 class MultipartTester : public MultipartStreamReader::IHandler |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
730 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
731 private: |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
732 struct Part |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
733 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
734 MultipartStreamReader::HttpHeaders headers_; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
735 std::string data_; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
736 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
737 Part(const MultipartStreamReader::HttpHeaders& headers, |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
738 const void* part, |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
739 size_t size) : |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
740 headers_(headers), |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
741 data_(reinterpret_cast<const char*>(part), size) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
742 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
743 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
744 }; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
745 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
746 std::vector<Part> parts_; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
747 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
748 public: |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
749 virtual void HandlePart(const MultipartStreamReader::HttpHeaders& headers, |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
750 const void* part, |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
751 size_t size) |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
752 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
753 parts_.push_back(Part(headers, part, size)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
754 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
755 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
756 unsigned int GetCount() const |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
757 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
758 return parts_.size(); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
759 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
760 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
761 MultipartStreamReader::HttpHeaders& GetHeaders(size_t i) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
762 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
763 return parts_[i].headers_; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
764 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
765 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
766 const std::string& GetData(size_t i) const |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
767 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
768 return parts_[i].data_; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
769 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
770 }; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
771 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
772 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
773 TEST(MultipartStreamReader, ParseHeaders) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
774 { |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
775 std::string ct, b, st, header; |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
776 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
777 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
778 MultipartStreamReader::HttpHeaders h; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
779 h["hello"] = "world"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
780 h["Content-Type"] = "world"; // Should be in lower-case |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
781 h["CONTENT-type"] = "world"; // Should be in lower-case |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
782 ASSERT_FALSE(MultipartStreamReader::GetMainContentType(header, h)); |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
783 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
784 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
785 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
786 MultipartStreamReader::HttpHeaders h; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
787 h["content-type"] = "world"; |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
788 ASSERT_TRUE(MultipartStreamReader::GetMainContentType(header, h)); |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
789 ASSERT_EQ(header, "world"); |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
790 ASSERT_FALSE(MultipartStreamReader::ParseMultipartContentType(ct, st, b, header)); |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
791 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
792 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
793 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
794 MultipartStreamReader::HttpHeaders h; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
795 h["content-type"] = "multipart/related; dummy=value; boundary=1234; hello=world"; |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
796 ASSERT_TRUE(MultipartStreamReader::GetMainContentType(header, h)); |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
797 ASSERT_EQ(header, h["content-type"]); |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
798 ASSERT_TRUE(MultipartStreamReader::ParseMultipartContentType(ct, st, b, header)); |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
799 ASSERT_EQ(ct, "multipart/related"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
800 ASSERT_EQ(b, "1234"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
801 ASSERT_TRUE(st.empty()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
802 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
803 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
804 { |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
805 ASSERT_FALSE(MultipartStreamReader::ParseMultipartContentType |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
806 (ct, st, b, "multipart/related; boundary=")); // Empty boundary |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
807 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
808 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
809 { |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
810 ASSERT_TRUE(MultipartStreamReader::ParseMultipartContentType |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
811 (ct, st, b, "Multipart/Related; TYPE=Application/Dicom; Boundary=heLLO")); |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
812 ASSERT_EQ(ct, "multipart/related"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
813 ASSERT_EQ(b, "heLLO"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
814 ASSERT_EQ(st, "application/dicom"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
815 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
816 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
817 { |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
818 ASSERT_TRUE(MultipartStreamReader::ParseMultipartContentType |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
819 (ct, st, b, "Multipart/Related; type=\"application/DICOM\"; Boundary=a")); |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
820 ASSERT_EQ(ct, "multipart/related"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
821 ASSERT_EQ(b, "a"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
822 ASSERT_EQ(st, "application/dicom"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
823 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
824 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
825 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
826 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
827 TEST(MultipartStreamReader, BytePerByte) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
828 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
829 std::string stream = "GARBAGE"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
830 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
831 std::string boundary = "123456789123456789"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
832 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
833 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
834 for (size_t i = 0; i < 10; i++) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
835 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
836 std::string f = "hello " + boost::lexical_cast<std::string>(i); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
837 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
838 stream += "\r\n--" + boundary + "\r\n"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
839 if (i % 2 == 0) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
840 stream += "Content-Length: " + boost::lexical_cast<std::string>(f.size()) + "\r\n"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
841 stream += "Content-Type: toto " + boost::lexical_cast<std::string>(i) + "\r\n\r\n"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
842 stream += f; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
843 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
844 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
845 stream += "\r\n--" + boundary + "--"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
846 stream += "GARBAGE"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
847 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
848 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
849 for (unsigned int k = 0; k < 2; k++) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
850 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
851 MultipartTester decoded; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
852 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
853 MultipartStreamReader reader(boundary); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
854 reader.SetBlockSize(1); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
855 reader.SetHandler(decoded); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
856 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
857 if (k == 0) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
858 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
859 for (size_t i = 0; i < stream.size(); i++) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
860 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
861 reader.AddChunk(&stream[i], 1); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
862 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
863 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
864 else |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
865 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
866 reader.AddChunk(stream); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
867 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
868 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
869 reader.CloseStream(); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
870 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
871 ASSERT_EQ(10u, decoded.GetCount()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
872 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
873 for (size_t i = 0; i < 10; i++) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
874 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
875 ASSERT_EQ("hello " + boost::lexical_cast<std::string>(i), decoded.GetData(i)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
876 ASSERT_EQ("toto " + boost::lexical_cast<std::string>(i), decoded.GetHeaders(i)["content-type"]); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
877 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
878 if (i % 2 == 0) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
879 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
880 ASSERT_EQ(2u, decoded.GetHeaders(i).size()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
881 ASSERT_TRUE(decoded.GetHeaders(i).find("content-length") != decoded.GetHeaders(i).end()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
882 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
883 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
884 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
885 } |
4072
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
886 |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
887 |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
888 TEST(WebServiceParameters, Url) |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
889 { |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
890 WebServiceParameters w; |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
891 |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
892 ASSERT_THROW(w.SetUrl("ssh://coucou"), OrthancException); |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
893 w.SetUrl("http://coucou"); |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
894 w.SetUrl("https://coucou"); |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
895 ASSERT_THROW(w.SetUrl("httpss://coucou"), OrthancException); |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
896 ASSERT_THROW(w.SetUrl(""), OrthancException); |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
897 |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
898 // New in Orthanc 1.7.2: Allow relative URLs (for DICOMweb in Stone) |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
899 w.SetUrl("coucou"); |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
900 w.SetUrl("/coucou"); |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
901 } |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
902 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
903 |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
904 TEST(ChunkedBuffer, DISABLED_Large) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
905 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
906 const size_t LARGE = 60 * 1024 * 1024; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
907 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
908 ChunkedBuffer b; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
909 for (size_t i = 0; i < LARGE; i++) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
910 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
911 b.AddChunk(boost::lexical_cast<std::string>(i % 10)); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
912 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
913 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
914 std::string s; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
915 b.Flatten(s); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
916 ASSERT_EQ(LARGE, s.size()); |
4157
86e99e08ba52
fix compiler warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4151
diff
changeset
|
917 ASSERT_EQ(0u, b.GetNumBytes()); |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
918 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
919 for (size_t i = 0; i < LARGE; i++) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
920 { |
4157
86e99e08ba52
fix compiler warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4151
diff
changeset
|
921 ASSERT_EQ(static_cast<char>('0' + (i % 10)), s[i]); |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
922 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
923 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
924 b.Flatten(s); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
925 ASSERT_EQ(0u, s.size()); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
926 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
927 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
928 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
929 TEST(ChunkedBuffer, Pending) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
930 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
931 ChunkedBuffer b; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
932 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
933 for (size_t pendingSize = 0; pendingSize < 16; pendingSize++) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
934 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
935 b.SetPendingBufferSize(pendingSize); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
936 ASSERT_EQ(pendingSize, b.GetPendingBufferSize()); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
937 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
938 unsigned int pos = 0; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
939 unsigned int iteration = 0; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
940 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
941 while (pos < 1024) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
942 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
943 size_t chunkSize = (iteration % 17); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
944 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
945 std::string chunk; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
946 chunk.resize(chunkSize); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
947 for (size_t i = 0; i < chunkSize; i++) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
948 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
949 chunk[i] = '0' + (pos % 10); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
950 pos++; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
951 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
952 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
953 b.AddChunk(chunk); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
954 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
955 iteration ++; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
956 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
957 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
958 std::string s; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
959 b.Flatten(s); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
960 ASSERT_EQ(0u, b.GetNumBytes()); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
961 ASSERT_EQ(pos, s.size()); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
962 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
963 for (size_t i = 0; i < s.size(); i++) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
964 { |
4157
86e99e08ba52
fix compiler warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4151
diff
changeset
|
965 ASSERT_EQ(static_cast<char>('0' + (i % 10)), s[i]); |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
966 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
967 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
968 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
969 |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
970 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
971 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
972 namespace |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
973 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
974 class TotoBody : public HttpClient::IRequestBody |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
975 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
976 private: |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
977 size_t size_; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
978 size_t chunkSize_; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
979 size_t pos_; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
980 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
981 public: |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
982 TotoBody(size_t size, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
983 size_t chunkSize) : |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
984 size_(size), |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
985 chunkSize_(chunkSize), |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
986 pos_(0) |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
987 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
988 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
989 |
4204 | 990 virtual bool ReadNextChunk(std::string& chunk) ORTHANC_OVERRIDE |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
991 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
992 if (pos_ == size_) |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
993 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
994 return false; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
995 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
996 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
997 chunk.clear(); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
998 chunk.resize(chunkSize_); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
999 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1000 size_t i = 0; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1001 while (pos_ < size_ && |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1002 i < chunk.size()) |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1003 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1004 chunk[i] = '0' + (pos_ % 7); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1005 pos_++; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1006 i++; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1007 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1008 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1009 if (i < chunk.size()) |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1010 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1011 chunk.erase(i, chunk.size()); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1012 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1013 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1014 return true; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1015 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1016 }; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1017 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1018 class TotoServer : public IHttpHandler |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1019 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1020 public: |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1021 virtual bool CreateChunkedRequestReader(std::unique_ptr<IChunkedRequestReader>& target, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1022 RequestOrigin origin, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1023 const char* remoteIp, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1024 const char* username, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1025 HttpMethod method, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1026 const UriComponents& uri, |
4204 | 1027 const Arguments& headers) ORTHANC_OVERRIDE |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1028 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1029 return false; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1030 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1031 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1032 virtual bool Handle(HttpOutput& output, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1033 RequestOrigin origin, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1034 const char* remoteIp, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1035 const char* username, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1036 HttpMethod method, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1037 const UriComponents& uri, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1038 const Arguments& headers, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1039 const GetArguments& getArguments, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1040 const void* bodyData, |
4204 | 1041 size_t bodySize) ORTHANC_OVERRIDE |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1042 { |
4158
32ac045109a6
fix compiler warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4157
diff
changeset
|
1043 printf("received %d\n", static_cast<int>(bodySize)); |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1044 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1045 const uint8_t* b = reinterpret_cast<const uint8_t*>(bodyData); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1046 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1047 for (size_t i = 0; i < bodySize; i++) |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1048 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1049 if (b[i] != ('0' + i % 7)) |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1050 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1051 throw; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1052 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1053 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1054 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1055 output.Answer("ok"); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1056 return true; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1057 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1058 }; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1059 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1060 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1061 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1062 #include "../Sources/HttpServer/HttpServer.h" |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1063 |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1064 TEST(HttpClient, DISABLED_Issue156_Slow) |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1065 { |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1066 // https://bugs.orthanc-server.com/show_bug.cgi?id=156 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1067 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1068 TotoServer handler; |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1069 HttpServer server; |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1070 server.SetPortNumber(5000); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1071 server.Register(handler); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1072 server.Start(); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1073 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1074 WebServiceParameters w; |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1075 w.SetUrl("http://localhost:5000"); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1076 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1077 // This is slow in Orthanc <= 1.5.8 (issue 156) |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1078 TotoBody body(600 * 1024 * 1024, 6 * 1024 * 1024 - 17); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1079 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1080 HttpClient c(w, "toto"); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1081 c.SetMethod(HttpMethod_Post); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1082 c.AddHeader("Expect", ""); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1083 c.AddHeader("Transfer-Encoding", "chunked"); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1084 c.SetBody(body); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1085 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1086 std::string s; |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1087 ASSERT_TRUE(c.Apply(s)); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1088 ASSERT_EQ("ok", s); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1089 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1090 server.Stop(); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1091 } |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1092 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1093 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1094 TEST(HttpClient, DISABLED_Issue156_Crash) |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1095 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1096 TotoServer handler; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1097 HttpServer server; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1098 server.SetPortNumber(5000); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1099 server.Register(handler); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1100 server.Start(); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1101 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1102 WebServiceParameters w; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1103 w.SetUrl("http://localhost:5000"); |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1104 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1105 // This crashes Orthanc 1.6.0 to 1.7.2 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1106 TotoBody body(32 * 1024, 1); |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1107 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1108 HttpClient c(w, "toto"); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1109 c.SetMethod(HttpMethod_Post); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1110 c.AddHeader("Expect", ""); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1111 c.AddHeader("Transfer-Encoding", "chunked"); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1112 c.SetBody(body); |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1113 |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1114 std::string s; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1115 ASSERT_TRUE(c.Apply(s)); |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1116 ASSERT_EQ("ok", s); |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1117 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1118 server.Stop(); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1119 } |