Skip to content

Commit 2829c99

Browse files
Merge pull request #68 from garethsb/replace-deprecated-request
Replace deprecated request with native fetch
2 parents 6c8f120 + 3f1e05c commit 2829c99

3 files changed

Lines changed: 17 additions & 425 deletions

File tree

index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
limitations under the License.
1414
*/
1515

16-
const request = require('request-promise-native');
1716
const fs = require('fs');
1817
const util = require('util');
1918
const readFile = util.promisify(fs.readFile);
@@ -23,17 +22,19 @@ const { allSections : checkST2110 } = require('./checkST2110.js');
2322

2423
const getSDP = (path) => {
2524
return (path.startsWith('http')) ?
26-
request({
27-
url: path,
28-
resolveWithFullResponse: true
29-
}).then(res => {
30-
if (!res.headers['content-type'].startsWith('application/sdp')) {
25+
fetch(path).then(res => {
26+
if (!res.ok) {
3127
return Promise.reject(new Error(
32-
`Media type (MIME type/Content-Type) of SDP file is '${res.headers['content-type']}' and not signalled as 'applicatio/sdp' as required in RFC 4566 Section 5.`));
28+
`SDP file request resulted in non-OK response code of ${res.status}.`));
29+
}
30+
const contentType = res.headers.get('content-type');
31+
if (!contentType || !contentType.startsWith('application/sdp')) {
32+
return Promise.reject(new Error(
33+
`Media type (MIME type/Content-Type) of SDP file is '${contentType}' and not signalled as 'application/sdp' as required in RFC 4566 Section 5.`));
3334
} else {
34-
return Promise.resolve(res.body);
35+
return res.text();
3536
}
36-
}, e => Promise.reject(e)) :
37+
}) :
3738
readFile(path, 'utf8');
3839
};
3940

0 commit comments

Comments
 (0)