Git Product home page Git Product logo

node-fastify-auto-push's Introduction

Fastify plugin for HTTP/2 automatic server push

This is not an official Google product.

HTTP/2 is a major revision of the HTTP protocol. One of its differences from HTTP/1 is server push, which allows a server to pre-emptively send responses to a client in association with a previous client-initiated request. This can be useful when the server knows the client will need to have those responses available in order to fully process the response to the original request.

It sounds simple and easy but is quite tricky for service developers to manually figure out and configure what resources to push in association with another resource. There are also many pitfalls the implementors must know about. See Rules of Thumb for HTTP/2 Push for the details.

This project is for automating server push and getting rid of the need for manual configurations from service developers. It is a fastify plugin that serves static files and is implemented on top of the h2-auto-push package. It can be thought as a replacement of the fastify-static plugin that supports automatic server-push.

For more details, see the h2-auto-push package.

This package currently works only with Node >=9.4.0.

How to use

import * as fastify from 'fastify';
import {staticServe} from 'fastify-auto-push';
...
const app = fastify({https: {key, cert}, http2: true});
app.register(staticServe, {root: 'path/to/static'});
...

node-fastify-auto-push's People

Contributors

douglascvas avatar greenkeeper[bot] avatar jinwoo avatar mcollina avatar millette avatar ofrobots avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-fastify-auto-push's Issues

Example HTTP/2 push does not appear to work

Basic process:

  1. git clone [email protected]:google/node-fastify-auto-push.git
  2. cd node-fastify-auto-push/samples/static-page
  3. npm start -- --h2 --ap -p 3000
  4. Open Google Chrome (v65) and navigate to https://localhost:3000/, bypass security warning, see "Wikipedia" load.
  5. Open DevTools > Network Tab, reload page and notice that "Initiator" isn't "Push" (as one would expect it to be):
    image
  6. Try using nghttp2-client as I have seen suggested for testing "Push" (wherein pushed assets are represented by an asterisk next to their asset row):
nghttp -ans https://localhost:3000
[WARNING] Certificate verification failed: Hostname mismatch
Some requests were not processed. total=23, processed=8
***** Statistics *****

Request timing:
  responseEnd: the  time  when  last  byte of  response  was  received
               relative to connectEnd
 requestStart: the time  just before  first byte  of request  was sent
               relative  to connectEnd.   If  '*' is  shown, this  was
               pushed by server.
      process: responseEnd - requestStart
         code: HTTP status code
         size: number  of  bytes  received as  response  body  without
               inflation.
          URI: request URI

see http://www.w3.org/TR/resource-timing/#processing-model

sorted by 'complete'

id  responseEnd requestStart  process code size request path
  4     +3.01ms *    +1.78ms   1.23ms  200  285 /load_1.css
 10     +3.02ms *    +1.81ms   1.21ms  200   2K /images/40px-Edit-clear.svg.png
  6     +3.17ms *    +1.79ms   1.39ms  200   3K /images/50px-Question_book-new.svg.png
  8     +3.40ms *    +1.79ms   1.61ms  200   8K /images/220px-Node.js_logo.svg.png
  2     +3.66ms *    +1.77ms   1.89ms  200  49K /load_3.css
 19     +6.59ms      +4.68ms   1.91ms  200   2K /wikipedia.ico
 21     +6.91ms      +4.68ms   2.24ms  200  17K /images/220px-Ryan_Dahl.jpg
 23     +9.00ms      +6.08ms   2.92ms  200   1K /images/28px-Free_and_open-source_software_logo_(2009).svg.png

โš ๏ธ The nghttp command seems to immediately crash our example server after displaying the above output. The crash is noted logged like this:

npm start -- --h2 --ap -p 3000

> [email protected] start /home/tyler/tmp-code/node-fastify-auto-push/samples/static-page
> node index.js "--h2" "--ap" "-p" "3000"

(node:31382) ExperimentalWarning: The http2 module is an experimental API.
Listening on port 3000
events.js:165
      throw er; // Unhandled 'error' event
      ^

Error [ERR_HTTP2_INVALID_STREAM]: The stream has been destroyed
    at ServerHttp2Stream.doSendFileFD (internal/http2/core.js:1990:18)
    at FSReqWrap.oncomplete (fs.js:171:5)
Emitted 'error' event at:
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at process._tickCallback (internal/process/next_tick.js:178:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node index.js "--h2" "--ap" "-p" "3000"`
npm ERR! Exit status 1

Other details:


Please let me know if there's any additional information I should provide.
I deeply appreciate any time someone might spend thinking about this.
Thank you.

decorateReply doesn't working.

Thanks for jobs.

I have an issue when I use this module to serve multi-static routes.

import fastifyAutoPush from 'fastify-auto-push'
const fastifyStatic = fastifyAutoPush.staticServe
...
server.register(fastifyStatic, {
  root: path.join(__basename, 'resources'),
  prefix: '/resources/',
  decorateReply: false
})
server.register(fastifyStatic, {
  root: path.join(__basename, 'clients'),
  prefix: '/clients/',
  decorateReply: false
})

When I implement only the resources part, it works well. But the second clients made an error

FastifyError [Error]: The decorator 'sendFile' has already been added!

Then after some seconds, this error would happen also.

Error: ERR_AVVIO_PLUGIN_TIMEOUT: plugin did not start in time:

When I use the original fastify-static, decorateReply:false was the solution. But fastify-auto-push doesn't respect it.

What is the best practice to use this module with multi routes at once?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency ava to v6
  • chore(deps): update dependency fastify to v4
  • chore(deps): update dependency get-port to v7
  • chore(deps): update dependency gts to v5
  • chore(deps): update dependency js-green-licenses to v4
  • chore(deps): update dependency typescript to v5
  • fix(deps): update dependency fastify-plugin to v4
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • cookie ^0.3.1
  • fastify-plugin ^1.5.0
  • fastify-static ^2.3.4
  • h2-auto-push ^0.4.1
  • @types/cookie ^0.3.2
  • @types/get-port ^4.0.1
  • @types/node ^10.12.30
  • @types/send ^0.14.4
  • ava ^2.0.0
  • codecov ^3.2.0
  • fastify ^2.0.1
  • get-port ^5.0.0
  • gts ^1.0.0
  • js-green-licenses ^1.0.0
  • nyc ^14.0.0
  • typescript ~3.4.0
  • node >=9.4.0 || >8.9.4 <9
samples/static-page/package.json
  • argparse ^1.0.10
  • fastify ^2.0.0
  • fastify-auto-push ^0.4.0
  • fastify-static ^2.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.