annotate OrthancFramework/Sources/HttpServer/IHttpHandler.h @ 4151:8c559dd5034b

Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Aug 2020 11:59:02 +0200
parents bf7b9edf6b81
children 9dc0e42f868b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3414
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
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: 4044
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: 4044
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: 4044
diff changeset
10 * the License, or (at your option) any later version.
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
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: 4044
diff changeset
15 * Lesser General Public License for more details.
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
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: 4044
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: 4044
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: 4044
diff changeset
19 * <http://www.gnu.org/licenses/>.
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #pragma once
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
25 #include "../Compatibility.h"
2142
5a8840920121 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
26 #include "../Toolbox.h"
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "HttpOutput.h"
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <map>
1515
c94353fbd4e9 cont http compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1446
diff changeset
30 #include <set>
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <vector>
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <string>
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
33 #include <memory>
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 namespace Orthanc
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 class IHttpHandler : public boost::noncopyable
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 public:
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 typedef std::map<std::string, std::string> Arguments;
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 typedef std::vector< std::pair<std::string, std::string> > GetArguments;
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
43
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
44 class IChunkedRequestReader : public boost::noncopyable
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
45 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
46 public:
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
47 virtual ~IChunkedRequestReader()
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
48 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
49 }
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
50
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
51 virtual void AddBodyChunk(const void* data,
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
52 size_t size) = 0;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
53
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
54 virtual void Execute(HttpOutput& output) = 0;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
55 };
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
56
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
57
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 virtual ~IHttpHandler()
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
62 /**
3973
d86bddb50972 fix spelling errors according to debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
63 * This function allows one to deal with chunked transfers (new in
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
64 * Orthanc 1.5.7). It is only called if "method" is POST or PUT.
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
65 **/
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
66 virtual bool CreateChunkedRequestReader(std::unique_ptr<IChunkedRequestReader>& target,
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
67 RequestOrigin origin,
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
68 const char* remoteIp,
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
69 const char* username,
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
70 HttpMethod method,
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
71 const UriComponents& uri,
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
72 const Arguments& headers) = 0;
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
73
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 virtual bool Handle(HttpOutput& output,
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
75 RequestOrigin origin,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
76 const char* remoteIp,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
77 const char* username,
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 HttpMethod method,
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 const UriComponents& uri,
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 const Arguments& headers,
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 const GetArguments& getArguments,
3401
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3395
diff changeset
82 const void* bodyData,
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1442
diff changeset
83 size_t bodySize) = 0;
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 };
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }