File tree Expand file tree Collapse file tree 5 files changed +18
-41
lines changed Expand file tree Collapse file tree 5 files changed +18
-41
lines changed Original file line number Diff line number Diff line change 33 */
44'use strict' ;
55
6+ const contentType = require ( 'content-type' ) ;
7+
68const {
79 parseLinkHeader,
8- buildHeaders,
9- parseContentTypeHeader
10+ buildHeaders
1011} = require ( '../util' ) ;
1112const { LINK_HEADER_CONTEXT } = require ( '../constants' ) ;
1213const JsonLdError = require ( '../JsonLdError' ) ;
@@ -88,14 +89,14 @@ module.exports = ({
8889 }
8990
9091 const { res, body} = result ;
91- const { contentType , params } = parseContentTypeHeader ( res . headers [ 'content-type' ] ) ;
92+ const { type , parameters } = contentType . parse ( res ) ;
9293
9394 doc = {
9495 contextUrl : null ,
9596 documentUrl : url ,
9697 document : body || null ,
97- contentType : contentType ,
98- profile : params . profile
98+ contentType : type ,
99+ profile : parameters . profile
99100 } ;
100101
101102 // separate profile from content-type
Original file line number Diff line number Diff line change 33 */
44'use strict' ;
55
6+ const contentType = require ( 'content-type' ) ;
7+
68const {
79 parseLinkHeader,
8- buildHeaders,
9- parseContentTypeHeader
10+ buildHeaders
1011} = require ( '../util' ) ;
1112const { LINK_HEADER_CONTEXT } = require ( '../constants' ) ;
1213const JsonLdError = require ( '../JsonLdError' ) ;
@@ -75,15 +76,14 @@ module.exports = ({
7576 } ) ;
7677 }
7778
78- const { contentType, params} =
79- parseContentTypeHeader ( req . getResponseHeader ( 'Content-Type' ) ) ;
79+ const { type, parameters} = contentType . parse ( req ) ;
8080
8181 const doc = {
8282 contextUrl : null ,
8383 documentUrl : url ,
8484 document : req . response ,
85- contentType : contentType ,
86- profile : params . profile
85+ contentType : type ,
86+ profile : parameters . profile
8787 } ;
8888 let alternate = null ;
8989
Original file line number Diff line number Diff line change 3434 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3535 */
3636const canonize = require ( 'rdf-canonize' ) ;
37+ const contentType = require ( 'content-type' ) ;
3738const util = require ( './util' ) ;
3839const ContextResolver = require ( './ContextResolver' ) ;
3940const IdentifierIssuer = util . IdentifierIssuer ;
@@ -900,6 +901,10 @@ jsonld.get = async function(url, options) {
900901 for ( let i = 0 ; i < scripts . length ; i ++ ) {
901902 const script = scripts [ i ] ;
902903 // only application/ld+json
904+ const { type, parameters} = contentType . parse ( script . getAttribute ( 'type' ) ) ;
905+ if ( type !== 'application/ld+json' ) {
906+ continue ;
907+ }
903908 if ( ! script . getAttribute ( 'type' ) . startsWith ( 'application/ld+json' ) ) {
904909 continue ;
905910 }
Original file line number Diff line number Diff line change @@ -143,36 +143,6 @@ api.parseLinkHeader = header => {
143143 return rval ;
144144} ;
145145
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-
176146/**
177147 * Throws an exception if the given value is not a valid @type value.
178148 *
Original file line number Diff line number Diff line change 3131 ],
3232 "dependencies" : {
3333 "canonicalize" : " ^1.0.1" ,
34+ "content-type" : " ^1.0.4" ,
3435 "lru-cache" : " ^5.1.1" ,
3536 "rdf-canonize" : " ^1.0.2" ,
3637 "request" : " ^2.88.0" ,
You can’t perform that action at this time.
0 commit comments