1
1
/*!
2
2
* mime-db
3
3
* Copyright(c) 2014 Jonathan Ong
4
- * Copyright(c) 2015-2022 Douglas Christopher Wilson
4
+ * Copyright(c) 2015-2023 Douglas Christopher Wilson
5
5
* MIT Licensed
6
6
*/
7
7
10
10
*/
11
11
12
12
var co = require ( 'co' )
13
- var getRawBody = require ( 'raw-body' )
14
- var cogent = require ( 'cogent' )
13
+ var got = require ( 'got' )
15
14
var parser = require ( 'csv-parse' )
16
15
var toArray = require ( 'stream-to-array' )
17
16
var typer = require ( 'media-typer' )
@@ -109,14 +108,14 @@ function addTemplateData (data, options) {
109
108
}
110
109
111
110
return function * get ( ) {
112
- var res = yield * cogent ( 'https://www.iana.org/assignments/media-types/' + data . template , { retries : 3 } )
111
+ var res = yield got ( 'https://www.iana.org/assignments/media-types/' + data . template )
113
112
var ref = data . type + '/' + data . name
114
113
var rfc = getRfcReferences ( data . reference ) [ 0 ]
115
114
116
115
if ( res . statusCode === 404 && data . template !== ref ) {
117
116
console . log ( 'template ' + data . template + ' not found, retry as ' + ref )
118
117
data . template = ref
119
- res = yield * cogent ( 'https://www.iana.org/assignments/media-types/' + ref , { retries : 3 } )
118
+ res = yield got ( 'https://www.iana.org/assignments/media-types/' + ref )
120
119
121
120
// replace the guessed mime
122
121
if ( res . statusCode === 200 ) {
@@ -126,7 +125,7 @@ function addTemplateData (data, options) {
126
125
127
126
if ( res . statusCode === 404 && rfc !== undefined ) {
128
127
console . log ( 'template ' + data . template + ' not found, fetch ' + rfc )
129
- res = yield * cogent ( 'https://tools.ietf.org/rfc/' + rfc . toLowerCase ( ) + '.txt' )
128
+ res = yield got ( 'https://tools.ietf.org/rfc/' + rfc . toLowerCase ( ) + '.txt' )
130
129
}
131
130
132
131
if ( res . statusCode === 404 ) {
@@ -138,12 +137,11 @@ function addTemplateData (data, options) {
138
137
throw new Error ( 'got status code ' + res . statusCode + ' from template ' + data . template )
139
138
}
140
139
141
- var body = yield getTemplateBody ( res )
142
- var href = res . urls [ 0 ] . href
140
+ var body = getTemplateBody ( res . body )
143
141
var mime = extractTemplateMime ( body )
144
142
145
143
// add the template as a source
146
- addSource ( data , href )
144
+ addSource ( data , res . url )
147
145
148
146
if ( mimeEql ( mime , data . mime ) ) {
149
147
// use extracted mime
@@ -232,13 +230,13 @@ function extractTemplateExtensions (body) {
232
230
}
233
231
234
232
function * get ( type , options ) {
235
- var res = yield * cogent ( 'https://www.iana.org/assignments/media-types/' + encodeURIComponent ( type ) + '.csv' , { retries : 3 } )
233
+ var res = yield got ( 'https://www.iana.org/assignments/media-types/' + encodeURIComponent ( type ) + '.csv' )
236
234
237
235
if ( res . statusCode !== 200 ) {
238
236
throw new Error ( 'got status code ' + res . statusCode + ' from ' + type )
239
237
}
240
238
241
- var mimes = yield toArray ( res . pipe ( parser ( ) ) )
239
+ var mimes = yield toArray ( parser ( res . body ) )
242
240
var headers = mimes . shift ( ) . map ( normalizeHeader )
243
241
var reduceRows = generateRowMapper ( headers )
244
242
var templates = Object . create ( null )
@@ -276,8 +274,7 @@ function * get (type, options) {
276
274
} )
277
275
}
278
276
279
- function * getTemplateBody ( res ) {
280
- var body = yield getRawBody ( res , { encoding : 'ascii' } )
277
+ function getTemplateBody ( body ) {
281
278
var lines = body . split ( / \r ? \n / )
282
279
var slurp = false
283
280
0 commit comments