# HG changeset patch # User Sebastien Jodogne # Date 1548068944 -3600 # Node ID 6e8822be2f08c2bacf26304ca1a31911eeadc285 # Parent 706b60e7ee1e99df13c016f7151581ccfad63e59 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive) diff -r 706b60e7ee1e -r 6e8822be2f08 Core/HttpServer/HttpOutput.cpp --- 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::const_iterator it = headers_.begin(); it != headers_.end(); ++it) diff -r 706b60e7ee1e -r 6e8822be2f08 Core/HttpServer/HttpServer.cpp --- 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 + } }; diff -r 706b60e7ee1e -r 6e8822be2f08 Core/HttpServer/IHttpOutputStream.h --- 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; }; } diff -r 706b60e7ee1e -r 6e8822be2f08 Core/HttpServer/StringHttpOutput.h --- 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); }; } diff -r 706b60e7ee1e -r 6e8822be2f08 NEWS --- 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) diff -r 706b60e7ee1e -r 6e8822be2f08 Resources/Patches/civetweb-1.11.patch --- 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 */