question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Search: Protocol validation prevents use with local emulator

See original GitHub issue

Library name and version

Azure.Search.Documents

Describe the bug

On this line: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/search/Azure.Search.Documents/src/SearchClient.cs#L196

Its throwing an error if the endpoint isn’t https. I am using an emulator for local development and it is http instead. This class shouldn’t attempt to validate the scheme, it’s not really its concern.

Expected behavior

I expect it to not throw an exception when provided an http scheme endpoint url.

Actual behavior

It throws an ArgumentException saying the scheme must be https.

Reproduction Steps

new SearchClient("http://localhost:8080", "test", null);

Environment

> dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.202
 Commit:    f8a55617d2

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  12.5
 OS Platform: Darwin
 RID:         osx.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.202/

Host (useful for support):
  Version: 6.0.4
  Commit:  be98e88c76

.NET SDKs installed:
  5.0.400 [/usr/local/share/dotnet/sdk]
  6.0.200 [/usr/local/share/dotnet/sdk]
  6.0.201 [/usr/local/share/dotnet/sdk]
  6.0.202 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ShivangiRejacommented, Oct 3, 2022

Closing this issue as I believe it has been addressed. @justinmchase please feel free to reopen this issue or create a new one if you have any further questions. Thanks you!

1reaction
ShivangiRejacommented, Sep 19, 2022

By default, we do secure communication (https) over the wire. Even Search service doesn’t support http request and throws exception if we send http request:

<body>
502 Bad Gateway This error occurs when you enter HTTP instead of HTTPS in the connection.
</body> </html>

I believe If you’re using an emulator for local development, you can add HTTP support for our clients with a custom pipeline policy. Here’s how you can add:

SearchClientOptions options = new();
options.AddPolicy(new UnsafeForceHttpPolicy(), HttpPipelinePosition.PerCall);
Uri endpoint = new Uri("https://<resource-name>.search.windows.net");
SearchClient client = new SearchClient(endpoint, indexName, new AzureKeyCredential("<PrimaryApiKey>"), options);

public class UnsafeForceHttpPolicy : HttpPipelineSynchronousPolicy
{
    public override void OnSendingRequest(HttpMessage message) => message.Request.Uri.Scheme = "http";
}

In this sample, https endpoint will let it get past the validation in the constructor but the pipeline will flip it to http before we send anything.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SDK v3 does not works locally with CosmosDB Emulator ...
I've tried to run the CosmosDb Emulator on a docker container without any success. By setting an IHttpClientFactory to bypass SSL certificate ...
Read more >
Install and develop locally with Azure Cosmos DB Emulator
Learn how to install and use the Azure Cosmos DB Emulator on Windows, Linux, macOS, and Windows docker environments. Using the emulator you ......
Read more >
Connect your app to the Authentication Emulator - Firebase
The Firebase Local Emulator Suite emulates products for a single Firebase project. To select the project to use, before you start the emulators,...
Read more >
Testing apps locally with the emulator - Cloud Pub/Sub
To develop and test your application locally, you can use the Pub/Sub emulator, which provides local emulation of the production Pub/Sub service.
Read more >
Reading bug reports
Android bug reports contain dumpsys , dumpstate , and logcat data in text (.txt) format, enabling you to easily search for specific content....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found