hashicorp / vault-client-go

HashiCorp Vault Go Client Library generated from OpenAPI spec.
Mozilla Public License 2.0
84 stars 17 forks source link

SetCustomHeaders/WithCustomHeaders seems broken #236

Closed nyxi closed 1 year ago

nyxi commented 1 year ago

Expected Behavior

Custom headers added with SetCustomHeaders should be added to all requests made with the client.

Current Behavior

The custom headers added with SetCustomHeaders are not added to requests made with the client.

Failure Information

vault-client-go 0.4.0

Steps to Reproduce

package main

import (
        "context"
        "fmt"
        "log"
        "net/http"

        "github.com/hashicorp/vault-client-go"
        "github.com/hashicorp/vault-client-go/schema"
)

func handler(w http.ResponseWriter, r *http.Request) {
        fmt.Printf("Accept-Encoding: %s\n", r.Header.Get("accept-encoding"))
        fmt.Printf("Amazing: %s\n", r.Header.Get("amazing"))
}

func listen() {
        http.HandleFunc("/", http.HandlerFunc(handler))
        http.ListenAndServe(":9393", nil)
}

func main() {
        go listen()
        // Get a Vault client
        client, _ := vault.New(
                vault.WithAddress("http://localhost:9393"),
        )

        headers := make(http.Header)
        headers.Set("amazing", "very")
        err := client.SetCustomHeaders(headers)
        if err != nil {
                log.Fatalln(err)
        }

        _, _ = client.Auth.JwtOidcRequestAuthorizationUrl(
                context.Background(),
                schema.JwtOidcRequestAuthorizationUrlRequest{
                        RedirectUri: "http://localhost:9393/oidc/callback",
                        Role:        "default_role",
                },
                vault.WithCustomHeaders(headers),
        )
}
averche commented 1 year ago

Hi @nyxi, thanks for reporting this bug!

Somehow the wiring was never done for custom headers. I believe I have a fix for this in #237

averche commented 1 year ago

Fixed and released in 0.4.1. Thanks again!