zinc icon indicating copy to clipboard operation
zinc copied to clipboard

Calling ZnHeaders>>#contentType raises an DNU exception if multiple Content-Type headers are present

Open udoschneider opened this issue 4 years ago • 0 comments

In ZnHeaders>>#contentType #trimBoth is sent to header's Content-Type value:

headerValue := (self headers at: 'Content-Type') trimBoth.

If only a single Content-Type header was part of the response the result of (self headers at: 'Content-Type') is a String and everything works. However if the response specified multiple Content-Type headers the result is an Array and calling #trimBoth raises an exception.

A simple testcase to raise the error:

ZnHeadersTest>>#testMultiValuedContentType
	| headers |
	headers := ZnHeaders new.
	headers at: 'Content-Type' put: 'application/javascript'.
	headers at: 'Content-Type' add: 'application/x-javascript'.
	self
		assert: (headers at: 'Content-Type')
		equals: #('application/javascript' 'application/x-javascript').
	self
		shouldnt: [ headers contentType ]
		raise: Error
		description: '''Content-Type'' could have multiple values.'

udoschneider avatar Aug 15 '20 11:08 udoschneider