diff --git a/.gitignore b/.gitignore
index 781b61d..3f27ed2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,6 +31,7 @@ build/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
+*opencover.xml
*_i.c
*_p.c
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..e175a37
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,14 @@
+language: csharp
+mono: none
+env:
+ global:
+ - DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
+ - DOTNET_CLI_TELEMETRY_OPTOUT=1
+ - secure: LyfZri+LDXaez/OqC/JU+HMNQeDebmf+SYPZUOGDtWeYBWsYdpsIuhQj5PgfV5aNwSMeefxjFPk/27Cw8D7M7SDcIavBoZbP5fCBqGr9FQKRWkDizaKqP1Mnmu5bFCCr7+7jgTueFk2NZ60rj6vJsmmDtIrMoGF07RzqPySgfLM=
+dotnet: 2.1.401
+install:
+- dotnet restore
+script:
+- dotnet test -c Release /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[JsonLD.Test*]*"
+after_success:
+- bash <(curl -s https://codecov.io/bash)
diff --git a/Directory.Build.targets b/Directory.Build.targets
new file mode 100644
index 0000000..eca789c
--- /dev/null
+++ b/Directory.Build.targets
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/after.JsonLD.sln.targets b/after.JsonLD.sln.targets
new file mode 100644
index 0000000..cf28d82
--- /dev/null
+++ b/after.JsonLD.sln.targets
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/src/json-ld.net/Core/DocumentLoader.cs b/src/json-ld.net/Core/DocumentLoader.cs
index bb7d5f7..3eb83dc 100644
--- a/src/json-ld.net/Core/DocumentLoader.cs
+++ b/src/json-ld.net/Core/DocumentLoader.cs
@@ -16,11 +16,13 @@ public virtual RemoteDocument LoadDocument(string url)
{
#if !PORTABLE && !IS_CORECLR
RemoteDocument doc = new RemoteDocument(url, null);
+ HttpWebResponse resp;
+
try
{
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
req.Accept = AcceptHeader;
- WebResponse resp = req.GetResponse();
+ resp = (HttpWebResponse)req.GetResponse();
bool isJsonld = resp.Headers[HttpResponseHeader.ContentType] == "application/ld+json";
if (!resp.Headers[HttpResponseHeader.ContentType].Contains("json"))
{
@@ -31,7 +33,7 @@ public virtual RemoteDocument LoadDocument(string url)
if (!isJsonld && linkHeaders != null)
{
linkHeaders = linkHeaders.SelectMany((h) => h.Split(",".ToCharArray()))
- .Select(h => h.Trim()).ToArray();
+ .Select(h => h.Trim()).ToArray();
IEnumerable linkedContexts = linkHeaders.Where(v => v.EndsWith("rel=\"http://www.w3.org/ns/json-ld#context\""));
if (linkedContexts.Count() > 1)
{
@@ -54,9 +56,32 @@ public virtual RemoteDocument LoadDocument(string url)
{
throw;
}
- catch (Exception)
+ catch (WebException webException)
+ {
+ try
+ {
+ resp = (HttpWebResponse)webException.Response;
+ int baseStatusCode = (int)(Math.Floor((double)resp.StatusCode / 100)) * 100;
+ if (baseStatusCode == 300)
+ {
+ string location = resp.Headers[HttpResponseHeader.Location];
+ if (!string.IsNullOrWhiteSpace(location))
+ {
+ // TODO: Add recursion break or simply switch to HttpClient so we don't have to recurse on HTTP redirects.
+ return LoadDocument(location);
+ }
+ }
+ }
+ catch (Exception innerException)
+ {
+ throw new JsonLdError(JsonLdError.Error.LoadingDocumentFailed, url, innerException);
+ }
+
+ throw new JsonLdError(JsonLdError.Error.LoadingDocumentFailed, url, webException);
+ }
+ catch (Exception exception)
{
- throw new JsonLdError(JsonLdError.Error.LoadingDocumentFailed, url);
+ throw new JsonLdError(JsonLdError.Error.LoadingDocumentFailed, url, exception);
}
return doc;
#else
diff --git a/src/json-ld.net/Core/JsonLdError.cs b/src/json-ld.net/Core/JsonLdError.cs
index 6c8103d..81b1388 100644
--- a/src/json-ld.net/Core/JsonLdError.cs
+++ b/src/json-ld.net/Core/JsonLdError.cs
@@ -11,14 +11,22 @@ public class JsonLdError : Exception
private JsonLdError.Error type;
internal JObject details = null;
- public JsonLdError(JsonLdError.Error type, object detail) : base(detail == null ?
- string.Empty : detail.ToString())
+ public JsonLdError(JsonLdError.Error type, object detail, Exception innerException)
+ : base(detail == null ? string.Empty : detail.ToString(), innerException)
{
// TODO: pretty toString (e.g. print whole json objects)
this.type = type;
}
- public JsonLdError(JsonLdError.Error type) : base(string.Empty)
+ public JsonLdError(JsonLdError.Error type, object detail)
+ : base(detail == null ? string.Empty : detail.ToString())
+ {
+ // TODO: pretty toString (e.g. print whole json objects)
+ this.type = type;
+ }
+
+ public JsonLdError(JsonLdError.Error type)
+ : base(string.Empty)
{
this.type = type;
}
diff --git a/src/json-ld.net/json-ld.net.csproj b/src/json-ld.net/json-ld.net.csproj
index 735d818..611ba8e 100644
--- a/src/json-ld.net/json-ld.net.csproj
+++ b/src/json-ld.net/json-ld.net.csproj
@@ -5,7 +5,7 @@
Implements the W3C JSON-LD 1.0 standard.
1.0.6
NuGet;linked-data-dotnet
- netstandard1.3;netstandard2.0
+ netstandard1.3;netstandard2.0;netcoreapp2.1
json-ld.net
json-ld.net
json-ld;jsonld;json;linked-data;rdf;semantic;web
diff --git a/test/json-ld.net.tests/json-ld.net.tests.csproj b/test/json-ld.net.tests/json-ld.net.tests.csproj
index c7d68bb..e743c9b 100644
--- a/test/json-ld.net.tests/json-ld.net.tests.csproj
+++ b/test/json-ld.net.tests/json-ld.net.tests.csproj
@@ -6,6 +6,7 @@
false
false
false
+ true
@@ -19,6 +20,7 @@
+