Giter Club home page Giter Club logo

http2-cache.js's Introduction

Build Status

http2-cache.js

This library is pre 1.0.0, much of the functionality is not yet fully implemented.

This library provides a user-space based HTTP/2 client implementation and cache that slots in under traditional network Browser APIs such as XHR (eventually Fetch). This project is intended to be useful for 1. providing HTTP/2 emulation when not natively available and 2. allowing backends to pre-populate a browser-side cache via HTTP/2 push.

This project is designed to be 100% spec compliant. It should be removable without loss of functionality when there is universal support for HTTP/2 with a consistent H2-cache implementation.

Design

HTTP/2 (RFC-7540) runs in userspace by running it on top of WebSocket. An HTTP (RFC-7234) in memory cache implementation stores cacheable responses. The XHR API can be configured to route a subset of requests via this transport stack.

A consistent implementation for caching HTTP/2 push requests has not yet emerged. See discussion for current the state of the world. This HTTP/2 implementation will not use the cache for any request (Including HTTP/2 pushed) that contains the request cache-directive "no-cache". HTTP/2 pushed requests that do not include this directive may have their HTTP/2 stream aborted by the client if the cache already contains a cached response for that request. I.E. use the request cache-directive "no-cache" when doing cache-busting. This should work in all cases where you want to do a cache replacement.

HTTP/2 push requests require an established stream to send the push request. The API provides a means to open a long-lived upstream request to an arbitrary location that may be used to send push requests. Alternatively, streams may be left open for sending future pushed responses via "long-pushing", that is sending the push promise for a future response, prior to completing the response to an existing request. I.e. always maintain one response in flight, by sending the push promise for it prior to completing a response.

API/Usage

The API attaches to the XMLHttpRequest object.

XMLHttpRequest.proxy([urls of configurations])

The proxy([urls of configurations]) triggers fetching of JSON configurations on the backend server. The configurations should be of the following form:

    'url': 'http://which-urls-to-send-via-http2:443/',
    'options': {
        'transport': 'wss://where-the-underlying-ws-transport-connects:443/',
        'h2PushPath': 'optional-path-that-is-opened-for-pushes'
    }

In full

<script type="text/javascript" src="http2-cache.js"></script>
<script type="text/javascript">
    XMLHttpRequest.proxy(["http://localhost:8000/config"]);
</script>

Build

The integration tests require Java JDK 8 be installed.

npm install

Browser Compatibility

TODO automation tests and testing in full, currently have checked chrome and firefox latest by hand.

Native Browser Implementations

The example directory contains a simple Web App which tests whether the browser supports native HTTP2 push with SPEC compliant caching.

Start origin

http-server -c-1

Start data server

 node server.js 

Visit page https://localhost:8080/ (Note: need to trust TLS cert)

Integration Tests

TODO -- These tests are not complete.

http2-cache.js's People

Contributors

hthetiot avatar marchant avatar

Watchers

James Cloos avatar Alex Zuckut avatar

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.