Skip to content

Commit

Permalink
Allow the user to require that FHIR Base URLs use HTTPS (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
DilumAluthge authored Feb 21, 2023
1 parent 9e89d6f commit 88dd618
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FHIRClient"
uuid = "b44d2ca2-8176-4fa9-8684-826e17b2a2da"
authors = ["Dilum Aluthge", "Rhode Island Quality Institute", "contributors"]
version = "1.1.0"
version = "1.2.0"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
20 changes: 20 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ abstract type FHIRVersion <: Any
abstract type FHIRVersion
end

function _uses_https(url_str::AbstractString)
return startswith(lowercase(strip(url_str)), "https://")
end

function _uses_https(uri::HTTP.URI)
return _uses_https(Base.string(uri))
end

"""
The base URL for a FHIR server.
Expand All @@ -31,6 +38,19 @@ struct BaseURL <: Any
"""
struct BaseURL
uri::HTTP.URI
function BaseURL(uri::HTTP.URI; require_https::Bool = false) # TODO: change the default to `true`
this_uri_uses_https = _uses_https(uri)
if !this_uri_uses_https
msg = "The following FHIR Base URL does not use HTTPS: $(uri)"
if require_https
throw(ArgumentError(msg))
else
@warn "`require_https` is set to `false` - we strongly recommend setting it to `true`"
@warn msg
end
end
return new(uri)
end
end
_get_http_uri(base_url::BaseURL) = base_url.uri
function _get_http_uri_string(uri::HTTP.URI)::String
Expand Down
1 change: 1 addition & 0 deletions test/unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
include("unit/fhir-to-julia.jl")
include("unit/other-fhir-versions.jl")
include("unit/requests.jl")
include("unit/types.jl")
end
3 changes: 3 additions & 0 deletions test/unit/types.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@test_throws Exception FHIRClient.BaseURL(HTTP.URI("http://example.com"); require_https = true)
@test FHIRClient.BaseURL(HTTP.URI("http://example.com"); require_https = false) isa FHIRClient.BaseURL
@test_logs (:warn,) match_mode=:any FHIRClient.BaseURL(HTTP.URI("http://example.com"); require_https = false)

2 comments on commit 88dd618

@DilumAluthge
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/78173

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.2.0 -m "<description of version>" 88dd618b99bf666fe213551477476943767310bc
git push origin v1.2.0

Please sign in to comment.