File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ export class RestTemplate implements RestOperations {
102
102
103
103
private async handleData < D > ( response : Response ) : Promise < [ D , Response ] > {
104
104
const contentTypeHeader = response . headers . get ( 'content-type' ) ;
105
- const contentType = contentTypeHeader ?. split ( ';' ) [ 0 ] ?? undefined ;
105
+ const contentType = this . resolvePrimaryContentType ( contentTypeHeader ) ;
106
106
107
107
if ( ! contentType ) {
108
108
return Promise . resolve ( [ null , response ] ) ;
@@ -128,4 +128,13 @@ export class RestTemplate implements RestOperations {
128
128
}
129
129
}
130
130
131
+ private resolvePrimaryContentType ( value : string ) {
132
+ let result : string | undefined = undefined ;
133
+ const firstPart = value ?. split ( ';' ) [ 0 ] ?? undefined ;
134
+ if ( firstPart ) {
135
+ result = firstPart . split ( ',' ) [ 0 ] ;
136
+ }
137
+ return result ;
138
+ }
139
+
131
140
}
Original file line number Diff line number Diff line change @@ -41,4 +41,28 @@ describe("passport control", () => {
41
41
expect ( result ) . toEqual ( 'error' ) ;
42
42
} ) ;
43
43
44
+ it ( "should contenttype header issues correctly" , async ( ) => {
45
+ // Arrange
46
+ template . errorHandler = {
47
+ hasError : ( ) => false ,
48
+ handleError : ( ) => { throw Error ( '' ) }
49
+ }
50
+ fetchMock . mockIf ( 'http://localhost/test' , req => {
51
+ return Promise . resolve ( {
52
+ status : 200 ,
53
+ body : JSON . stringify ( { id : '123' } ) ,
54
+ headers : {
55
+ 'content-type' : 'application/json; application/xml' ,
56
+ 'Content-Type' : 'application/json'
57
+ }
58
+ } ) ;
59
+ } ) ;
60
+
61
+ // Act
62
+ const result = await template . getForObject ( 'http://localhost/test' ) as any ;
63
+
64
+ // Assert
65
+ expect ( result . id ) . toEqual ( '123' ) ;
66
+ } ) ;
67
+
44
68
} ) ;
You can’t perform that action at this time.
0 commit comments