profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/Ethan-Arrowood/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.
Ethan Arrowood Ethan-Arrowood @Microsoft ethanarrowood.com 👻 Node.js, Fastify, Undici, TypeScript he/him

beaucarnes/freeCodeCamp 1

The https://freeCodeCamp.com open source codebase and curriculum. Learn to code and help nonprofits.

bonham000/FreeCodeCamp 1

The https://FreeCodeCamp.com open source codebase and curriculum. Learn to code and help nonprofits.

Ethan-Arrowood/applying-advanced-typescript-definition-patterns 1

Code repo for my talk "Applying Advanced TypeScript Definition Patterns"

BboyAkers/pino-application-insights 0

fastify plugin: pino application insights

Ethan-Arrowood/100-days-of-code 0

Fork this template for the 100 days journal - to keep yourself accountable

Ethan-Arrowood/15puzzle 0

Old 15 puzzle game I made using jQuery

Ethan-Arrowood/25-days-of-serverless 0

Repository responsible for 25 days of Serverless challenges

release fastify/fastify-cli

v2.11.0

released time in 31 minutes

issue commentnodejs/undici

Mocks should match headers

I'll get a PR sorted for this this weekend :)

mcollina

comment created time in an hour

issue commentfastify/help

setErrorHandler question

You can check the err.validation and a err.validationContext property.

diwic

comment created time in an hour

issue commentnodejs/undici

Mocks should match headers

@ronag this must be fixed before the v4 release.

mcollina

comment created time in an hour

issue commentnodejs/undici

Mocks should match headers

cc @jonnydgreen

mcollina

comment created time in an hour

issue openednodejs/undici

Mocks should match headers

Currently we do not match the headers when doing intercepts:

mockPool.intercept({
  path: '/foo',
  method: 'GET',
  headers: {
     'User-Agent': 'undici' // requests with different or missing user agent would not be matched.
  }
}).reply(200, 'foo')

I would only consider an header as a requirement if included. So passing (or not passing) an Accept header would not make a difference for this interceptor.

created time in an hour

push eventnodejs/undici

Jonny Green

commit sha 3b98c86c7a31c29c56d6c5a31d95875d58f1ac85

Improve mock errors (#790) * Improve mock not matching errors * Improve mock errors further by indicating path,method or body as the problem * Add better error handling in buildMockDispatch and correct typos

view details

push time in an hour

PR merged nodejs/undici

Improve mock errors

Fixes: https://github.com/nodejs/undici/issues/787

As suggested, I've added the following improvements to help debug when a mock dispatch is not matched

For a missing path:

Mock dispatch not matched for path '/wrong': subsequent request to origin http://localhost:9999 was not allowed (net.connect is not enabled for this origin)
Mock dispatch not matched for path '/wrong': subsequent request to origin http://localhost:9999 was not allowed (net.connect is disabled)

For a missing method:

Mock dispatch not matched for method 'WRONG': subsequent request to origin http://localhost:9999 was not allowed (net.connect is not enabled for this origin)
Mock dispatch not matched for method 'WRONG': subsequent request to origin http://localhost:9999 was not allowed (net.connect is disabled)

For a missing body:

Mock dispatch not matched for body 'wrong': subsequent request to origin http://localhost:9999 was not allowed (net.connect is not enabled for this origin)
Mock dispatch not matched for body 'wrong': subsequent request to origin http://localhost:9999 was not allowed (net.connect is disabled)

I've also exposed the mockErrors as a separate object to errors so they are not confused, happy to refactor if you would prefer them to be all together :)

+311 -36

3 comments

14 changed files

jonnydgreen

pr closed time in an hour

issue closednodejs/undici

Not matching mocks are hard to debug

Bug Description

When a mock does not match (and net.connect is disabled), we error with a generic:

Unable to find mock dispatch and real dispatches are disabled for XYZ

However, we are likely setting up a mock for this URL - so there might be something that is not matching.

We should provide better error messages.

closed time in an hour

mcollina

pull request commentnodejs/undici

Improve mock errors

That's perfect thanks.

jonnydgreen

comment created time in an hour

release fastify/fastify-cors

v6.0.1

released time in an hour

release fastify/fastify-basic-auth

v1.1.0

released time in an hour

push eventfastify/fastify

Mohamed Edrah

commit sha 64e6d970a982a5e55186dee41965acd1b943799c

Fix Content-Length not being updated after onSend hook (#3058)

view details

push time in 2 hours

PR merged fastify/fastify

Fix Content-Length not being updated after onSend hook

<!-- Thank you for your pull request. Please provide a description above and review the requirements below.

Bug fixes and new features should include tests and possibly benchmarks.

Contributors guide: https://github.com/fastify/fastify/blob/master/CONTRIBUTING.md

By making a contribution to this project, I certify that:

  • (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or

  • (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or

  • (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.

  • (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. -->

Checklist

This PR fixes #3057, onSendEnd will now set Content-length header to the length of the payload if they're not already equal and if the http method isn't HEAD.

+26 -0

0 comment

2 changed files

MSE99

pr closed time in 2 hours

issue closedfastify/fastify

After changing payload in onSend hook, Content-Length is not updated

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] I have searched existing issues to ensure it has not already been reported

Fastify version

3.15.1

Node.js version

14.16.1

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

20.04

Description

I'm minifying payloads in onSend. Without explicitly setting Content-Length, the old Content-Length of the unmodified payload is sent. Probably the other relevant detail is that the payloads are generated by fastify-static and they use streams, so I'm draining the stream into a string which I then modify.

Steps to Reproduce

Here's the entire plugin:

'use strict';

import fastifyPlugin from 'fastify-plugin';
import {FastifyPluginAsync} from 'fastify';
import htmlMinifier from 'html-minifier';
import {PassThrough} from 'readable-stream';

const streamToString = (stream: any): Promise<string> => {
  const chunks: Buffer[] = [];
  return new Promise((resolve, reject) => {
    stream.on('data', (chunk: any) => chunks.push(Buffer.from(chunk)));
    stream.on('error', (err: Error) => reject(err));
    stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
  });
};

const minify = (s: string) =>
  htmlMinifier.minify(s, {
    collapseBooleanAttributes: true,
    collapseWhitespace: true,
    minifyCSS: true,
    minifyJS: true,
    removeComments: true,
    removeEmptyAttributes: true,
    removeRedundantAttributes: true,
    removeScriptTypeAttributes: true,
    removeStyleLinkTypeAttributes: true,
    useShortDoctype: true,
  });

const plugin: FastifyPluginAsync = async (app, _options) => {
  app.addHook('onSend', async (_request, reply, payload) => {
    const contentType = reply.getHeader('Content-Type');
    if (contentType && contentType.includes('text/html')) {
      if (payload instanceof PassThrough) {
        const content = minify(await streamToString(payload));
        //reply.header('Content-Length', content.length);
        return content;
      }
    }
  });
};

export default fastifyPlugin(plugin);

Expected Behavior

Content-Length should be set based on the new payload.

closed time in 2 hours

btmorex

pull request commentnodejs/undici

Improve mock errors

Thanks! Just to clarify, when you say check/assertions on Headers as well, do you mean match on mock dispatch headers? For example:

mockPool.intercept({
  path: '/foo',
  method: 'GET',
  headers: ['hello', 'there'] // Only a request for this origin,path,method,headers will be intercepted
}).reply(200, 'foo')

If so, I can do that in a separate PR over the weekend if that works for you? :)

jonnydgreen

comment created time in 2 hours

delete branch Ethan-Arrowood/fastify

delete branch : dependabot/npm_and_yarn/tap-15.0.6

delete time in 3 hours

PR closed Ethan-Arrowood/fastify

build(deps-dev): bump tap from 14.11.0 to 15.0.6 dependencies javascript

Bumps tap from 14.11.0 to 15.0.6. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/tapjs/node-tap/releases">tap's releases</a>.</em></p> <blockquote> <h2>v15.0.0</h2> <h2>15.0 - 2021-03-30</h2> <p>This is a major refactor of much of tap's internals, and a lot of new features.</p> <h3>BREAKING CHANGES</h3> <ul> <li>Drop the use of the <code>@std/esm</code> module, in favor of native ES Modules.</li> <li>Drop the inclusion of <code>typescript</code> by default. (Typescript still supported, but requires that you install it yourself.)</li> <li><code>.jsx</code> files only run automatically when <code>--jsx</code> config is explicitly enabled.</li> <li><code>--check-coverage</code> on by default.</li> <li>Drop support for node <code><10</code>.</li> <li>Separate <code>t.has</code> from <code>t.match</code>, so these are distinct.</li> <li>Deprecate aliases.</li> <li>Do not report on test points filtered with <code>only</code> or <code>grep</code> options.</li> <li>Resolve <code>t.test()</code> promise to the child test results, rather than the parent test.</li> <li>Remove <code>callback</code> argument from <code>t.beforeEach</code> and <code>t.afterEach</code>. Return a promise if you wish these methods to be async.</li> </ul> <h3>NEW FEATURES and BUG FIXES</h3> <ul> <li>Restructure snapshot output folder, and change file extensions to <code>.cjs</code>.</li> <li>Add <code>t.compareOptions</code> object to pass options to all the methods that use <code>tcompare</code> (ie, <code>t.has</code>, <code>t.match</code>, <code>t.same</code>, etc.)</li> <li>Improved diffing and comparison output for long strings and buffers.</li> <li>Add <code>t.before</code> method.</li> <li>Add <code>t.mock()</code> API for mocking calls to <code>require()</code> in modules being tested.</li> <li>Inherit the <code>t.saveFixture</code> boolean option.</li> <li>Create fixtures symbolic links as junctions if pointing at directories.</li> <li>Set both <code>FORCE_COLOR</code> and <code>NO_COLOR</code> environment variables appropriately.</li> <li>Pull initial <code>TS_NODE_COMPILER_OPTIONS</code> from test environment.</li> <li>Run fixture cleanup aysnchronously on <code>t.teardown()</code> to minimize Windows folder locking issues.</li> <li>Load <code>.taprc.yml</code> and <code>.taprc.yaml</code> config files if present, and no <code>.taprc</code> is present.</li> </ul> <h3>DEPENDENCIES and REFACTORING</h3> <ul> <li>Extract most of the internal functionality to <a href="https://npm.im/libtap"><code>libtap</code></a>.</li> <li>Update <code>nyc</code> to version 15.</li> <li>Conditional exports to limit diving into tap's internals except via supported APIs.</li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/tapjs/node-tap/commit/f7c0781c9819760a9e4cfa95ed77b36a6c12f64e"><code>f7c0781</code></a> 15.0.6</li> <li><a href="https://github.com/tapjs/node-tap/commit/f5b805d1df0479afda8bb46704266dca4867db07"><code>f5b805d</code></a> Remove unused import</li> <li><a href="https://github.com/tapjs/node-tap/commit/071341723373352326dfb0f03c9d65d714fa5ed7"><code>0713417</code></a> update cli doc</li> <li><a href="https://github.com/tapjs/node-tap/commit/475f0522a72aeb221c30c2cd98fcb16556da5839"><code>475f052</code></a> 15.0.5</li> <li><a href="https://github.com/tapjs/node-tap/commit/55d8e713577dc715549527c90d7b71428afe4d2e"><code>55d8e71</code></a> test on node v16</li> <li><a href="https://github.com/tapjs/node-tap/commit/89dc9167bef18bb7f8d5ba88417e203f36072af8"><code>89dc916</code></a> update cli doc</li> <li><a href="https://github.com/tapjs/node-tap/commit/8e405a79be99c54c5da8b92c4e15af0f3a7d358a"><code>8e405a7</code></a> 15.0.4</li> <li><a href="https://github.com/tapjs/node-tap/commit/a73b15843379e3f23613527c6d9b008d6ed50c35"><code>a73b158</code></a> treport@2.0.1</li> <li><a href="https://github.com/tapjs/node-tap/commit/c051fee5d959b7b34f84d8e93db614ebcfe6c55e"><code>c051fee</code></a> update cli doc</li> <li><a href="https://github.com/tapjs/node-tap/commit/bc1374545d9aea3d5dfb1863ce28d98f8678ee29"><code>bc13745</code></a> 15.0.3</li> <li>Additional commits viewable in <a href="https://github.com/tapjs/node-tap/compare/v14.11.0...v15.0.6">compare view</a></li> </ul> </details> <br />

Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


<details> <summary>Dependabot commands and options</summary> <br />

You can trigger Dependabot actions by commenting on this PR:

  • @dependabot rebase will rebase this PR
  • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
  • @dependabot merge will merge this PR after your CI passes on it
  • @dependabot squash and merge will squash and merge this PR after your CI passes on it
  • @dependabot cancel merge will cancel a previously requested merge and block automerging
  • @dependabot reopen will reopen this PR if it is closed
  • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
  • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

</details>

+1 -1

1 comment

1 changed file

dependabot[bot]

pr closed time in 3 hours

create barnchEthan-Arrowood/fastify

branch : dependabot/npm_and_yarn/tap-15.0.9

created branch time in 3 hours

pull request commentEthan-Arrowood/fastify

build(deps-dev): bump tap from 14.11.0 to 15.0.6

Superseded by #13.

dependabot[bot]

comment created time in 3 hours

PR opened Ethan-Arrowood/fastify

build(deps-dev): bump tap from 14.11.0 to 15.0.9

Bumps tap from 14.11.0 to 15.0.9. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/tapjs/node-tap/releases">tap's releases</a>.</em></p> <blockquote> <h2>v15.0.0</h2> <h2>15.0 - 2021-03-30</h2> <p>This is a major refactor of much of tap's internals, and a lot of new features.</p> <h3>BREAKING CHANGES</h3> <ul> <li>Drop the use of the <code>@std/esm</code> module, in favor of native ES Modules.</li> <li>Drop the inclusion of <code>typescript</code> by default. (Typescript still supported, but requires that you install it yourself.)</li> <li><code>.jsx</code> files only run automatically when <code>--jsx</code> config is explicitly enabled.</li> <li><code>--check-coverage</code> on by default.</li> <li>Drop support for node <code><10</code>.</li> <li>Separate <code>t.has</code> from <code>t.match</code>, so these are distinct.</li> <li>Deprecate aliases.</li> <li>Do not report on test points filtered with <code>only</code> or <code>grep</code> options.</li> <li>Resolve <code>t.test()</code> promise to the child test results, rather than the parent test.</li> <li>Remove <code>callback</code> argument from <code>t.beforeEach</code> and <code>t.afterEach</code>. Return a promise if you wish these methods to be async.</li> </ul> <h3>NEW FEATURES and BUG FIXES</h3> <ul> <li>Restructure snapshot output folder, and change file extensions to <code>.cjs</code>.</li> <li>Add <code>t.compareOptions</code> object to pass options to all the methods that use <code>tcompare</code> (ie, <code>t.has</code>, <code>t.match</code>, <code>t.same</code>, etc.)</li> <li>Improved diffing and comparison output for long strings and buffers.</li> <li>Add <code>t.before</code> method.</li> <li>Add <code>t.mock()</code> API for mocking calls to <code>require()</code> in modules being tested.</li> <li>Inherit the <code>t.saveFixture</code> boolean option.</li> <li>Create fixtures symbolic links as junctions if pointing at directories.</li> <li>Set both <code>FORCE_COLOR</code> and <code>NO_COLOR</code> environment variables appropriately.</li> <li>Pull initial <code>TS_NODE_COMPILER_OPTIONS</code> from test environment.</li> <li>Run fixture cleanup aysnchronously on <code>t.teardown()</code> to minimize Windows folder locking issues.</li> <li>Load <code>.taprc.yml</code> and <code>.taprc.yaml</code> config files if present, and no <code>.taprc</code> is present.</li> </ul> <h3>DEPENDENCIES and REFACTORING</h3> <ul> <li>Extract most of the internal functionality to <a href="https://npm.im/libtap"><code>libtap</code></a>.</li> <li>Update <code>nyc</code> to version 15.</li> <li>Conditional exports to limit diving into tap's internals except via supported APIs.</li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/tapjs/node-tap/commit/4dbac3861ced7a12a3c61b3df259ce1d8a1e87a9"><code>4dbac38</code></a> 15.0.9</li> <li><a href="https://github.com/tapjs/node-tap/commit/fbc770a7bf122da60ad60103d852cbf2904dd7e8"><code>fbc770a</code></a> update tcompare</li> <li><a href="https://github.com/tapjs/node-tap/commit/0adf0d7f312229ecb66720ad329cdb563b649ddc"><code>0adf0d7</code></a> update cli doc</li> <li><a href="https://github.com/tapjs/node-tap/commit/0906b78a2aa292c5bf3d9165c097cbb243fca86b"><code>0906b78</code></a> 15.0.8</li> <li><a href="https://github.com/tapjs/node-tap/commit/296b423c34d949d05ba0d8152275425d4f2caef1"><code>296b423</code></a> treport 2.0.2</li> <li><a href="https://github.com/tapjs/node-tap/commit/b4fe5a814edef7dffddb3d261e6e5a0faea542b1"><code>b4fe5a8</code></a> update cli doc</li> <li><a href="https://github.com/tapjs/node-tap/commit/79af49d8c88f93ece879b27cb51ffa2abd3308e6"><code>79af49d</code></a> 15.0.7</li> <li><a href="https://github.com/tapjs/node-tap/commit/26a71b9c9e1c3ce014682f719b83f594b59f3b16"><code>26a71b9</code></a> update tcompare and all deps</li> <li><a href="https://github.com/tapjs/node-tap/commit/5d612c7685f37ad4623858d493ada424fcdd32c4"><code>5d612c7</code></a> Fix for <a href="https://github-redirect.dependabot.com/tapjs/node-tap/issues/740">#740</a></li> <li><a href="https://github.com/tapjs/node-tap/commit/60e2c67b2b9534d1423b03660fc3ab7954e9f4b6"><code>60e2c67</code></a> update cli doc</li> <li>Additional commits viewable in <a href="https://github.com/tapjs/node-tap/compare/v14.11.0...v15.0.9">compare view</a></li> </ul> </details> <br />

Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


<details> <summary>Dependabot commands and options</summary> <br />

You can trigger Dependabot actions by commenting on this PR:

  • @dependabot rebase will rebase this PR
  • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
  • @dependabot merge will merge this PR after your CI passes on it
  • @dependabot squash and merge will squash and merge this PR after your CI passes on it
  • @dependabot cancel merge will cancel a previously requested merge and block automerging
  • @dependabot reopen will reopen this PR if it is closed
  • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
  • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

</details>

+1 -1

0 comment

1 changed file

pr created time in 3 hours

issue commentfastify/help

JTD with fastify - is it possible?

@zekth Thank you 👍

ahgentil

comment created time in 3 hours

PR opened fastify/fastify

Fix Content-Length not being updated after onSend hook

<!-- Thank you for your pull request. Please provide a description above and review the requirements below.

Bug fixes and new features should include tests and possibly benchmarks.

Contributors guide: https://github.com/fastify/fastify/blob/master/CONTRIBUTING.md

By making a contribution to this project, I certify that:

  • (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or

  • (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or

  • (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.

  • (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. -->

Checklist

This PR fixes #3075, onSendEnd will now set Content-length header to the length of the payload if they're not already equal and if the http method isn't HEAD.

+26 -0

0 comment

2 changed files

pr created time in 4 hours

issue openedfastify/help

setErrorHandler question

💬 How does one integrate error handling?

Hi and thanks for providing a help forum!

I'm new to fastify and I'm trying to understand how setErrorHandler works.

What I'm trying to do is: If the schema validation failed or similar, it's okay to tell the client what went wrong, but if the client managed to cause an internal server error, don't tell the client the details.

Something like:

app.setErrorHandler(function (error, request, reply) {
    const statusCode = ???;
    if (statusCode >= 400 && statusCode <= 500) {
        console.warn(error);
        // The client did something wrong, okay to tell it what it is
        return doFastifysNormalErrorHandling();
    }
    // The error is within the server, don't tell the client what it is
    console.error(error);
    reply.code(statusCode || 500).send("500 Internal server error");
});

## Your Environment

- *node version*: 14
- *fastify version*: >= 3.0.0
- *os*: Mac, Windows, Linux
- *any other relevant information*

created time in 5 hours

MemberEvent

startedSamVerschueren/tsd

started time in 9 hours

MemberEvent
MemberEvent

push eventelectron/electronjs.org-new

Antón Molleda

commit sha 7e776e85beb6c63d063c4c4aed159152c8804ae7

chore: more tests

view details

push time in 11 hours

startedkubernetes-sigs/secrets-store-csi-driver

started time in 11 hours