comparison OrthancFramework/UnitTestsSources/RestApiTests.cpp @ 4330:a01b1c9cbef4

moving generic type definitions from IHttpHandler to HttpToolbox
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Nov 2020 14:39:10 +0100
parents 9684a690ca63
children 072adf3c3409
comparison
equal deleted inserted replaced
4329:9dc0e42f868b 4330:a01b1c9cbef4
31 #include "../Sources/Compression/ZlibCompressor.h" 31 #include "../Sources/Compression/ZlibCompressor.h"
32 #include "../Sources/HttpServer/HttpContentNegociation.h" 32 #include "../Sources/HttpServer/HttpContentNegociation.h"
33 #include "../Sources/HttpServer/MultipartStreamReader.h" 33 #include "../Sources/HttpServer/MultipartStreamReader.h"
34 #include "../Sources/Logging.h" 34 #include "../Sources/Logging.h"
35 #include "../Sources/OrthancException.h" 35 #include "../Sources/OrthancException.h"
36 #include "../Sources/RestApi/RestApi.h"
37 #include "../Sources/RestApi/RestApiHierarchy.h" 36 #include "../Sources/RestApi/RestApiHierarchy.h"
38 #include "../Sources/WebServiceParameters.h" 37 #include "../Sources/WebServiceParameters.h"
39 38
40 #include <ctype.h> 39 #include <ctype.h>
41 #include <boost/lexical_cast.hpp> 40 #include <boost/lexical_cast.hpp>
42 #include <algorithm> 41 #include <algorithm>
42
43 #if ORTHANC_SANDBOXED != 1
44 # include "../Sources/RestApi/RestApi.h"
45 #endif
43 46
44 47
45 using namespace Orthanc; 48 using namespace Orthanc;
46 49
47 #if !defined(UNIT_TESTS_WITH_HTTP_CONNEXIONS) && (ORTHANC_SANDBOXED != 1) 50 #if !defined(UNIT_TESTS_WITH_HTTP_CONNEXIONS) && (ORTHANC_SANDBOXED != 1)
180 183
181 184
182 #if ORTHANC_SANDBOXED != 1 185 #if ORTHANC_SANDBOXED != 1
183 TEST(RestApi, ParseCookies) 186 TEST(RestApi, ParseCookies)
184 { 187 {
185 IHttpHandler::Arguments headers; 188 HttpToolbox::Arguments headers;
186 IHttpHandler::Arguments cookies; 189 HttpToolbox::Arguments cookies;
187 190
188 headers["cookie"] = "a=b;c=d;;;e=f;;g=h;"; 191 headers["cookie"] = "a=b;c=d;;;e=f;;g=h;";
189 HttpToolbox::ParseCookies(cookies, headers); 192 HttpToolbox::ParseCookies(cookies, headers);
190 ASSERT_EQ(4u, cookies.size()); 193 ASSERT_EQ(4u, cookies.size());
191 ASSERT_EQ("b", cookies["a"]); 194 ASSERT_EQ("b", cookies["a"]);
211 #endif 214 #endif
212 215
213 216
214 TEST(RestApi, RestApiPath) 217 TEST(RestApi, RestApiPath)
215 { 218 {
216 IHttpHandler::Arguments args; 219 HttpToolbox::Arguments args;
217 UriComponents trail; 220 UriComponents trail;
218 221
219 { 222 {
220 RestApiPath uri("/coucou/{abc}/d/*"); 223 RestApiPath uri("/coucou/{abc}/d/*");
221 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d/e/f/g")); 224 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d/e/f/g"));
309 class MyVisitor : public RestApiHierarchy::IVisitor 312 class MyVisitor : public RestApiHierarchy::IVisitor
310 { 313 {
311 public: 314 public:
312 virtual bool Visit(const RestApiHierarchy::Resource& resource, 315 virtual bool Visit(const RestApiHierarchy::Resource& resource,
313 const UriComponents& uri, 316 const UriComponents& uri,
314 const IHttpHandler::Arguments& components, 317 const HttpToolbox::Arguments& components,
315 const UriComponents& trailing) ORTHANC_OVERRIDE 318 const UriComponents& trailing) ORTHANC_OVERRIDE
316 { 319 {
317 return resource.Handle(*(RestApiGetCall*) NULL); 320 return resource.Handle(*(RestApiGetCall*) NULL);
318 } 321 }
319 }; 322 };
977 980
978 981
979 982
980 #if ORTHANC_SANDBOXED != 1 983 #if ORTHANC_SANDBOXED != 1
981 984
985
982 namespace 986 namespace
983 { 987 {
984 class TotoBody : public HttpClient::IRequestBody 988 class TotoBody : public HttpClient::IRequestBody
985 { 989 {
986 private: 990 private:
1032 RequestOrigin origin, 1036 RequestOrigin origin,
1033 const char* remoteIp, 1037 const char* remoteIp,
1034 const char* username, 1038 const char* username,
1035 HttpMethod method, 1039 HttpMethod method,
1036 const UriComponents& uri, 1040 const UriComponents& uri,
1037 const Arguments& headers) ORTHANC_OVERRIDE 1041 const HttpToolbox::Arguments& headers) ORTHANC_OVERRIDE
1038 { 1042 {
1039 return false; 1043 return false;
1040 } 1044 }
1041 1045
1042 virtual bool Handle(HttpOutput& output, 1046 virtual bool Handle(HttpOutput& output,
1043 RequestOrigin origin, 1047 RequestOrigin origin,
1044 const char* remoteIp, 1048 const char* remoteIp,
1045 const char* username, 1049 const char* username,
1046 HttpMethod method, 1050 HttpMethod method,
1047 const UriComponents& uri, 1051 const UriComponents& uri,
1048 const Arguments& headers, 1052 const HttpToolbox::Arguments& headers,
1049 const GetArguments& getArguments, 1053 const HttpToolbox::GetArguments& getArguments,
1050 const void* bodyData, 1054 const void* bodyData,
1051 size_t bodySize) ORTHANC_OVERRIDE 1055 size_t bodySize) ORTHANC_OVERRIDE
1052 { 1056 {
1053 printf("received %d\n", static_cast<int>(bodySize)); 1057 printf("received %d\n", static_cast<int>(bodySize));
1054 1058