You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2012/11/08 23:44:11 UTC

[15/15] git commit: refactor is_preflight_request() for clarity

refactor is_preflight_request() for clarity


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/f976cfef
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/f976cfef
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/f976cfef

Branch: refs/heads/431-feature_cors
Commit: f976cfef52450a3c6c6ffd5049f5805037f874da
Parents: eccc28b
Author: Jan Lehnardt <ja...@apache.org>
Authored: Thu Nov 8 22:19:27 2012 +0100
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Nov 8 23:37:33 2012 +0100

----------------------------------------------------------------------
 src/couchdb/couch_httpd_cors.erl |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/f976cfef/src/couchdb/couch_httpd_cors.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_cors.erl b/src/couchdb/couch_httpd_cors.erl
index 6f501cc..a783ae6 100644
--- a/src/couchdb/couch_httpd_cors.erl
+++ b/src/couchdb/couch_httpd_cors.erl
@@ -32,20 +32,20 @@
 
 is_preflight_request(#httpd{method=Method}=Req) when Method /= 'OPTIONS' ->
     Req;
-is_preflight_request(#httpd{mochi_req=MochiReq}=Req) ->
-    case get_bool_config("httpd", "enable_cors", false) of
-        true ->
-            case preflight_request(MochiReq) of
-                {ok, PreflightHeaders} ->
-                    send_preflight_response(Req, PreflightHeaders);
-                _ ->
-                    Req
-            end;
-        false ->
+is_preflight_request(Req) ->
+    EnableCors = get_bool_config("httpd", "enable_cors", false),
+    is_preflight_request(Req, EnableCors).
+
+is_preflight_request(Req, false) ->
+    Req;
+is_preflight_request(#httpd{mochi_req=MochiReq}=Req, true) ->
+    case preflight_request(MochiReq) of
+        {ok, PreflightHeaders} ->
+            send_preflight_response(Req, PreflightHeaders);
+        _ ->
             Req
     end.
 
-
 cors_headers(#httpd{mochi_req=MochiReq}) ->
     Host = couch_httpd_vhost:host(MochiReq),
     case get_bool_config("httpd", "enable_cors", false) of


Re: [15/15] git commit: refactor is_preflight_request() for clarity

Posted by Jan Lehnardt <ja...@apache.org>.
On Nov 9, 2012, at 08:12 , Benoit Chesneau <bc...@gmail.com> wrote:

> I just think some of you is allergic to case ;)

That’s totally me :)

My prime objectives here were:

 1. reducing the level of indentation
 2. making each function clause do “one thing”

Hop ya’ll fine with that!
Jan
-- 


> 
> - benoit
> 
> On Fri, Nov 9, 2012 at 9:09 AM, Paul Davis <pa...@gmail.com> wrote:
>> I find it quite a bit more readable.
>> 
>> 
>> On Fri, Nov 9, 2012 at 12:23 AM, Benoit Chesneau <bc...@gmail.com>wrote:
>> 
>>> Hrm I don't find it more clear... Now you have to look at 2 places to
>>> know what this true or false is about. the case was enough. Also why
>>> not reusing the enable_cors() new fonction ?
>>> 
>>> On Thu, Nov 8, 2012 at 11:44 PM,  <ja...@apache.org> wrote:
>>>> refactor is_preflight_request() for clarity
>>>> 
>>>> 
>>>> Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
>>>> Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/f976cfef
>>>> Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/f976cfef
>>>> Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/f976cfef
>>>> 
>>>> Branch: refs/heads/431-feature_cors
>>>> Commit: f976cfef52450a3c6c6ffd5049f5805037f874da
>>>> Parents: eccc28b
>>>> Author: Jan Lehnardt <ja...@apache.org>
>>>> Authored: Thu Nov 8 22:19:27 2012 +0100
>>>> Committer: Jan Lehnardt <ja...@apache.org>
>>>> Committed: Thu Nov 8 23:37:33 2012 +0100
>>>> 
>>>> ----------------------------------------------------------------------
>>>> src/couchdb/couch_httpd_cors.erl |   22 +++++++++++-----------
>>>> 1 files changed, 11 insertions(+), 11 deletions(-)
>>>> ----------------------------------------------------------------------
>>>> 
>>>> 
>>>> 
>>> http://git-wip-us.apache.org/repos/asf/couchdb/blob/f976cfef/src/couchdb/couch_httpd_cors.erl
>>>> ----------------------------------------------------------------------
>>>> diff --git a/src/couchdb/couch_httpd_cors.erl
>>> b/src/couchdb/couch_httpd_cors.erl
>>>> index 6f501cc..a783ae6 100644
>>>> --- a/src/couchdb/couch_httpd_cors.erl
>>>> +++ b/src/couchdb/couch_httpd_cors.erl
>>>> @@ -32,20 +32,20 @@
>>>> 
>>>> is_preflight_request(#httpd{method=Method}=Req) when Method /=
>>> 'OPTIONS' ->
>>>>     Req;
>>>> -is_preflight_request(#httpd{mochi_req=MochiReq}=Req) ->
>>>> -    case get_bool_config("httpd", "enable_cors", false) of
>>>> -        true ->
>>>> -            case preflight_request(MochiReq) of
>>>> -                {ok, PreflightHeaders} ->
>>>> -                    send_preflight_response(Req, PreflightHeaders);
>>>> -                _ ->
>>>> -                    Req
>>>> -            end;
>>>> -        false ->
>>>> +is_preflight_request(Req) ->
>>>> +    EnableCors = get_bool_config("httpd", "enable_cors", false),
>>>> +    is_preflight_request(Req, EnableCors).
>>>> +
>>>> +is_preflight_request(Req, false) ->
>>>> +    Req;
>>>> +is_preflight_request(#httpd{mochi_req=MochiReq}=Req, true) ->
>>>> +    case preflight_request(MochiReq) of
>>>> +        {ok, PreflightHeaders} ->
>>>> +            send_preflight_response(Req, PreflightHeaders);
>>>> +        _ ->
>>>>             Req
>>>>     end.
>>>> 
>>>> -
>>>> cors_headers(#httpd{mochi_req=MochiReq}) ->
>>>>     Host = couch_httpd_vhost:host(MochiReq),
>>>>     case get_bool_config("httpd", "enable_cors", false) of
>>>> 
>>> 


Re: [15/15] git commit: refactor is_preflight_request() for clarity

Posted by Benoit Chesneau <bc...@gmail.com>.
I just think some of you is allergic to case ;)

- benoit

On Fri, Nov 9, 2012 at 9:09 AM, Paul Davis <pa...@gmail.com> wrote:
> I find it quite a bit more readable.
>
>
> On Fri, Nov 9, 2012 at 12:23 AM, Benoit Chesneau <bc...@gmail.com>wrote:
>
>> Hrm I don't find it more clear... Now you have to look at 2 places to
>> know what this true or false is about. the case was enough. Also why
>> not reusing the enable_cors() new fonction ?
>>
>> On Thu, Nov 8, 2012 at 11:44 PM,  <ja...@apache.org> wrote:
>> > refactor is_preflight_request() for clarity
>> >
>> >
>> > Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
>> > Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/f976cfef
>> > Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/f976cfef
>> > Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/f976cfef
>> >
>> > Branch: refs/heads/431-feature_cors
>> > Commit: f976cfef52450a3c6c6ffd5049f5805037f874da
>> > Parents: eccc28b
>> > Author: Jan Lehnardt <ja...@apache.org>
>> > Authored: Thu Nov 8 22:19:27 2012 +0100
>> > Committer: Jan Lehnardt <ja...@apache.org>
>> > Committed: Thu Nov 8 23:37:33 2012 +0100
>> >
>> > ----------------------------------------------------------------------
>> >  src/couchdb/couch_httpd_cors.erl |   22 +++++++++++-----------
>> >  1 files changed, 11 insertions(+), 11 deletions(-)
>> > ----------------------------------------------------------------------
>> >
>> >
>> >
>> http://git-wip-us.apache.org/repos/asf/couchdb/blob/f976cfef/src/couchdb/couch_httpd_cors.erl
>> > ----------------------------------------------------------------------
>> > diff --git a/src/couchdb/couch_httpd_cors.erl
>> b/src/couchdb/couch_httpd_cors.erl
>> > index 6f501cc..a783ae6 100644
>> > --- a/src/couchdb/couch_httpd_cors.erl
>> > +++ b/src/couchdb/couch_httpd_cors.erl
>> > @@ -32,20 +32,20 @@
>> >
>> >  is_preflight_request(#httpd{method=Method}=Req) when Method /=
>> 'OPTIONS' ->
>> >      Req;
>> > -is_preflight_request(#httpd{mochi_req=MochiReq}=Req) ->
>> > -    case get_bool_config("httpd", "enable_cors", false) of
>> > -        true ->
>> > -            case preflight_request(MochiReq) of
>> > -                {ok, PreflightHeaders} ->
>> > -                    send_preflight_response(Req, PreflightHeaders);
>> > -                _ ->
>> > -                    Req
>> > -            end;
>> > -        false ->
>> > +is_preflight_request(Req) ->
>> > +    EnableCors = get_bool_config("httpd", "enable_cors", false),
>> > +    is_preflight_request(Req, EnableCors).
>> > +
>> > +is_preflight_request(Req, false) ->
>> > +    Req;
>> > +is_preflight_request(#httpd{mochi_req=MochiReq}=Req, true) ->
>> > +    case preflight_request(MochiReq) of
>> > +        {ok, PreflightHeaders} ->
>> > +            send_preflight_response(Req, PreflightHeaders);
>> > +        _ ->
>> >              Req
>> >      end.
>> >
>> > -
>> >  cors_headers(#httpd{mochi_req=MochiReq}) ->
>> >      Host = couch_httpd_vhost:host(MochiReq),
>> >      case get_bool_config("httpd", "enable_cors", false) of
>> >
>>

Re: [15/15] git commit: refactor is_preflight_request() for clarity

Posted by Paul Davis <pa...@gmail.com>.
I find it quite a bit more readable.


On Fri, Nov 9, 2012 at 12:23 AM, Benoit Chesneau <bc...@gmail.com>wrote:

> Hrm I don't find it more clear... Now you have to look at 2 places to
> know what this true or false is about. the case was enough. Also why
> not reusing the enable_cors() new fonction ?
>
> On Thu, Nov 8, 2012 at 11:44 PM,  <ja...@apache.org> wrote:
> > refactor is_preflight_request() for clarity
> >
> >
> > Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
> > Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/f976cfef
> > Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/f976cfef
> > Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/f976cfef
> >
> > Branch: refs/heads/431-feature_cors
> > Commit: f976cfef52450a3c6c6ffd5049f5805037f874da
> > Parents: eccc28b
> > Author: Jan Lehnardt <ja...@apache.org>
> > Authored: Thu Nov 8 22:19:27 2012 +0100
> > Committer: Jan Lehnardt <ja...@apache.org>
> > Committed: Thu Nov 8 23:37:33 2012 +0100
> >
> > ----------------------------------------------------------------------
> >  src/couchdb/couch_httpd_cors.erl |   22 +++++++++++-----------
> >  1 files changed, 11 insertions(+), 11 deletions(-)
> > ----------------------------------------------------------------------
> >
> >
> >
> http://git-wip-us.apache.org/repos/asf/couchdb/blob/f976cfef/src/couchdb/couch_httpd_cors.erl
> > ----------------------------------------------------------------------
> > diff --git a/src/couchdb/couch_httpd_cors.erl
> b/src/couchdb/couch_httpd_cors.erl
> > index 6f501cc..a783ae6 100644
> > --- a/src/couchdb/couch_httpd_cors.erl
> > +++ b/src/couchdb/couch_httpd_cors.erl
> > @@ -32,20 +32,20 @@
> >
> >  is_preflight_request(#httpd{method=Method}=Req) when Method /=
> 'OPTIONS' ->
> >      Req;
> > -is_preflight_request(#httpd{mochi_req=MochiReq}=Req) ->
> > -    case get_bool_config("httpd", "enable_cors", false) of
> > -        true ->
> > -            case preflight_request(MochiReq) of
> > -                {ok, PreflightHeaders} ->
> > -                    send_preflight_response(Req, PreflightHeaders);
> > -                _ ->
> > -                    Req
> > -            end;
> > -        false ->
> > +is_preflight_request(Req) ->
> > +    EnableCors = get_bool_config("httpd", "enable_cors", false),
> > +    is_preflight_request(Req, EnableCors).
> > +
> > +is_preflight_request(Req, false) ->
> > +    Req;
> > +is_preflight_request(#httpd{mochi_req=MochiReq}=Req, true) ->
> > +    case preflight_request(MochiReq) of
> > +        {ok, PreflightHeaders} ->
> > +            send_preflight_response(Req, PreflightHeaders);
> > +        _ ->
> >              Req
> >      end.
> >
> > -
> >  cors_headers(#httpd{mochi_req=MochiReq}) ->
> >      Host = couch_httpd_vhost:host(MochiReq),
> >      case get_bool_config("httpd", "enable_cors", false) of
> >
>

Re: [15/15] git commit: refactor is_preflight_request() for clarity

Posted by Benoit Chesneau <bc...@gmail.com>.
forget the enable_cors() blah

On Fri, Nov 9, 2012 at 12:23 AM, Benoit Chesneau <bc...@gmail.com> wrote:
> Hrm I don't find it more clear... Now you have to look at 2 places to
> know what this true or false is about. the case was enough. Also why
> not reusing the enable_cors() new fonction ?
>
> On Thu, Nov 8, 2012 at 11:44 PM,  <ja...@apache.org> wrote:
>> refactor is_preflight_request() for clarity
>>
>>
>> Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/f976cfef
>> Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/f976cfef
>> Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/f976cfef
>>
>> Branch: refs/heads/431-feature_cors
>> Commit: f976cfef52450a3c6c6ffd5049f5805037f874da
>> Parents: eccc28b
>> Author: Jan Lehnardt <ja...@apache.org>
>> Authored: Thu Nov 8 22:19:27 2012 +0100
>> Committer: Jan Lehnardt <ja...@apache.org>
>> Committed: Thu Nov 8 23:37:33 2012 +0100
>>
>> ----------------------------------------------------------------------
>>  src/couchdb/couch_httpd_cors.erl |   22 +++++++++++-----------
>>  1 files changed, 11 insertions(+), 11 deletions(-)
>> ----------------------------------------------------------------------
>>
>>
>> http://git-wip-us.apache.org/repos/asf/couchdb/blob/f976cfef/src/couchdb/couch_httpd_cors.erl
>> ----------------------------------------------------------------------
>> diff --git a/src/couchdb/couch_httpd_cors.erl b/src/couchdb/couch_httpd_cors.erl
>> index 6f501cc..a783ae6 100644
>> --- a/src/couchdb/couch_httpd_cors.erl
>> +++ b/src/couchdb/couch_httpd_cors.erl
>> @@ -32,20 +32,20 @@
>>
>>  is_preflight_request(#httpd{method=Method}=Req) when Method /= 'OPTIONS' ->
>>      Req;
>> -is_preflight_request(#httpd{mochi_req=MochiReq}=Req) ->
>> -    case get_bool_config("httpd", "enable_cors", false) of
>> -        true ->
>> -            case preflight_request(MochiReq) of
>> -                {ok, PreflightHeaders} ->
>> -                    send_preflight_response(Req, PreflightHeaders);
>> -                _ ->
>> -                    Req
>> -            end;
>> -        false ->
>> +is_preflight_request(Req) ->
>> +    EnableCors = get_bool_config("httpd", "enable_cors", false),
>> +    is_preflight_request(Req, EnableCors).
>> +
>> +is_preflight_request(Req, false) ->
>> +    Req;
>> +is_preflight_request(#httpd{mochi_req=MochiReq}=Req, true) ->
>> +    case preflight_request(MochiReq) of
>> +        {ok, PreflightHeaders} ->
>> +            send_preflight_response(Req, PreflightHeaders);
>> +        _ ->
>>              Req
>>      end.
>>
>> -
>>  cors_headers(#httpd{mochi_req=MochiReq}) ->
>>      Host = couch_httpd_vhost:host(MochiReq),
>>      case get_bool_config("httpd", "enable_cors", false) of
>>

Re: [15/15] git commit: refactor is_preflight_request() for clarity

Posted by Benoit Chesneau <bc...@gmail.com>.
Hrm I don't find it more clear... Now you have to look at 2 places to
know what this true or false is about. the case was enough. Also why
not reusing the enable_cors() new fonction ?

On Thu, Nov 8, 2012 at 11:44 PM,  <ja...@apache.org> wrote:
> refactor is_preflight_request() for clarity
>
>
> Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
> Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/f976cfef
> Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/f976cfef
> Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/f976cfef
>
> Branch: refs/heads/431-feature_cors
> Commit: f976cfef52450a3c6c6ffd5049f5805037f874da
> Parents: eccc28b
> Author: Jan Lehnardt <ja...@apache.org>
> Authored: Thu Nov 8 22:19:27 2012 +0100
> Committer: Jan Lehnardt <ja...@apache.org>
> Committed: Thu Nov 8 23:37:33 2012 +0100
>
> ----------------------------------------------------------------------
>  src/couchdb/couch_httpd_cors.erl |   22 +++++++++++-----------
>  1 files changed, 11 insertions(+), 11 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/couchdb/blob/f976cfef/src/couchdb/couch_httpd_cors.erl
> ----------------------------------------------------------------------
> diff --git a/src/couchdb/couch_httpd_cors.erl b/src/couchdb/couch_httpd_cors.erl
> index 6f501cc..a783ae6 100644
> --- a/src/couchdb/couch_httpd_cors.erl
> +++ b/src/couchdb/couch_httpd_cors.erl
> @@ -32,20 +32,20 @@
>
>  is_preflight_request(#httpd{method=Method}=Req) when Method /= 'OPTIONS' ->
>      Req;
> -is_preflight_request(#httpd{mochi_req=MochiReq}=Req) ->
> -    case get_bool_config("httpd", "enable_cors", false) of
> -        true ->
> -            case preflight_request(MochiReq) of
> -                {ok, PreflightHeaders} ->
> -                    send_preflight_response(Req, PreflightHeaders);
> -                _ ->
> -                    Req
> -            end;
> -        false ->
> +is_preflight_request(Req) ->
> +    EnableCors = get_bool_config("httpd", "enable_cors", false),
> +    is_preflight_request(Req, EnableCors).
> +
> +is_preflight_request(Req, false) ->
> +    Req;
> +is_preflight_request(#httpd{mochi_req=MochiReq}=Req, true) ->
> +    case preflight_request(MochiReq) of
> +        {ok, PreflightHeaders} ->
> +            send_preflight_response(Req, PreflightHeaders);
> +        _ ->
>              Req
>      end.
>
> -
>  cors_headers(#httpd{mochi_req=MochiReq}) ->
>      Host = couch_httpd_vhost:host(MochiReq),
>      case get_bool_config("httpd", "enable_cors", false) of
>