Mercurial > hg > orthanc
comparison Core/HttpServer/HttpOutput.cpp @ 1517:4f8c8ef114db
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Aug 2015 10:32:34 +0200 |
parents | d73a2178b319 |
children | 8bd0d897763f |
comparison
equal
deleted
inserted
replaced
1516:f09f5d3225a7 | 1517:4f8c8ef114db |
---|---|
213 state_ = State_Done; | 213 state_ = State_Done; |
214 } | 214 } |
215 } | 215 } |
216 | 216 |
217 | 217 |
218 HttpCompression HttpOutput::GetPreferredCompression(size_t bodySize) const | |
219 { | |
220 #if 0 | |
221 // TODO Do not compress small files? | |
222 if (bodySize < 512) | |
223 { | |
224 return HttpCompression_None; | |
225 } | |
226 #endif | |
227 | |
228 // Prefer "gzip" over "deflate" if the choice is offered | |
229 | |
230 if (isGzipAllowed_) | |
231 { | |
232 return HttpCompression_Gzip; | |
233 } | |
234 else if (isDeflateAllowed_) | |
235 { | |
236 return HttpCompression_Deflate; | |
237 } | |
238 else | |
239 { | |
240 return HttpCompression_None; | |
241 } | |
242 } | |
243 | |
244 | |
218 void HttpOutput::SendMethodNotAllowed(const std::string& allowed) | 245 void HttpOutput::SendMethodNotAllowed(const std::string& allowed) |
219 { | 246 { |
220 stateMachine_.ClearHeaders(); | 247 stateMachine_.ClearHeaders(); |
221 stateMachine_.SetHttpStatus(HttpStatus_405_MethodNotAllowed); | 248 stateMachine_.SetHttpStatus(HttpStatus_405_MethodNotAllowed); |
222 stateMachine_.AddHeader("Allow", allowed); | 249 stateMachine_.AddHeader("Allow", allowed); |
257 stateMachine_.AddHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\""); | 284 stateMachine_.AddHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\""); |
258 stateMachine_.SendBody(NULL, 0); | 285 stateMachine_.SendBody(NULL, 0); |
259 } | 286 } |
260 | 287 |
261 void HttpOutput::SendBody(const void* buffer, | 288 void HttpOutput::SendBody(const void* buffer, |
262 size_t length, | 289 size_t length) |
263 HttpCompression compression) | |
264 { | 290 { |
265 if (length == 0) | 291 if (length == 0) |
266 { | 292 { |
267 stateMachine_.SendBody(NULL, 0); | 293 stateMachine_.SendBody(NULL, 0); |
268 } | 294 } |
269 else | 295 else |
270 { | 296 { |
297 HttpCompression compression = GetPreferredCompression(length); | |
298 | |
271 switch (compression) | 299 switch (compression) |
272 { | 300 { |
273 case HttpCompression_None: | 301 case HttpCompression_None: |
274 { | 302 { |
275 stateMachine_.SendBody(buffer, length); | 303 stateMachine_.SendBody(buffer, length); |
316 throw OrthancException(ErrorCode_NotImplemented); | 344 throw OrthancException(ErrorCode_NotImplemented); |
317 } | 345 } |
318 } | 346 } |
319 } | 347 } |
320 | 348 |
321 void HttpOutput::SendBody(const std::string& str, | 349 void HttpOutput::SendBody(const std::string& str) |
322 HttpCompression compression) | 350 { |
323 { | 351 SendBody(str.size() == 0 ? NULL : str.c_str(), str.size()); |
324 SendBody(str.size() == 0 ? NULL : str.c_str(), str.size(), compression); | |
325 } | 352 } |
326 | 353 |
327 void HttpOutput::SendBody() | 354 void HttpOutput::SendBody() |
328 { | 355 { |
329 stateMachine_.SendBody(NULL, 0); | 356 stateMachine_.SendBody(NULL, 0); |