New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hal-browser

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hal-browser - npm Package Compare versions

Comparing version 0.5.6 to 0.6.0

12

changelog.md

@@ -0,1 +1,13 @@

0.6.0 (2018-10-12)
==================
* It's now possible to get alternative representations in a browser with the
`?_browser-accept` query parameter.
* Links with the `alternate` rel that are local, automatically get the
`?_browser-accept` parameter added, so a single resource can now have
multiple representations on the same url.
* Now using a new package for parsing HTTP Link urls. The old one didn't
support multiple links with the same `rel`.
0.5.6 (2018-10-04)

@@ -2,0 +14,0 @@ ==================

13

dist/components/alternate.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const url_1 = __importDefault(require("url"));
const util_1 = require("../util");

@@ -40,3 +44,10 @@ const types = {

}
alternateHtml.push(`<a href="${util_1.h(link.href)}" rel="${util_1.h(link.rel)}" title="${util_1.h(label)}"${cssClass}>${util_1.h(label)}</a>`);
let href = link.href;
// If the url is relative, we're adding our secret argument to make the Accept header work.
if (href.match(/^\/[^\/]/)) {
const urlObj = url_1.default.parse(href, true);
urlObj.query['_browser-accept'] = link.type;
href = url_1.default.format(urlObj);
}
alternateHtml.push(`<a href="${util_1.h(href)}" rel="${util_1.h(link.rel)}" title="${util_1.h(label)}"${cssClass}>${util_1.h(label)}</a>`);
}

@@ -43,0 +54,0 @@ if (alternateHtml.length) {

19

dist/index.js

@@ -91,2 +91,13 @@ "use strict";

}
// Check to see if the client even wants html.
if (!ctx.accepts('text/html')) {
return next();
}
// If the url contained _browser-accept, we use that value to override the
// Accept header.
let oldAccept;
if ('_browser-accept' in ctx.query) {
oldAccept = ctx.request.headers.get('Accept');
ctx.request.headers.set('Accept', ctx.query['_browser-accept']);
}
// Don't do anything if the raw format was requested

@@ -96,8 +107,8 @@ if ('_browser-raw' in ctx.query) {

}
// Check to see if the client even wants html.
if (!ctx.accepts('text/html')) {
return next();
}
// Doing the inner request
await next();
if (oldAccept) {
// Putting the old value back in place
ctx.request.headers.set('Accept', oldAccept);
}
// We only care about transforming a few content-types

@@ -104,0 +115,0 @@ if (!exports.supportedContentTypes.includes(ctx.response.type)) {

@@ -7,3 +7,3 @@ "use strict";

const highlight_js_1 = __importDefault(require("highlight.js"));
const parse_link_header_1 = __importDefault(require("parse-link-header"));
const http_link_header_1 = __importDefault(require("http-link-header"));
const url_1 = __importDefault(require("url"));

@@ -65,9 +65,9 @@ function h(input) {

if (linkHeader) {
const parsed = parse_link_header_1.default(linkHeader);
for (const [rel, info] of Object.entries(parsed)) {
const parsed = http_link_header_1.default.parse(linkHeader);
for (const link of parsed.refs) {
result.push({
rel: rel,
href: info.url,
title: info.title,
type: info.type
rel: link.rel,
href: link.uri,
title: link.title,
type: link.type
});

@@ -74,0 +74,0 @@ }

{
"name": "hal-browser",
"version": "0.5.6",
"version": "0.6.0",
"description": "A HAL browser middleware",

@@ -40,6 +40,6 @@ "main": "dist/index.js",

"@types/highlight.js": "^9.12.3",
"@types/http-link-header": "^0.6.2",
"@types/markdown-it": "0.0.5",
"@types/mocha": "^5.2.5",
"@types/node": "^10.11.4",
"@types/parse-link-header": "^1.0.0",
"@types/sinon": "^5.0.3",

@@ -64,5 +64,5 @@ "chai": "^4.2.0",

"highlight.js": "^9.12.0",
"markdown-it": "^8.4.2",
"parse-link-header": "^1.0.1"
"http-link-header": "^0.8.0",
"markdown-it": "^8.4.2"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc