mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-06 11:35:54 +08:00
Revert to URI.parse/1 (#770)
This commit is contained in:
parent
c9b21f221d
commit
fef322706f
3 changed files with 9 additions and 11 deletions
|
@ -18,10 +18,10 @@ defmodule Livebook.ContentLoader do
|
|||
"""
|
||||
@spec rewrite_url(String.t()) :: String.t()
|
||||
def rewrite_url(url) do
|
||||
case URI.new(url) do
|
||||
{:ok, uri} -> uri |> do_rewrite_url() |> URI.to_string()
|
||||
{:error, _} -> url
|
||||
end
|
||||
url
|
||||
|> URI.parse()
|
||||
|> do_rewrite_url()
|
||||
|> URI.to_string()
|
||||
end
|
||||
|
||||
defp do_rewrite_url(%URI{host: "github.com"} = uri) do
|
||||
|
|
|
@ -366,7 +366,7 @@ defimpl Livebook.FileSystem, for: Livebook.FileSystem.S3 do
|
|||
headers = opts[:headers] || []
|
||||
body = opts[:body]
|
||||
|
||||
%{host: host} = URI.new!(file_system.bucket_url)
|
||||
%{host: host} = URI.parse(file_system.bucket_url)
|
||||
|
||||
url = file_system.bucket_url <> path <> "?" <> URI.encode_query(query)
|
||||
|
||||
|
@ -394,7 +394,7 @@ defimpl Livebook.FileSystem, for: Livebook.FileSystem.S3 do
|
|||
|
||||
defp region_from_uri(uri) do
|
||||
# For many services the API host is of the form *.[region].[rootdomain].com
|
||||
%{host: host} = URI.new!(uri)
|
||||
%{host: host} = URI.parse(uri)
|
||||
host |> String.split(".") |> Enum.reverse() |> Enum.at(2, "auto")
|
||||
end
|
||||
|
||||
|
|
|
@ -167,10 +167,8 @@ defmodule Livebook.Utils do
|
|||
"""
|
||||
@spec valid_url?(String.t()) :: boolean()
|
||||
def valid_url?(url) do
|
||||
case URI.new(url) do
|
||||
{:ok, uri} -> uri.scheme != nil and uri.host != nil
|
||||
_ -> false
|
||||
end
|
||||
uri = URI.parse(url)
|
||||
uri.scheme != nil and uri.host != nil
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -247,7 +245,7 @@ defmodule Livebook.Utils do
|
|||
@spec expand_url(String.t(), String.t()) :: String.t()
|
||||
def expand_url(url, relative_path) do
|
||||
url
|
||||
|> URI.new!()
|
||||
|> URI.parse()
|
||||
|> Map.update!(:path, fn path ->
|
||||
path |> Path.dirname() |> Path.join(relative_path) |> Path.expand()
|
||||
end)
|
||||
|
|
Loading…
Add table
Reference in a new issue