Skip to content

Implement isInjected read-only request property to indicate request…#4117

Merged
cjihrig merged 8 commits intohapijs:masterfrom
neenhouse:add-is-injected-prop
Aug 11, 2020
Merged

Implement isInjected read-only request property to indicate request…#4117
cjihrig merged 8 commits intohapijs:masterfrom
neenhouse:add-is-injected-prop

Conversation

@neenhouse
Copy link
Copy Markdown
Contributor

Closes #4116

Implements isInjected read-only request property to indicate request is injected by server.inject()

@neenhouse neenhouse force-pushed the add-is-injected-prop branch from b89f059 to 8686b67 Compare July 21, 2020 18:48
Copy link
Copy Markdown
Contributor

@kanongil kanongil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also use this request.isInjected property here:

const isInjection = Shot.isInjection(request.raw.req);
.

@neenhouse
Copy link
Copy Markdown
Contributor Author

I would also use this request.isInjected property here:

const isInjection = Shot.isInjection(request.raw.req);

.

Implemented.

@neenhouse
Copy link
Copy Markdown
Contributor Author

neenhouse commented Jul 24, 2020

Can you guys take a look / merge #4125 to address the 2 failing unit tests on master? I'll rebase this one when it lands

Nevermind, issue locally was a combination of me being on the VPN, and as @cjhrig explained in the other thread:

Node releases v14.6.0, which introduced new global variables. Previously, lab didn't know about them, so it reported errors. lab has already been updated - travis is just using a cached version.

So build for this PR should be green with a fresh re-build.

const internals = {
events: Podium.validate(['finish', { name: 'peek', spread: true }, 'disconnect']),
reserved: ['server', 'url', 'query', 'path', 'method', 'mime', 'setUrl', 'setMethod', 'headers', 'id', 'app', 'plugins', 'route', 'auth', 'pre', 'preResponses', 'info', 'orig', 'params', 'paramsArray', 'payload', 'state', 'jsonp', 'response', 'raw', 'domain', 'log', 'logs', 'generateResponse']
reserved: ['server', 'url', 'query', 'path', 'method', 'mime', 'setUrl', 'setMethod', 'headers', 'id', 'app', 'plugins', 'route', 'auth', 'pre', 'preResponses', 'info', 'isInjected', 'orig', 'params', 'paramsArray', 'payload', 'state', 'jsonp', 'response', 'raw', 'domain', 'log', 'logs', 'generateResponse']
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could arguably be seen as a breaking change. Maybe this should go into v20 for good measure CC @cjihrig.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should consider this semver major since the request object is owned by hapi. Any user code that is attaching things to the request object can use a symbol, request.app, etc.

Copy link
Copy Markdown
Member

@devinivy devinivy Jul 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of server.decorate('request', ...) usage, but either way I see your point. For example, the schmervice plugin adds support for request.services(). If hapi decided to name something "services" then it would break that plugin.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you're saying makes sense. One thing we could do: automatically consider any additions to the reserved lists across the codebase as semver major.

Another longer term, but not mutually exclusive, idea: have decorate() update some new object (request.decorations?) on requests so that they won't ever conflict with hapi.

Copy link
Copy Markdown
Member

@devinivy devinivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the build breakage is related directly to hapijs/lab#981. Beyond that this looks good to me. I made a note, but it may make sense to include this as a small feature in v20 given that reserving request.isInjection could be seen as a breaking change. It's pretty slight, though.

@devinivy devinivy added the feature New functionality or improvement label Jul 25, 2020
@cjihrig
Copy link
Copy Markdown
Contributor

cjihrig commented Jul 25, 2020

I cleared the Travis cache. Hopefully the CI will be green now.

neenhouse and others added 2 commits July 25, 2020 11:05
Co-authored-by: Colin Ihrig <cjihrig@gmail.com>
@neenhouse neenhouse force-pushed the add-is-injected-prop branch from 298f11f to ce1367e Compare July 25, 2020 16:16
Copy link
Copy Markdown
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there.

@cjihrig cjihrig merged commit 783aa8a into hapijs:master Aug 11, 2020
@cjihrig
Copy link
Copy Markdown
Contributor

cjihrig commented Aug 11, 2020

Thanks for the contribution!

@cjihrig cjihrig mentioned this pull request Aug 11, 2020
@neenhouse neenhouse deleted the add-is-injected-prop branch August 11, 2020 13:48
@cjihrig cjihrig added this to the 20.0.0 milestone Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New functionality or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improved injected request detection

5 participants