algorand / go-algorand-sdk

Algorand Golang SDK

Home Page:https://pkg.go.dev/github.com/algorand/go-algorand-sdk/v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for "Host" header in custom headers

urtho opened this issue · comments

Problem

There are use cases where one needs algod/indexer client to dial a different IP than the one resolved from hostname
(aka fake hostname)

This should be possible by providing IP address as a hostname and a custom 'host' header when initializing the Client.

Unfortunately this does not work in Golang as it historically ignores header with Key == 'host'
See this golang issue

Solution

While adding custom headers to a request check if lowercased header key equals to 'host' and set req.Host to the header value.

Dependencies

none

Urgency

none

Would this be solved by using a second client pointing to the other server?

What is the use case though? Couldn't this normally be handled by local DNS or hosts entries ?

In my case I need to dial the same url like "mainnet-api.algonode.cloud" but each time to point to a different IP address.
With curl this is the equivalent of curl -H "Host: mainnet-api.algonode.cloud" http://my-real-node-ip
But I would love to be able to do that with SDK so I can write an automated testing tool.