GithubHelp home page GithubHelp logo

seancribbs / chatterbox Goto Github PK

View Code? Open in Web Editor NEW

This project forked from joedevivo/chatterbox

0.0 2.0 0.0 1.82 MB

HTTP/2 Server for Erlang. Boy, that guy was a real chatterbox waddn't he? I didn't think he was ever going to stop with the story.

License: MIT License

Makefile 0.10% Erlang 27.57% HTML 7.14% CSS 34.39% JavaScript 30.79%

chatterbox's Introduction

chatterbox

Chatterbox is an HTTP/2 library for Erlang. Use as much of it as you want, but the goal is to implement as much of [https://tools.ietf.org/html/rfc7540][RFC-7540] as possible, 100% of the time.

It already pulls in [https://github.com/joedevivo/hpack][joedevivo/hpack] for the implementation of [https://tools.ietf.org/html/rfc7541][RFC-7541]/

Rebar3

Chatterbox is a rebar3 jam. Get into it! rebar3.org

Setting up Firefox go to the URL about:config and search for the

setting network.http.spdy.enforce.tls.profile and toggle it to false

HTTP/2 Connections

Chatterbox provides a module http2_connection which models (you guessed it!) an HTTP/2 connection. This gen_fsm can represent either side of an HTTP/2 connection (i.e. a client or server). Really, the only difference is in how you start the connection.

Server Side Connections

A server side connection can be started with [https://github.com/ninenines/ranch][ninenines/ranch] using the included chatterbox_ranch_protocol like this:

%% Set up the socket options:
Options = [
        {port, 8080},
        %% you can find certs to play with in ./config
        {certfile,   "localhost.crt"},
        {keyfile,    "localhost.key"},
        {honor_cipher_order, false},
        {versions, ['tlsv1.2']},
        {next_protocols_advertised, [<<"h2">>]}
],

%% You'll also have to set the content root for the chatterbox static
%% content handler

RootDir = "/path/to/content",

application:set_env(
        chatterbox,
        {chatterbox_static_content_hander, [{root_dir, RootDir}]}),

{ok, _RanchPid} =
    ranch:start_listener(
      chatterbox_ranch_protocol,
      10,
      ranch_ssl,
      Options,
      chatterbox_ranch_protocol,
      []),

You can do this in a rebar3 shell or in your application.

You don't have to use ranch. You can use see chatterbox_sup for an alternative.

Serving up the EUC 2015 Deck

clone chatterbox and [https://github.com/joedevivo/euc2015][euc2015]

then set the RootDir above to the checkout of euc2015.

Then it should be as easy as pointing Firefox to https://localhost:8080/.

Client Side Connections

We'll start up http2_connection a little differently. http2_client:start_link/* will take care of the differences.

Here's how to use it!

{ok, Pid} = http2_client:start_link().

Headers = [
           {<<":method">>, <<"GET">>},
           {<<":path">>, <<"/index.html">>},
           {<<":scheme">>, <<"http">>},
           {<<":authority">>, <<"localhost:8080">>},
           {<<"accept">>, <<"*/*">>},
           {<<"accept-encoding">>, <<"gzip, deflate">>},
           {<<"user-agent">>, <<"nghttp2/0.7.7">>}
          ].

{ok, StreamId} = http2_client:send_request(Pid, Headers, <<>>).

{ok, {Headers, Body}} = http2_client:get_response(Pid, StreamId).

There still needs to be some way of detecting that a promise has been pushed from the server, either actively or passively. In theory, if you knew the StreamId, you could check for a response on that stream and it would be there.

Author(s)

  • Joe DeVivo

Copyright

Copyright (c) 2015,16 Joe DeVivo, dat MIT License tho.

chatterbox's People

Contributors

joedevivo avatar tsloughter avatar

Watchers

 avatar  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.