@@ -21,6 +21,7 @@ import org.apache.http.entity.StringEntity
21
21
import org.apache.http.impl.client.CloseableHttpClient
22
22
import org.apache.http.message.BasicHeader
23
23
import org.apache.http.message.BasicStatusLine
24
+ import spock.lang.Issue
24
25
import spock.lang.Specification
25
26
import spock.lang.Unroll
26
27
@@ -83,7 +84,7 @@ class ProviderClientSpec extends Specification {
83
84
0 * httpRequest. _
84
85
}
85
86
86
- def ' setting up headers adds an JSON content type if none was provided and there is a body' () {
87
+ def ' setting up headers adds an TEXT content type if none was provided and there is a body' () {
87
88
given :
88
89
def headers = [
89
90
A : [' a' ],
@@ -100,12 +101,12 @@ class ProviderClientSpec extends Specification {
100
101
headers. each {
101
102
1 * httpRequest. addHeader(it. key, it. value[0 ])
102
103
}
103
- 1 * httpRequest. addHeader(' Content-Type' , ' application/json ' )
104
+ 1 * httpRequest. addHeader(' Content-Type' , ' text/plain; charset=ISO-8859-1 ' )
104
105
105
106
0 * httpRequest. _
106
107
}
107
108
108
- def ' setting up headers does not add an JSON content type if there is no body' () {
109
+ def ' setting up headers does not add an TEXT content type if there is no body' () {
109
110
given :
110
111
def headers = [
111
112
A : [' a' ],
@@ -122,12 +123,12 @@ class ProviderClientSpec extends Specification {
122
123
headers. each {
123
124
1 * httpRequest. addHeader(it. key, it. value[0 ])
124
125
}
125
- 0 * httpRequest. addHeader(' Content-Type' , ' application/json ' )
126
+ 0 * httpRequest. addHeader(' Content-Type' , ' text/plain ' )
126
127
127
128
0 * httpRequest. _
128
129
}
129
130
130
- def ' setting up headers does not add an JSON content type if there is already one' () {
131
+ def ' setting up headers does not add an TEXT content type if there is already one' () {
131
132
given :
132
133
def headers = [
133
134
A : [' a' ],
@@ -144,7 +145,7 @@ class ProviderClientSpec extends Specification {
144
145
headers. each {
145
146
1 * httpRequest. addHeader(it. key, it. value[0 ])
146
147
}
147
- 0 * httpRequest. addHeader(' Content-Type' , ' application/json ' )
148
+ 0 * httpRequest. addHeader(' Content-Type' , ' text/plain ' )
148
149
149
150
0 * httpRequest. _
150
151
}
@@ -626,4 +627,22 @@ class ProviderClientSpec extends Specification {
626
627
]
627
628
}
628
629
630
+ @Issue (' #1013' )
631
+ def ' If no content type header is present, defaults to text/plain' () {
632
+ given :
633
+ StatusLine statusLine = new BasicStatusLine (new ProtocolVersion (' http' , 1 , 1 ), 200 , ' OK' )
634
+ Header [] headers = [] as Header []
635
+ HttpResponse response = Mock (HttpResponse ) {
636
+ getStatusLine() >> statusLine
637
+ getAllHeaders() >> headers
638
+ getEntity() >> new StringEntity (' HELLO' , null as ContentType )
639
+ }
640
+
641
+ when :
642
+ def result = client. handleResponse(response)
643
+
644
+ then :
645
+ result. contentType. toString() == ' text/plain; charset=ISO-8859-1'
646
+ }
647
+
629
648
}
0 commit comments