UNPKG

ketting

Version:

Opiniated HATEAOS / Rest client.

67 lines 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.entityHeaderNames = void 0; exports.parseContentType = parseContentType; exports.parseLink = parseLink; exports.isSafeMethod = isSafeMethod; 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(); } 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; } const safeMethods = ['GET', 'HEAD', 'OPTIONS', 'PRI', 'PROPFIND', 'REPORT', 'SEARCH', 'TRACE']; function isSafeMethod(method) { return safeMethods.includes(method); } /** * Older HTTP versions calls these 'entity headers'. * * Never HTTP/1.1 specs calls some of these 'representation headers'. * * What they have in common is that these headers can exist on request and * response and say something *about* the content. */ exports.entityHeaderNames = [ 'Content-Type', 'Content-Language', 'Content-Location', 'Deprecation', 'ETag', 'Expires', 'Last-Modified', 'Sunset', 'Title', 'Warning', ]; //# sourceMappingURL=util.js.map