]> gitweb.michael.orlitzky.com - dead/lwn-epub.git/blobdiff - src/LWN/URI.hs
Add some tests for the article URL construction.
[dead/lwn-epub.git] / src / LWN / URI.hs
index 9e7c7d944963a0a52b51b2b6b48aeb48ef57373d..7aa4240cf146eee312801881100ce43be087b6e5 100644 (file)
@@ -14,7 +14,7 @@ import Network.URI (
 import Test.HUnit (Assertion, assertEqual)
 import Test.Framework (Test, testGroup)
 import Test.Framework.Providers.HUnit (testCase)
-import Text.Regex.Posix
+import Text.Regex.Posix ((=~))
 
 -- Distinguish between URLs (Strings) and URIs as provided by the
 -- Network.URI module.
@@ -40,6 +40,19 @@ http_port uri =
     parse_result = uriAuthority uri
 
 
+make_https :: URL -> URL
+make_https url =
+  case parse_result of
+    Nothing -> url -- Shrug?
+    Just uri ->
+      if http uri then
+        show $ uri { uriScheme = "https:" }
+      else
+        url -- Leave non-http URLs alone.
+  where
+    parse_result = parseURIReference url
+
+
 -- | Does this URI use an HTTPS-compatible port?
 https_port :: URI -> Bool
 https_port uri =