couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [2/5] git commit: simplify `split_host_port()`
Date Sun, 11 Nov 2012 19:32:04 GMT
simplify `split_host_port()`


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

Branch: refs/heads/431-feature_cors
Commit: 31a826855046aa678be3281bf541dc38f93ca0a7
Parents: f75b1b5
Author: Jan Lehnardt <jan@apache.org>
Authored: Sun Nov 11 16:02:17 2012 +0000
Committer: Jan Lehnardt <jan@apache.org>
Committed: Sun Nov 11 20:32:02 2012 +0100

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


http://git-wip-us.apache.org/repos/asf/couchdb/blob/31a82685/src/couchdb/couch_httpd_cors.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_cors.erl b/src/couchdb/couch_httpd_cors.erl
index 7e45c96..14b93f4 100644
--- a/src/couchdb/couch_httpd_cors.erl
+++ b/src/couchdb/couch_httpd_cors.erl
@@ -224,16 +224,21 @@ split_headers(H) ->
     re:split(H, ",\\s*", [{return,list}, trim]).
 
 split_host_port(HostAsString) ->
-    case string:rchr(HostAsString, $:) of
-    0 ->
+    % split at semicolon ":"
+    Split = string:rchr(HostAsString, $:),
+    split_host_port(HostAsString, Split).
+
+split_host_port(HostAsString, 0) ->
+    % no semicolon
+    {HostAsString, '*'};
+split_host_port(HostAsString, N) ->
+    HostPart = string:substr(HostAsString, 1, N-1),
+    % parse out port
+    % is there a nicer way?
+    case (catch erlang:list_to_integer(string:substr(HostAsString,
+                    N+1, length(HostAsString)))) of
+    {'EXIT', _} ->
         {HostAsString, '*'};
-    N ->
-        HostPart = string:substr(HostAsString, 1, N-1),
-        case (catch erlang:list_to_integer(string:substr(HostAsString,
-                        N+1, length(HostAsString)))) of
-        {'EXIT', _} ->
-            {HostAsString, '*'};
-        Port ->
-            {HostPart, Port}
-        end
+    Port ->
+        {HostPart, Port}
     end.


Mime
View raw message