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/3f4a4e1c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/3f4a4e1c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/3f4a4e1c
Branch: refs/heads/431-feature-cors
Commit: 3f4a4e1cde458bb17831ec17f312d202ec145fab
Parents: 2995c20
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 16:11:16 2012 +0000
----------------------------------------------------------------------
src/couchdb/couch_httpd_cors.erl | 27 ++++++++++++++++-----------
1 files changed, 16 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/3f4a4e1c/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.
|