Fallback to reading the x-terraform-get header if the module registry returns an empty json body (#2079)

Signed-off-by: James Humphries <james@james-humphries.co.uk>
This commit is contained in:
James Humphries 2024-10-23 15:33:56 +01:00 committed by GitHub
parent ce6f727755
commit c9541d81b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,6 +22,7 @@ import (
"github.com/hashicorp/go-retryablehttp" "github.com/hashicorp/go-retryablehttp"
svchost "github.com/hashicorp/terraform-svchost" svchost "github.com/hashicorp/terraform-svchost"
"github.com/hashicorp/terraform-svchost/disco" "github.com/hashicorp/terraform-svchost/disco"
"github.com/opentofu/opentofu/internal/httpclient" "github.com/opentofu/opentofu/internal/httpclient"
"github.com/opentofu/opentofu/internal/logging" "github.com/opentofu/opentofu/internal/logging"
"github.com/opentofu/opentofu/internal/registry/regsrc" "github.com/opentofu/opentofu/internal/registry/regsrc"
@ -246,6 +247,11 @@ func (c *Client) ModuleLocation(ctx context.Context, module *regsrc.Module, vers
location = v.Location location = v.Location
// if the location is empty, we will fallback to the header
if location == "" {
location = resp.Header.Get(xTerraformGet)
}
case http.StatusNoContent: case http.StatusNoContent:
// FALLBACK: set the found location from the header // FALLBACK: set the found location from the header
location = resp.Header.Get(xTerraformGet) location = resp.Header.Get(xTerraformGet)