Mercurial > hg > orthanc
changeset 3154:6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 21 Jan 2019 12:09:04 +0100 |
parents | 706b60e7ee1e |
children | 077e1101d908 |
files | Core/HttpServer/HttpOutput.cpp Core/HttpServer/HttpServer.cpp Core/HttpServer/IHttpOutputStream.h Core/HttpServer/StringHttpOutput.h NEWS Resources/Patches/civetweb-1.11.patch |
diffstat | 6 files changed, 62 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/HttpServer/HttpOutput.cpp Sun Jan 20 14:02:49 2019 +0100 +++ b/Core/HttpServer/HttpOutput.cpp Mon Jan 21 12:09:04 2019 +0100 @@ -407,12 +407,6 @@ throw OrthancException(ErrorCode_ParameterOutOfRange); } - if (keepAlive_) - { - throw OrthancException(ErrorCode_NotImplemented, - "Multipart answers are not implemented together with keep-alive connections"); - } - if (state_ != State_WritingHeader) { throw OrthancException(ErrorCode_BadSequenceOfCalls); @@ -428,6 +422,20 @@ std::string header = "HTTP/1.1 200 OK\r\n"; + if (keepAlive_) + { +#if ORTHANC_ENABLE_MONGOOSE == 1 + throw OrthancException(ErrorCode_NotImplemented, + "Multipart answers are not implemented together " + "with keep-alive connections if using Mongoose"); +#else + // Turn off Keep-Alive for multipart answers + // https://github.com/civetweb/civetweb/issues/727 + stream_.DisableKeepAlive(); + header += "Connection: close\r\n"; +#endif + } + // Possibly add the cookies for (std::list<std::string>::const_iterator it = headers_.begin(); it != headers_.end(); ++it)
--- a/Core/HttpServer/HttpServer.cpp Sun Jan 20 14:02:49 2019 +0100 +++ b/Core/HttpServer/HttpServer.cpp Mon Jan 21 12:09:04 2019 +0100 @@ -108,6 +108,16 @@ { // Ignore this } + + virtual void DisableKeepAlive() + { +#if ORTHANC_ENABLE_MONGOOSE == 1 + throw OrthancException(ErrorCode_NotImplemented, + "Only available if using CivetWeb"); +#elif ORTHANC_ENABLE_CIVETWEB == 1 + mg_disable_keep_alive(connection_); +#endif + } };
--- a/Core/HttpServer/IHttpOutputStream.h Sun Jan 20 14:02:49 2019 +0100 +++ b/Core/HttpServer/IHttpOutputStream.h Mon Jan 21 12:09:04 2019 +0100 @@ -50,5 +50,9 @@ virtual void OnHttpStatusReceived(HttpStatus status) = 0; virtual void Send(bool isHeader, const void* buffer, size_t length) = 0; + + // Disable HTTP keep alive for this single HTTP connection. Must + // be called before sending the "HTTP/1.1 200 OK" header. + virtual void DisableKeepAlive() = 0; }; }
--- a/Core/HttpServer/StringHttpOutput.h Sun Jan 20 14:02:49 2019 +0100 +++ b/Core/HttpServer/StringHttpOutput.h Mon Jan 21 12:09:04 2019 +0100 @@ -54,6 +54,10 @@ virtual void Send(bool isHeader, const void* buffer, size_t length); + virtual void DisableKeepAlive() + { + } + void GetOutput(std::string& output); }; }
--- a/NEWS Sun Jan 20 14:02:49 2019 +0100 +++ b/NEWS Mon Jan 21 12:09:04 2019 +0100 @@ -1,6 +1,7 @@ Pending changes in the mainline =============================== +* Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive) Version 1.5.2 (2019-01-18)
--- a/Resources/Patches/civetweb-1.11.patch Sun Jan 20 14:02:49 2019 +0100 +++ b/Resources/Patches/civetweb-1.11.patch Mon Jan 21 12:09:04 2019 +0100 @@ -1,6 +1,20 @@ +diff -urEb civetweb-1.11.orig/include/civetweb.h civetweb-1.11/include/civetweb.h +--- civetweb-1.11.orig/include/civetweb.h 2019-01-17 21:09:41.844888908 +0100 ++++ civetweb-1.11/include/civetweb.h 2019-01-21 12:05:08.138998659 +0100 +@@ -1507,6 +1507,10 @@ + #endif + + ++// Added by SJ ++CIVETWEB_API void mg_disable_keep_alive(struct mg_connection *conn); ++ ++ + #ifdef __cplusplus + } + #endif /* __cplusplus */ diff -urEb civetweb-1.11.orig/src/civetweb.c civetweb-1.11/src/civetweb.c --- civetweb-1.11.orig/src/civetweb.c 2019-01-17 21:09:41.852888857 +0100 -+++ civetweb-1.11/src/civetweb.c 2019-01-17 21:23:54.273424124 +0100 ++++ civetweb-1.11/src/civetweb.c 2019-01-21 12:06:35.826868284 +0100 @@ -59,6 +59,9 @@ #if defined(__linux__) && !defined(_XOPEN_SOURCE) #define _XOPEN_SOURCE 600 /* For flockfile() on Linux */ @@ -68,3 +82,17 @@ conn->host = alloc_get_host(conn); if (!conn->host) { mg_snprintf(conn, +@@ -19857,4 +19882,13 @@ + } + + ++// Added by SJ ++void mg_disable_keep_alive(struct mg_connection *conn) ++{ ++ if (conn != NULL) { ++ conn->must_close = 1; ++ } ++} ++ ++ + /* End of civetweb.c */