├── gleam.toml ├── test ├── test_helper.exs ├── service.gleam └── gleam_plug_test.exs ├── CHANGELOG.md ├── .formatter.exs ├── .gitattributes ├── .gitignore ├── mix.exs ├── README.md ├── src └── gleam │ └── http │ └── plug.gleam ├── mix.lock ├── lib └── gleam_plug.ex └── LICENSE /gleam.toml: -------------------------------------------------------------------------------- 1 | name = "gleam_plug" 2 | -------------------------------------------------------------------------------- /test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## v0.1.0 - 2020-08-22 4 | 5 | - Initial release. 6 | -------------------------------------------------------------------------------- /.formatter.exs: -------------------------------------------------------------------------------- 1 | # Used by "mix format" 2 | [ 3 | inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] 4 | ] 5 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | examples/* linguist-documentation=false 2 | 3 | # We want fancy syntax highlighting on GitHub, though GitHub doesn't know how 4 | # to speak Gleam. Until it does (maybe one day!) we'll tell GitHub that these 5 | # files are Rust, which has a similar enough syntax for the highlighting to 6 | # work in most cases. 7 | # The only caveat is that we need to add a `;` after each use of the `type` 8 | # keyword as our type syntax is different to theirs in a way that confuses 9 | # GitHub. 10 | *.gleam linguist-language=Rust 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build/ 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover/ 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps/ 9 | 10 | # Where third-party dependencies like ExDoc output generated docs. 11 | /doc/ 12 | 13 | # Ignore .fetch files in case you like to edit your project deps locally. 14 | /.fetch 15 | 16 | # If the VM crashes, it generates a dump, let's ignore it too. 17 | erl_crash.dump 18 | 19 | # Also ignore archive artifacts (built via "mix archive.build"). 20 | *.ez 21 | 22 | # Ignore package tarball (built via "mix hex.build"). 23 | gleam_plug-*.tar 24 | 25 | gen 26 | -------------------------------------------------------------------------------- /test/service.gleam: -------------------------------------------------------------------------------- 1 | import gleam/http 2 | import gleam/int 3 | import gleam/option.{None, Some} 4 | import gleam/bit_builder.{BitBuilder} 5 | 6 | pub fn handle(req: http.Request(BitBuilder)) { 7 | let port = case req.port { 8 | Some(p) -> int.to_string(p) 9 | None -> "" 10 | } 11 | http.response(200) 12 | |> http.prepend_resp_header("made-with", "Gleam") 13 | |> http.prepend_resp_header("got-path", req.path) 14 | |> http.prepend_resp_header("got-method", http.method_to_string(req.method)) 15 | |> http.prepend_resp_header("got-scheme", http.scheme_to_string(req.scheme)) 16 | |> http.prepend_resp_header("got-port", port) 17 | |> http.prepend_resp_header("got-host", req.host) 18 | |> http.set_resp_body(req.body) 19 | } 20 | -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | defmodule GleamPlug.MixProject do 2 | use Mix.Project 3 | 4 | def project do 5 | [ 6 | app: :gleam_plug, 7 | version: "0.1.0", 8 | elixir: "~> 1.9", 9 | start_permanent: Mix.env() == :prod, 10 | erlc_paths: ["src", "gen"], 11 | compilers: [:gleam | Mix.compilers()], 12 | description: "A Gleam HTTP service adapter for the Plug web application interface", 13 | package: [ 14 | licenses: ["Apache-2.0"], 15 | links: %{github: "https://github.com/gleam-lang/plug"} 16 | ], 17 | deps: deps() 18 | ] 19 | end 20 | 21 | # Run "mix help compile.app" to learn about applications. 22 | def application do 23 | [ 24 | extra_applications: [:logger] 25 | ] 26 | end 27 | 28 | # Run "mix help deps" to learn about dependencies. 29 | defp deps do 30 | [ 31 | {:mix_gleam, "~> 0.1"}, 32 | {:gleam_http, "~> 1.3"}, 33 | {:plug, "~> 1.10"}, 34 | {:ex_doc, ">= 0.0.0", only: :dev, runtime: false} 35 | ] 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /test/gleam_plug_test.exs: -------------------------------------------------------------------------------- 1 | defmodule GleamPlugTest do 2 | use ExUnit.Case 3 | doctest GleamPlug 4 | import Plug.Test 5 | 6 | test "calling a service" do 7 | conn = conn(:patch, "/hello") 8 | 9 | conn = 10 | conn 11 | |> GleamPlug.conn_to_request("hello") 12 | |> :service.handle() 13 | |> GleamPlug.send(conn) 14 | 15 | assert sent_resp(conn) == 16 | {200, 17 | [ 18 | {"cache-control", "max-age=0, private, must-revalidate"}, 19 | {"got-host", "www.example.com"}, 20 | {"got-port", "80"}, 21 | {"got-scheme", "http"}, 22 | {"got-method", "patch"}, 23 | {"got-path", "/hello"}, 24 | {"made-with", "Gleam"} 25 | ], "hello"} 26 | end 27 | 28 | test "call_service/3" do 29 | conn = conn(:patch, "/hello") 30 | conn = GleamPlug.call_service(conn, "hello", &:service.handle/1) 31 | 32 | assert sent_resp(conn) == 33 | {200, 34 | [ 35 | {"cache-control", "max-age=0, private, must-revalidate"}, 36 | {"got-host", "www.example.com"}, 37 | {"got-port", "80"}, 38 | {"got-scheme", "http"}, 39 | {"got-method", "patch"}, 40 | {"got-path", "/hello"}, 41 | {"made-with", "Gleam"} 42 | ], "hello"} 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gleam Plug! 🔌 2 | 3 | A Gleam HTTP service adapter for the Plug web application interface. 4 | 5 | ## Usage 6 | 7 | Define a Gleam HTTP service 8 | 9 | ```rust 10 | import gleam/http 11 | import gleam/bit_builder.{BitBuilder} 12 | 13 | pub fn service(req: http.Request(BitBuilder)) { 14 | http.response(200) 15 | |> http.prepend_resp_header("made-with", "Gleam") 16 | |> http.set_resp_body(req.body) 17 | } 18 | ``` 19 | 20 | And then call it from an Elixir Plug application 21 | 22 | ```elixir 23 | defmodule MyPlug do 24 | def init(options) do 25 | options 26 | end 27 | 28 | def call(conn, body) do 29 | conn 30 | |> GleamPlug.call_service(body, &:my_gleam_module.service/1) 31 | end 32 | end 33 | ``` 34 | 35 | Phoenix controllers are Plugs and so Gleam services can be called from them 36 | in the same way. 37 | 38 | ```elixir 39 | defmodule MyAppWeb.UserController do 40 | use MyAppWeb, :controller 41 | 42 | def show(conn, params) do 43 | conn 44 | |> GleamPlug.call_service(params, &:my_gleam_module.service/1) 45 | end 46 | end 47 | ``` 48 | 49 | ## Installation 50 | 51 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed 52 | by adding `gleam_plug` to your list of dependencies in `mix.exs`: 53 | 54 | ```elixir 55 | def deps do 56 | [ 57 | {:gleam_plug, "~> 0.1.0"} 58 | ] 59 | end 60 | ``` 61 | 62 | Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) 63 | and published on [HexDocs](https://hexdocs.pm). Once published, the docs can 64 | be found at [https://hexdocs.pm/gleam_plug](https://hexdocs.pm/gleam_plug). 65 | -------------------------------------------------------------------------------- /src/gleam/http/plug.gleam: -------------------------------------------------------------------------------- 1 | import gleam/http 2 | import gleam/result 3 | import gleam/option.{None, Option, Some} 4 | import gleam/dynamic.{Dynamic} 5 | import gleam/bit_builder.{BitBuilder} 6 | 7 | pub external type Conn 8 | 9 | pub external fn port(Conn) -> Int = 10 | "Elixir.GleamPlug" "port" 11 | 12 | pub external fn host(Conn) -> String = 13 | "Elixir.GleamPlug" "host" 14 | 15 | pub external fn scheme(Conn) -> http.Scheme = 16 | "Elixir.GleamPlug" "scheme" 17 | 18 | external fn elixir_method(Conn) -> Dynamic = 19 | "Elixir.GleamPlug" "method" 20 | 21 | pub fn method(conn: Conn) -> http.Method { 22 | conn 23 | |> elixir_method 24 | |> http.method_from_dynamic 25 | |> result.unwrap(http.Get) 26 | } 27 | 28 | pub external fn request_path(Conn) -> String = 29 | "Elixir.GleamPlug" "request_path" 30 | 31 | pub external fn req_headers(Conn) -> List(http.Header) = 32 | "Elixir.GleamPlug" "req_headers" 33 | 34 | external fn elixir_query_string(Conn) -> String = 35 | "Elixir.GleamPlug" "query_string" 36 | 37 | pub fn query_string(conn: Conn) -> Option(String) { 38 | case elixir_query_string(conn) { 39 | "" -> None 40 | q -> Some(q) 41 | } 42 | } 43 | 44 | /// Convert a Plug connection to a Gleam HTTP request which can be 45 | /// used to call a Gleam HTTP service. 46 | /// 47 | /// It is common Plug applications to extract and decode the request 48 | /// body using a middleware so this function does not attempt to read 49 | /// the body directly from the conn, instead it must be given as the 50 | /// second argument. 51 | /// 52 | pub fn conn_to_request(conn: Conn, body: a) -> http.Request(a) { 53 | http.Request( 54 | body: body, 55 | headers: req_headers(conn), 56 | host: host(conn), 57 | path: request_path(conn), 58 | method: method(conn), 59 | port: Some(port(conn)), 60 | query: query_string(conn), 61 | scheme: scheme(conn), 62 | ) 63 | } 64 | 65 | external fn send_resp(conn: Conn, status: Int, body: BitBuilder) -> Conn = 66 | "Elixir.Plug.Conn" "send_resp" 67 | 68 | external fn merge_resp_headers(conn: Conn, headers: List(http.Header)) -> Conn = 69 | "Elixir.Plug.Conn" "merge_resp_headers" 70 | 71 | /// Send a Gleam HTTP response over the Plug connection. 72 | /// 73 | /// Note that this function does not halt the connection, so if subsequent 74 | /// plugs try to send another response, it will error out. Use the `halt` 75 | /// function after this function if you want to halt the plug pipeline. 76 | /// 77 | pub fn send(response: http.Response(BitBuilder), conn: Conn) -> Conn { 78 | conn 79 | |> merge_resp_headers(response.headers) 80 | |> send_resp(response.status, response.body) 81 | } 82 | 83 | /// Halts the Plug pipeline by preventing further plugs downstream from being 84 | /// invoked. See the docs for Plug.Builder for more information on halting a 85 | /// Plug pipeline. 86 | /// 87 | pub external fn halt(Conn) -> Conn = 88 | "Elixir.Plug.Conn" "halt" 89 | -------------------------------------------------------------------------------- /mix.lock: -------------------------------------------------------------------------------- 1 | %{ 2 | "earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"}, 3 | "ex_doc": {:hex, :ex_doc, "0.22.2", "03a2a58bdd2ba0d83d004507c4ee113b9c521956938298eba16e55cc4aba4a6c", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "cf60e1b3e2efe317095b6bb79651f83a2c1b3edcb4d319c421d7fcda8b3aff26"}, 4 | "gleam_http": {:hex, :gleam_http, "1.3.0", "dc84d787cb49550d7e98834a966a4f07ee90fe863a6088e752e8f1a208ab41c1", [:rebar3], [{:gleam_stdlib, "~> 0.10.0", [hex: :gleam_stdlib, repo: "hexpm", optional: false]}], "hexpm", "11b3815d1275847f7357a0eb94856e5627d5aa85080aac770d480db1f9240a0a"}, 5 | "gleam_stdlib": {:hex, :gleam_stdlib, "0.10.1", "f123f33e03b5cdf5e19fc179b9ee81269deb93f7defadb17ef2930e4db9011e7", [:rebar3], [], "hexpm", "8acd5d8ae1bd013b848f22745be39e6d25968bf29899a87eb5d7057f4ed89dd0"}, 6 | "makeup": {:hex, :makeup, "1.0.3", "e339e2f766d12e7260e6672dd4047405963c5ec99661abdc432e6ec67d29ef95", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "2e9b4996d11832947731f7608fed7ad2f9443011b3b479ae288011265cdd3dad"}, 7 | "makeup_elixir": {:hex, :makeup_elixir, "0.14.1", "4f0e96847c63c17841d42c08107405a005a2680eb9c7ccadfd757bd31dabccfb", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f2438b1a80eaec9ede832b5c41cd4f373b38fd7aa33e3b22d9db79e640cbde11"}, 8 | "mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm", "6cbe761d6a0ca5a31a0931bf4c63204bceb64538e664a8ecf784a9a6f3b875f1"}, 9 | "mix_gleam": {:hex, :mix_gleam, "0.1.0", "a0cee5d30de865124a32ca6cd53b64c3e2ac57f12adf6e47b88fb673f47c716e", [:mix], [], "hexpm", "9ff518e6aab444c7f2e74038f9383020ef89810cf1f4402911f33b202ffd72e7"}, 10 | "nimble_parsec": {:hex, :nimble_parsec, "0.6.0", "32111b3bf39137144abd7ba1cce0914533b2d16ef35e8abc5ec8be6122944263", [:mix], [], "hexpm", "27eac315a94909d4dc68bc07a4a83e06c8379237c5ea528a9acff4ca1c873c52"}, 11 | "plug": {:hex, :plug, "1.10.4", "41eba7d1a2d671faaf531fa867645bd5a3dce0957d8e2a3f398ccff7d2ef017f", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ad1e233fe73d2eec56616568d260777b67f53148a999dc2d048f4eb9778fe4a0"}, 12 | "plug_crypto": {:hex, :plug_crypto, "1.1.2", "bdd187572cc26dbd95b87136290425f2b580a116d3fb1f564216918c9730d227", [:mix], [], "hexpm", "6b8b608f895b6ffcfad49c37c7883e8df98ae19c6a28113b02aa1e9c5b22d6b5"}, 13 | "telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"}, 14 | } 15 | -------------------------------------------------------------------------------- /lib/gleam_plug.ex: -------------------------------------------------------------------------------- 1 | defmodule GleamPlug do 2 | @moduledoc """ 3 | A Gleam HTTP adapter for the Plug web application interface. 4 | 5 | ## Examples 6 | 7 | Define a Gleam HTTP service 8 | 9 | import gleam/http 10 | import gleam/bit_builder.{BitBuilder} 11 | 12 | pub fn service(req: http.Request(BitBuilder)) { 13 | http.response(200) 14 | |> http.prepend_resp_header("made-with", "Gleam") 15 | |> http.set_resp_body(req.body) 16 | } 17 | 18 | And then call it from an Elixir Plug application 19 | 20 | defmodule MyPlug do 21 | def init(options) do 22 | options 23 | end 24 | 25 | def call(conn, params) do 26 | conn 27 | |> GleamPlug.call_service(params, &:my_gleam_module.service/1) 28 | end 29 | end 30 | """ 31 | 32 | import Kernel, except: [send: 2] 33 | 34 | @type headers :: [{String.t(), String.t()}] 35 | @type option(inner) :: :none | {:some, inner} 36 | @type port_number :: option(integer()) 37 | @type query :: option(String.t()) 38 | @type path :: String.t() 39 | @type scheme :: :http | :https 40 | @type method :: 41 | :get 42 | | :post 43 | | :head 44 | | :put 45 | | :delete 46 | | :trace 47 | | :connect 48 | | :options 49 | | :patch 50 | | {:other, String.t()} 51 | 52 | @type request(body) :: 53 | {:request, method(), headers(), body, scheme(), path(), port_number(), path(), query} 54 | 55 | @type response(body) :: {:response, integer(), headers(), body} 56 | 57 | @doc """ 58 | Convert a Plug connection to a Gleam HTTP request which can be 59 | used to call a Gleam HTTP service. 60 | 61 | It is common Plug applications to extract and decode the request 62 | body using a middleware so this function does not attempt to read 63 | the body directly from the conn, instead it must be given as the 64 | second argument. 65 | """ 66 | def conn_to_request(conn, params) do 67 | :gleam@http@plug.conn_to_request(conn, params) 68 | end 69 | 70 | @doc """ 71 | Send a Gleam HTTP response over the Plug connection. 72 | 73 | Note that this function does not halt the connection, so if subsequent 74 | plugs try to send another response, it will error out. Use `Plug.Conn.halt/1!` 75 | after this function if you want to halt the plug pipeline. 76 | """ 77 | def send(response, conn) do 78 | :gleam@http@plug.send(response, conn) 79 | end 80 | 81 | @doc """ 82 | Call a Gleam HTTP service for a given Plug connection. 83 | 84 | It is common Plug applications to extract and decode the request 85 | body using a middleware so this function does not attempt to read 86 | the body directly from the conn, instead it must be given as the 87 | second argument. 88 | """ 89 | def call_service(conn, params, service) do 90 | conn 91 | |> conn_to_request(params) 92 | |> service.() 93 | |> send(conn) 94 | end 95 | 96 | @doc false 97 | def port(conn), do: conn.port 98 | @doc false 99 | def host(conn), do: conn.host 100 | @doc false 101 | def scheme(conn), do: conn.scheme 102 | @doc false 103 | def method(conn), do: conn.method 104 | @doc false 105 | def request_path(conn), do: conn.request_path 106 | @doc false 107 | def req_headers(conn), do: conn.req_headers 108 | @doc false 109 | def query_string(conn), do: conn.query_string 110 | end 111 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | Copyright 2018, Louis Pilfold . 179 | 180 | Licensed under the Apache License, Version 2.0 (the "License"); 181 | you may not use this file except in compliance with the License. 182 | You may obtain a copy of the License at 183 | 184 | http://www.apache.org/licenses/LICENSE-2.0 185 | 186 | Unless required by applicable law or agreed to in writing, software 187 | distributed under the License is distributed on an "AS IS" BASIS, 188 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 189 | See the License for the specific language governing permissions and 190 | limitations under the License. 191 | 192 | --------------------------------------------------------------------------------