@@ -747,6 +747,23 @@ public void setLocale(Locale locale) {
747747
748748 @ Override
749749 public String getHeader (String name ) {
750+ // Need special handling for Content-Type and Content-Length due to
751+ // special handling of these in coyoteResponse
752+ char cc = name .charAt (0 );
753+ if (cc == 'C' || cc == 'c' ) {
754+ if (name .equalsIgnoreCase ("Content-Type" )) {
755+ // Will return null if this has not been set
756+ return getCoyoteResponse ().getContentType ();
757+ }
758+ if (name .equalsIgnoreCase ("Content-Length" )) {
759+ // -1 means not known and is not sent to client
760+ if (getCoyoteResponse ().getContentLengthLong () != -1 ) {
761+ return String .valueOf (getCoyoteResponse ().getContentLengthLong ());
762+ } else {
763+ return null ;
764+ }
765+ }
766+ }
750767 return getCoyoteResponse ().getMimeHeaders ().getHeader (name );
751768 }
752769
@@ -759,13 +776,40 @@ public Collection<String> getHeaderNames() {
759776 for (int i = 0 ; i < n ; i ++) {
760777 result .add (headers .getName (i ).toString ());
761778 }
779+ if (getCoyoteResponse ().getContentType () != null ) {
780+ result .add ("Content-Type" );
781+ }
782+ if (getCoyoteResponse ().getContentLengthLong () != -1 ) {
783+ result .add ("Content-Length" );
784+ }
762785 return result ;
763-
764786 }
765787
766788
767789 @ Override
768790 public Collection <String > getHeaders (String name ) {
791+ // Need special handling for Content-Type and Content-Length due to
792+ // special handling of these in coyoteResponse
793+ char cc = name .charAt (0 );
794+ if (cc == 'C' || cc == 'c' ) {
795+ if (name .equalsIgnoreCase ("Content-Type" )) {
796+ // Will return null if this has not been set
797+ String contentType = getCoyoteResponse ().getContentType ();
798+ if (contentType != null ) {
799+ return Set .of (contentType );
800+ } else {
801+ return Set .of ();
802+ }
803+ }
804+ if (name .equalsIgnoreCase ("Content-Length" )) {
805+ // -1 means not known and is not sent to client
806+ if (getCoyoteResponse ().getContentLengthLong () != -1 ) {
807+ return Set .of (String .valueOf (getCoyoteResponse ().getContentLengthLong ()));
808+ } else {
809+ return Set .of ();
810+ }
811+ }
812+ }
769813 Enumeration <String > enumeration = getCoyoteResponse ().getMimeHeaders ().values (name );
770814 Set <String > result = new LinkedHashSet <>();
771815 while (enumeration .hasMoreElements ()) {
0 commit comments