File tree 5 files changed +18
-41
lines changed
5 files changed +18
-41
lines changed Original file line number Diff line number Diff line change 3
3
*/
4
4
'use strict' ;
5
5
6
+ const contentType = require ( 'content-type' ) ;
7
+
6
8
const {
7
9
parseLinkHeader,
8
- buildHeaders,
9
- parseContentTypeHeader
10
+ buildHeaders
10
11
} = require ( '../util' ) ;
11
12
const { LINK_HEADER_CONTEXT } = require ( '../constants' ) ;
12
13
const JsonLdError = require ( '../JsonLdError' ) ;
@@ -88,14 +89,14 @@ module.exports = ({
88
89
}
89
90
90
91
const { res, body} = result ;
91
- const { contentType , params } = parseContentTypeHeader ( res . headers [ 'content-type' ] ) ;
92
+ const { type , parameters } = contentType . parse ( res ) ;
92
93
93
94
doc = {
94
95
contextUrl : null ,
95
96
documentUrl : url ,
96
97
document : body || null ,
97
- contentType : contentType ,
98
- profile : params . profile
98
+ contentType : type ,
99
+ profile : parameters . profile
99
100
} ;
100
101
101
102
// separate profile from content-type
Original file line number Diff line number Diff line change 3
3
*/
4
4
'use strict' ;
5
5
6
+ const contentType = require ( 'content-type' ) ;
7
+
6
8
const {
7
9
parseLinkHeader,
8
- buildHeaders,
9
- parseContentTypeHeader
10
+ buildHeaders
10
11
} = require ( '../util' ) ;
11
12
const { LINK_HEADER_CONTEXT } = require ( '../constants' ) ;
12
13
const JsonLdError = require ( '../JsonLdError' ) ;
@@ -75,15 +76,14 @@ module.exports = ({
75
76
} ) ;
76
77
}
77
78
78
- const { contentType, params} =
79
- parseContentTypeHeader ( req . getResponseHeader ( 'Content-Type' ) ) ;
79
+ const { type, parameters} = contentType . parse ( req ) ;
80
80
81
81
let doc = {
82
82
contextUrl : null ,
83
83
documentUrl : url ,
84
84
document : req . response ,
85
- contentType : contentType ,
86
- profile : params . profile
85
+ contentType : type ,
86
+ profile : parameters . profile
87
87
} ;
88
88
let alternate = null ;
89
89
Original file line number Diff line number Diff line change 34
34
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
35
*/
36
36
const canonize = require ( 'rdf-canonize' ) ;
37
+ const contentType = require ( 'content-type' ) ;
37
38
const util = require ( './util' ) ;
38
39
const ContextResolver = require ( './ContextResolver' ) ;
39
40
const IdentifierIssuer = util . IdentifierIssuer ;
@@ -908,6 +909,10 @@ jsonld.get = async function(url, options) {
908
909
for ( let i = 0 ; i < scripts . length ; i ++ ) {
909
910
const script = scripts [ i ] ;
910
911
// only application/ld+json
912
+ const { type, parameters} = contentType . parse ( script . getAttribute ( 'type' ) ) ;
913
+ if ( type !== 'application/ld+json' ) {
914
+ continue ;
915
+ }
911
916
if ( ! script . getAttribute ( 'type' ) . startsWith ( 'application/ld+json' ) ) {
912
917
continue ;
913
918
}
Original file line number Diff line number Diff line change @@ -143,36 +143,6 @@ api.parseLinkHeader = header => {
143
143
return rval ;
144
144
} ;
145
145
146
- /**
147
- * Parses a content-type header.
148
- * The results will be key'd by the value of "rel".
149
- *
150
- * Accept: application/ld+json
151
- *
152
- * Parses as: ["application/ld+json", {}]
153
- *
154
- * Accept: application/ld+json;profile=http://www.w3.org/ns/json-ld#context
155
- *
156
- * Parses as: ["application/ld+json",
157
- * {profile: "http://www.w3.org/ns/json-ld#context"}]
158
- *
159
- * If there is more than one
160
- *
161
- * @param header the content-type header to parse.
162
- */
163
- api . parseContentTypeHeader = header => {
164
- const [ type , ...rest ] = header . split ( ';' ) ;
165
- const params = { } ;
166
- const rval = [ type . trim ( ) , params ] ;
167
-
168
- // assign parameters
169
- for ( const paramString of rest ) {
170
- const [ param , value ] = paramString . split ( '=' ) ;
171
- params [ param . trim ( ) . toLowerCase ( ) ] = value . trim ( ) ;
172
- }
173
- return rval ;
174
- } ;
175
-
176
146
/**
177
147
* Throws an exception if the given value is not a valid @type value.
178
148
*
Original file line number Diff line number Diff line change 31
31
],
32
32
"dependencies" : {
33
33
"canonicalize" : " ^1.0.1" ,
34
+ "content-type" : " ^1.0.4" ,
34
35
"lru-cache" : " ^5.1.1" ,
35
36
"object.fromentries" : " ^2.0.2" ,
36
37
"rdf-canonize" : " ^1.0.2" ,
You can’t perform that action at this time.
0 commit comments