From e50e9f8a94085a3743f6be49b6efbda98b1d12a6 Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Mon, 21 Mar 2022 07:34:01 +0000 Subject: [PATCH] Flaska: Add basic head support --- flaska.mjs | 3 +++ test/flaska.api.test.mjs | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/flaska.mjs b/flaska.mjs index 732d9a2..29b2fe5 100644 --- a/flaska.mjs +++ b/flaska.mjs @@ -487,6 +487,9 @@ export class Flaska { 'OPTIONS': new FlaskaRouter(), 'PATCH': new FlaskaRouter(), } + // HEAD and GET should be identical + this.routers['HEAD'] = this.routers['GET'] + this.get = this.routers.GET.addRoute.bind(this.routers.GET) this.post = this.routers.POST.addRoute.bind(this.routers.POST) this.put = this.routers.PUT.addRoute.bind(this.routers.PUT) diff --git a/test/flaska.api.test.mjs b/test/flaska.api.test.mjs index 747dae2..9823da9 100644 --- a/test/flaska.api.test.mjs +++ b/test/flaska.api.test.mjs @@ -25,6 +25,15 @@ t.test('it should have all the common verbs', function() { assert.strictEqual(typeof(flaska.patch), 'function') }) +t.test('the verbs GET and HEAD should be identical', function() { + let flaska = new Flaska({}, faker) + assert.ok(flaska.get) + assert.strictEqual(typeof(flaska.get), 'function') + assert.notOk(flaska.head) + assert.ok(flaska.routers['HEAD']) + assert.strictEqual(flaska.routers['GET'], flaska.routers['HEAD']) +}) + t.describe('#log', function() { t.test('default have a logger valid', function() { let flaska = new Flaska({}, faker)