Skip to content
This repository
branch: tm-riak-admin-…
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 102 lines (91 sloc) 3.697 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
%% -------------------------------------------------------------------
%%
%% riak_core_web: setup Riak's HTTP interface
%%
%% Copyright (c) 2007-2010 Basho Technologies, Inc. All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied. See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
%% -------------------------------------------------------------------

%% @doc Convenience functions for setting up the HTTP interface
%% of Riak. This module loads parameters from the application
%% environment:
%%
%%<dl><dt> web_ip
%%</dt><dd> IP address that the Webmachine node should listen to
%%</dd><dt> web_port
%%</dt><dd> port that the Webmachine node should listen to
%%</dd><dt> web_logdir
%%</dt><dd> directory under which the access log will be stored
%%</dd></dl>
-module(riak_core_web).

-export([bindings/1,
         old_binding/0]).

bindings(Scheme) ->
  Pairs = app_helper:get_env(riak_core, Scheme, []),
  [binding_config(Scheme, Pair) || Pair <- Pairs].

%% read the old, unwrapped web_ip and web_port config
old_binding() ->
    case {app_helper:get_env(riak_core, web_ip),
          app_helper:get_env(riak_core, web_port)} of
        {IP, Port} when IP /= undefined,
                        Port /= undefined ->
            lager:warning(
              "app.config is using old-style {web_ip, ~p} and"
              " {web_port, ~p} settings in its riak_core configuration."
              " These are now deprecated, and will be removed in a"
              " future version of Riak."
              " Please migrate to the new-style riak_core configuration"
              " of {http, [{~p, ~p}]}.",
              [IP, Port, IP, Port]),
            [binding_config(http, {IP, Port})];
        _ ->
            %% do not start the HTTP interface if any part of its
            %% config is missing (maintains 0.13 behavior)
            []
    end.

binding_config(Scheme, Binding) ->
  {Ip, Port} = Binding,
  Name = spec_name(Scheme, Ip, Port),
  Config = spec_from_binding(Scheme, Name, Binding),
  
  {Name,
    {webmachine_mochiweb, start, [Config]},
      permanent, 5000, worker, [mochiweb_socket_server]}.
  
spec_from_binding(http, Name, Binding) ->
  {Ip, Port} = Binding,
  NoDelay = app_helper:get_env(riak_core, disable_http_nagle, true),
  lists:flatten([{name, Name},
                  {ip, Ip},
                  {port, Port},
                  {nodelay, NoDelay}],
                  common_config());

spec_from_binding(https, Name, Binding) ->
  {Ip, Port} = Binding,
  SslOpts = app_helper:get_env(riak_core, ssl,
                     [{certfile, "etc/cert.pem"}, {keyfile, "etc/key.pem"}]),
  NoDelay = app_helper:get_env(riak_core, disable_http_nagle, false),
  lists:flatten([{name, Name},
                  {ip, Ip},
                  {port, Port},
                  {ssl, true},
                  {ssl_opts, SslOpts},
                  {nodelay, NoDelay}],
                  common_config()).

spec_name(Scheme, Ip, Port) ->
  atom_to_list(Scheme) ++ "_" ++ Ip ++ ":" ++ integer_to_list(Port).

common_config() ->
  [{log_dir, app_helper:get_env(riak_core, http_logdir, "log")},
    {backlog, 128},
    {dispatch, [{[], riak_core_wm_urlmap, []}]}].
Something went wrong with that request. Please try again.