1313
1414-export ([parse_url /1 ,
1515 transport_scheme /1 ,
16+ netloc /3 ,
1617 unparse_url /1 ,
1718 urldecode /1 , urldecode /2 ,
1819 urlencode /1 , urlencode /2 ,
@@ -94,14 +95,7 @@ normalize(#hackney_url{}=Url, Fun) when is_function(Fun, 1) ->
9495
9596 % % encode domain if needed
9697 Host2 = idna :to_ascii (Host1 ),
97- Netloc1 = case {Scheme , Port } of
98- {http , 80 } -> list_to_binary (Host2 );
99- {https , 443 } -> list_to_binary (Host2 );
100- {http_unix , _ } -> list_to_binary (Host2 );
101- _ ->
102- iolist_to_binary ([Host2 , " :" , integer_to_list (Port )])
103- end ,
104- {Host2 , Netloc1 }
98+ {Host2 , netloc (Scheme , Host2 , Port )}
10599 end ,
106100 Path1 = Fun (Path ),
107101 Url # hackney_url {host = Host , netloc = Netloc , path = Path1 }.
@@ -113,6 +107,15 @@ transport_scheme(hackney_ssl) ->
113107transport_scheme (hackney_local_tcp ) ->
114108 http_unix .
115109
110+ netloc (http , Host , 80 ) ->
111+ list_to_binary (Host );
112+ netloc (https , Host , 443 ) ->
113+ list_to_binary (Host );
114+ netloc (http_unix , Host , _Port ) ->
115+ list_to_binary (Host );
116+ netloc (_ , Host , Port ) ->
117+ iolist_to_binary ([Host , " :" , integer_to_list (Port )]).
118+
116119unparse_url (# hackney_url {}= Url ) ->
117120 # hackney_url {scheme = Scheme ,
118121 netloc = Netloc ,
0 commit comments