UNPKG

ketting

Version:

Opiniated HATEAOS / Rest client.

47 lines 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isSafeMethod = exports.parseLink = exports.parseContentType = void 0; const LinkHeader = require("http-link-header"); const link_1 = require("../link"); /** * Takes a Content-Type header, and only returns the mime-type part. */ function parseContentType(contentType) { if (!contentType) { return null; } if (contentType.includes(';')) { contentType = contentType.split(';')[0]; } return contentType.trim(); } exports.parseContentType = parseContentType; function parseLink(context, header) { const result = new link_1.Links(context); if (!header) { return result; } for (const httpLink of LinkHeader.parse(header).refs) { // Looping through individual links for (const rel of httpLink.rel.split(' ')) { // Looping through space separated rel values. const link = { rel: rel, href: httpLink.uri, context, title: httpLink.title, hreflang: httpLink.hreflang, type: httpLink.type, }; result.add(link); } } return result; } exports.parseLink = parseLink; const safeMethods = ['GET', 'HEAD', 'OPTIONS', 'PRI', 'PROPFIND', 'REPORT', 'SEARCH', 'TRACE']; function isSafeMethod(method) { return safeMethods.includes(method); } exports.isSafeMethod = isSafeMethod; //# sourceMappingURL=util.js.map