Mercurial > hg > orthanc
comparison Core/HttpServer/HttpOutput.cpp @ 50:a15e90e5d6fc
rename in code
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 05 Sep 2012 15:50:12 +0200 |
parents | 9be852ad33d2 |
children | c996319e90bc |
comparison
equal
deleted
inserted
replaced
49:e1a3ae0dadf3 | 50:a15e90e5d6fc |
---|---|
1 /** | 1 /** |
2 * Palantir - A Lightweight, RESTful DICOM Store | 2 * Palanthir - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, | 3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, |
4 * Belgium | 4 * Belgium |
5 * | 5 * |
6 * This program is free software: you can redistribute it and/or | 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 | 7 * modify it under the terms of the GNU General Public License as |
21 #include "HttpOutput.h" | 21 #include "HttpOutput.h" |
22 | 22 |
23 #include <vector> | 23 #include <vector> |
24 #include <stdio.h> | 24 #include <stdio.h> |
25 #include <boost/lexical_cast.hpp> | 25 #include <boost/lexical_cast.hpp> |
26 #include "../PalantirException.h" | 26 #include "../PalanthirException.h" |
27 #include "../Toolbox.h" | 27 #include "../Toolbox.h" |
28 #include "../../PalantirCppClient/HttpException.h" | 28 #include "../../PalanthirCppClient/HttpException.h" |
29 | 29 |
30 namespace Palantir | 30 namespace Palanthir |
31 { | 31 { |
32 void HttpOutput::SendString(const std::string& s) | 32 void HttpOutput::SendString(const std::string& s) |
33 { | 33 { |
34 if (s.size() > 0) | 34 if (s.size() > 0) |
35 Send(&s[0], s.size()); | 35 Send(&s[0], s.size()); |
80 | 80 |
81 | 81 |
82 void HttpOutput::SendMethodNotAllowedError(const std::string& allowed) | 82 void HttpOutput::SendMethodNotAllowedError(const std::string& allowed) |
83 { | 83 { |
84 std::string s = | 84 std::string s = |
85 "HTTP/1.1 405 " + std::string(HttpException::GetDescription(Palantir_HttpStatus_405_MethodNotAllowed)) + | 85 "HTTP/1.1 405 " + std::string(HttpException::GetDescription(Palanthir_HttpStatus_405_MethodNotAllowed)) + |
86 "\r\nAllow: " + allowed + | 86 "\r\nAllow: " + allowed + |
87 "\r\n\r\n"; | 87 "\r\n\r\n"; |
88 Send(&s[0], s.size()); | 88 Send(&s[0], s.size()); |
89 } | 89 } |
90 | 90 |
91 | 91 |
92 void HttpOutput::SendHeader(Palantir_HttpStatus status) | 92 void HttpOutput::SendHeader(Palanthir_HttpStatus status) |
93 { | 93 { |
94 if (status == Palantir_HttpStatus_200_Ok || | 94 if (status == Palanthir_HttpStatus_200_Ok || |
95 status == Palantir_HttpStatus_405_MethodNotAllowed) | 95 status == Palanthir_HttpStatus_405_MethodNotAllowed) |
96 { | 96 { |
97 throw PalantirException("Please use the dedicated methods to this HTTP status code in HttpOutput"); | 97 throw PalanthirException("Please use the dedicated methods to this HTTP status code in HttpOutput"); |
98 } | 98 } |
99 | 99 |
100 SendHeaderInternal(status); | 100 SendHeaderInternal(status); |
101 } | 101 } |
102 | 102 |
103 | 103 |
104 void HttpOutput::SendHeaderInternal(Palantir_HttpStatus status) | 104 void HttpOutput::SendHeaderInternal(Palanthir_HttpStatus status) |
105 { | 105 { |
106 std::string s = "HTTP/1.1 " + | 106 std::string s = "HTTP/1.1 " + |
107 boost::lexical_cast<std::string>(status) + | 107 boost::lexical_cast<std::string>(status) + |
108 " " + std::string(HttpException::GetDescription(status)) + | 108 " " + std::string(HttpException::GetDescription(status)) + |
109 "\r\n\r\n"; | 109 "\r\n\r\n"; |
134 uint64_t fileSize = Toolbox::GetFileSize(path); | 134 uint64_t fileSize = Toolbox::GetFileSize(path); |
135 | 135 |
136 FILE* fp = fopen(path.c_str(), "rb"); | 136 FILE* fp = fopen(path.c_str(), "rb"); |
137 if (!fp) | 137 if (!fp) |
138 { | 138 { |
139 SendHeaderInternal(Palantir_HttpStatus_500_InternalServerError); | 139 SendHeaderInternal(Palanthir_HttpStatus_500_InternalServerError); |
140 return; | 140 return; |
141 } | 141 } |
142 | 142 |
143 SendOkHeader(contentType.c_str(), true, fileSize); | 143 SendOkHeader(contentType.c_str(), true, fileSize); |
144 | 144 |
178 | 178 |
179 | 179 |
180 void HttpOutput::Redirect(const std::string& path) | 180 void HttpOutput::Redirect(const std::string& path) |
181 { | 181 { |
182 std::string s = | 182 std::string s = |
183 "HTTP/1.1 301 " + std::string(HttpException::GetDescription(Palantir_HttpStatus_301_MovedPermanently)) + | 183 "HTTP/1.1 301 " + std::string(HttpException::GetDescription(Palanthir_HttpStatus_301_MovedPermanently)) + |
184 "\r\nLocation: " + path + | 184 "\r\nLocation: " + path + |
185 "\r\n\r\n"; | 185 "\r\n\r\n"; |
186 Send(&s[0], s.size()); | 186 Send(&s[0], s.size()); |
187 } | 187 } |
188 } | 188 } |