dotnet-stellar-sdk icon indicating copy to clipboard operation
dotnet-stellar-sdk copied to clipboard

Support ServerUri with a path included

Open raymens opened this issue 2 years ago • 2 comments

We are having issues using a Node API provider that requires a path prefix like (https://provider.com/rpc/xlm/{auth-key}/). Currently the SDK only uses the domain part of the supplied Horizon URI, and the path is fully replaced by the segments generated by the various RequestBuilders.

Through this change the original path is now stored and used later on when adding the segments again.

I'm not entirely sure in what category this falls (bug/ feature/ breaking). If users have set-up the serverUri with a path that shouldn't be there, it would be included now. I'm happy to update the version once it's clear if it's major/minor/fix.

Workaround

As a temporary workaround we're using the following:

let prefixUriBuilderOfSnd (first: string) (second: Uri) =
    let urlBuilder = new UriBuilder(first)
    let target = new UriBuilder(second)

    // do not update if the path is the default `/`
    if urlBuilder.Path = "/" then
        target.Uri
    elif target.Path.StartsWith("/") then
        target.Path <- urlBuilder.Path + target.Path[1..]
        target.Uri
    else
        target.Path <- urlBuilder.Path + target.Path
        target.Uri

let private overrideServerUriHandler =
    { new DelegatingHandler(InnerHandler = new HttpClientHandler()) with
        member x.Send(request, cancellationToken) =
            request.RequestUri <- prefixUriBuilderOfSnd serverUri request.RequestUri
            base.Send(request, cancellationToken)
        member x.SendAsync(request, cancellationToken) =
            request.RequestUri <- prefixUriBuilderOfSnd serverUri request.RequestUri
            base.SendAsync(request, cancellationToken)
    }

Types of changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [x] I have read the CONTRIBUTING document.
  • [x] My code follows the code style of this project.
  • [ ] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [x] I have added tests to cover my changes.
  • [x] All new and existing tests passed.

raymens avatar Aug 23 '22 09:08 raymens

@Kirbyrawr Can you also review?

elucidsoft avatar Sep 02 '22 12:09 elucidsoft

Someone needs to merge this into master since we upgraded to .NET 6

elucidsoft avatar Sep 11 '22 23:09 elucidsoft

I've rebased it

raymens avatar Oct 13 '22 14:10 raymens