comparison Core/HttpServer/HttpOutput.cpp @ 43:9be852ad33d2

rename for c
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Sep 2012 09:59:34 +0200
parents 3a584803783e
children a15e90e5d6fc
comparison
equal deleted inserted replaced
42:ea48f38afe5f 43:9be852ad33d2
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(HttpStatus_405_MethodNotAllowed)) + 85 "HTTP/1.1 405 " + std::string(HttpException::GetDescription(Palantir_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(HttpStatus status) 92 void HttpOutput::SendHeader(Palantir_HttpStatus status)
93 { 93 {
94 if (status == HttpStatus_200_Ok || 94 if (status == Palantir_HttpStatus_200_Ok ||
95 status == HttpStatus_405_MethodNotAllowed) 95 status == Palantir_HttpStatus_405_MethodNotAllowed)
96 { 96 {
97 throw PalantirException("Please use the dedicated methods to this HTTP status code in HttpOutput"); 97 throw PalantirException("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(HttpStatus status) 104 void HttpOutput::SendHeaderInternal(Palantir_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(HttpStatus_500_InternalServerError); 139 SendHeaderInternal(Palantir_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(HttpStatus_301_MovedPermanently)) + 183 "HTTP/1.1 301 " + std::string(HttpException::GetDescription(Palantir_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 }