Mercurial > hg > orthanc
annotate Core/HttpServer/HttpOutput.h @ 1066:bb82e5e818e9
OnStoredInstance callback in plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 25 Jul 2014 18:39:02 +0200 |
parents | 8d1845feb277 |
children | ba5c0908600c |
rev | line source |
---|---|
0 | 1 /** |
59 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
689 | 3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
0 | 4 * Belgium |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #pragma once | |
34 | |
330 | 35 #include <list> |
0 | 36 #include <string> |
37 #include <stdint.h> | |
38 #include "../Enumerations.h" | |
910 | 39 #include "IHttpOutputStream.h" |
324 | 40 #include "HttpHandler.h" |
0 | 41 |
59 | 42 namespace Orthanc |
0 | 43 { |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
911
diff
changeset
|
44 class HttpOutput : public boost::noncopyable |
0 | 45 { |
46 private: | |
330 | 47 typedef std::list< std::pair<std::string, std::string> > Header; |
48 | |
910 | 49 class StateMachine : public boost::noncopyable |
50 { | |
911 | 51 private: |
910 | 52 enum State |
53 { | |
54 State_WaitingHttpStatus, | |
55 State_WritingHeader, | |
56 State_WritingBody | |
57 }; | |
58 | |
59 IHttpOutputStream& stream_; | |
60 State state_; | |
61 | |
62 public: | |
911 | 63 StateMachine(IHttpOutputStream& stream) : |
64 stream_(stream), | |
910 | 65 state_(State_WaitingHttpStatus) |
66 { | |
67 } | |
68 | |
69 void SendHttpStatus(HttpStatus status); | |
70 | |
71 void SendHeaderData(const void* buffer, size_t length); | |
72 | |
73 void SendHeaderString(const std::string& str); | |
74 | |
75 void SendBodyData(const void* buffer, size_t length); | |
76 | |
77 void SendBodyString(const std::string& str); | |
78 }; | |
79 | |
330 | 80 void PrepareOkHeader(Header& header, |
81 const char* contentType, | |
82 bool hasContentLength, | |
83 uint64_t contentLength, | |
84 const char* contentFilename); | |
85 | |
86 void SendOkHeader(const Header& header); | |
87 | |
910 | 88 StateMachine stateMachine_; |
1042
8d1845feb277
set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
912
diff
changeset
|
89 HttpHandler::Arguments cookies_; |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
90 |
0 | 91 public: |
910 | 92 HttpOutput(IHttpOutputStream& stream) : stateMachine_(stream) |
0 | 93 { |
94 } | |
95 | |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
96 void SendOkHeader(const char* contentType, |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
97 bool hasContentLength, |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
98 uint64_t contentLength, |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
99 const char* contentFilename); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
217
diff
changeset
|
100 |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
101 void SendBodyData(const void* buffer, size_t length) |
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
102 { |
911 | 103 stateMachine_.SendBodyData(buffer, length); |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
104 } |
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
105 |
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
106 void SendBodyString(const std::string& str) |
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
107 { |
911 | 108 stateMachine_.SendBodyString(str); |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
109 } |
0 | 110 |
1042
8d1845feb277
set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
912
diff
changeset
|
111 void SendMethodNotAllowed(const std::string& allowed); |
0 | 112 |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
113 void SendHeader(HttpStatus status); |
0 | 114 |
217 | 115 void Redirect(const std::string& path); |
0 | 116 |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
117 void SendUnauthorized(const std::string& realm); |
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
118 |
1042
8d1845feb277
set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
912
diff
changeset
|
119 void SetCookie(const std::string& cookie, |
8d1845feb277
set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
912
diff
changeset
|
120 const std::string& value) |
8d1845feb277
set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
912
diff
changeset
|
121 { |
8d1845feb277
set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
912
diff
changeset
|
122 cookies_[cookie] = value; |
8d1845feb277
set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
912
diff
changeset
|
123 } |
8d1845feb277
set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
912
diff
changeset
|
124 |
217 | 125 // Higher-level constructs to send entire buffers ---------------------------- |
0 | 126 |
127 void AnswerBufferWithContentType(const std::string& buffer, | |
128 const std::string& contentType); | |
129 | |
130 void AnswerBufferWithContentType(const void* buffer, | |
131 size_t size, | |
132 const std::string& contentType); | |
133 }; | |
134 } |