# HG changeset patch
# User Sebastien Jodogne <s.jodogne@gmail.com>
# Date 1579780688 -3600
# Node ID b6a569e6e85bbee2e40fca719cf8c5f2ed76024f
# Parent  a77e7839012ac2355d3136b0c8736edf193a1605
Fix issue #165

diff -r a77e7839012a -r b6a569e6e85b Core/HttpServer/HttpOutput.cpp
--- a/Core/HttpServer/HttpOutput.cpp	Thu Jan 16 12:50:06 2020 +0100
+++ b/Core/HttpServer/HttpOutput.cpp	Thu Jan 23 12:58:08 2020 +0100
@@ -463,6 +463,21 @@
     }
 
     boundary = Toolbox::GenerateUuid() + "-" + Toolbox::GenerateUuid();
+
+    /**
+     * Fix for issue #165: "Encapsulation boundaries must not appear
+     * within the encapsulations, and must be no longer than 70
+     * characters, not counting the two leading hyphens."
+     * https://tools.ietf.org/html/rfc1521
+     * https://bitbucket.org/sjodogne/orthanc/issues/165/
+     **/
+    if (boundary.size() != 36 + 1 + 36)  // one UUID contains 36 characters
+    {
+      throw OrthancException(ErrorCode_InternalError);
+    }
+    
+    boundary = boundary.substr(0, 70);
+    
     contentTypeHeader = ("multipart/" + subType + "; type=" + tmp + "; boundary=" + boundary);
   }
 
diff -r a77e7839012a -r b6a569e6e85b NEWS
--- a/NEWS	Thu Jan 16 12:50:06 2020 +0100
+++ b/NEWS	Thu Jan 23 12:58:08 2020 +0100
@@ -15,6 +15,7 @@
 * C-Find SCU at Instance level now sets the 0008,0052 tag to IMAGE per default (was INSTANCE).
   Therefore, the "ClearCanvas" and "Dcm4Chee" modality manufacturer have now been deprecated.
 * Fix issue #156 (Chunked Dicom-web transfer uses 100% CPU)
+* Fix issue #165 (Boundary parameter in multipart Content-Type is too long)
 * /instances/{id}/preview route now takes the windowing into account
 
 Version 1.5.8 (2019-10-16)