From 813d84a9fb59121e4ac736570c8a3af2569c6827 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Tue, 11 Feb 2020 07:48:58 -0500 Subject: [PATCH] ensure we only send one content-type and content-length header --- .../org/cobbzilla/wizard/resources/ResourceUtil.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/wizard-server/src/main/java/org/cobbzilla/wizard/resources/ResourceUtil.java b/wizard-server/src/main/java/org/cobbzilla/wizard/resources/ResourceUtil.java index 8e22f70..30aead5 100644 --- a/wizard-server/src/main/java/org/cobbzilla/wizard/resources/ResourceUtil.java +++ b/wizard-server/src/main/java/org/cobbzilla/wizard/resources/ResourceUtil.java @@ -70,7 +70,17 @@ public class ResourceUtil { if (contentLength != null) builder = builder.header(CONTENT_LENGTH, contentLength); if (headers != null) { for (NameAndValue h : headers) { - builder = builder.header(h.getName(), h.getValue()); + if (h.getName().equalsIgnoreCase(CONTENT_TYPE) && contentType != null) { + // we already added a Content-Type header, don't add a second one + if (log.isDebugEnabled()) log.debug("send: already added "+CONTENT_TYPE+" ("+contentType+"), not adding "+CONTENT_TYPE+" from headers: "+h.getValue()); + + } else if (h.getName().equalsIgnoreCase(CONTENT_LENGTH) && contentLength != null) { + // we already added a Content-Length header, don't add a second one + if (log.isDebugEnabled()) log.debug("send: already added "+CONTENT_LENGTH+" header ("+contentLength+"), not adding "+CONTENT_LENGTH+" from headers: "+h.getValue()); + + } else { + builder = builder.header(h.getName(), h.getValue()); + } } } return builder.build();