Search code examples
c#.netsparqldotnetrdf

Applying custom request options for a remote SPARQL connector in dotNetRdf


I'm trying to add custom headers to the HTTP requsets a SPARQL endpoint connector issues. The connector can use a custom remote endpoint, which inherits an ApplyCustomRequestOptions method I can override. Documentation for that method says

[...] add any additional custom request options/headers to the request.

However my overridden method is never called (so my custom options are not applied, so I can't add the headers).

The following code works as expected, except that my ApplyCustomRequestOptions is never invoked:

using System;
using System.Net;
using VDS.RDF.Query;
using VDS.RDF.Storage;

class Program
{
    static void Main(string[] args)
    {
        var endpointUri = new Uri("https://query.wikidata.org/sparql");

        var endpoint = new CustomEndpoint(endpointUri);

        using (var connector = new SparqlConnector(endpoint))
        {
            var result = connector.Query("SELECT * WHERE {?s ?p ?o} LIMIT 1");
        }
    }
}

public class CustomEndpoint : SparqlRemoteEndpoint
{
    public CustomEndpoint(Uri endpointUri) : base(endpointUri) { }

    protected override void ApplyCustomRequestOptions(HttpWebRequest httpRequest)
    {
        // This is never executed.
        base.ApplyCustomRequestOptions(httpRequest);
        // Implementation omitted.
    }
}

Is this the correct way to use these methods? If it isn't, what is it?

BTW this is dotNetRdf 1.0.12, .NET 4.6.1. I've tried multiple SPARQL endpoints, multiple queries (SELECT & CONSTRUCT) and multiple invocations of SparqlConnector.Query.


Solution

  • This is a bug. I've found the problem and fixed it and submitted a PR. You can track the status of the issue here: https://github.com/dotnetrdf/dotnetrdf/issues/103