Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (r *Request) readBody(resp *http.Response) (err error) {

r.Response.Format = r.Format
r.Response.Status = resp.StatusCode
r.Response.Header = resp.Header
r.Response.Raw = resp.Body
err = r.Response.Decode()

Expand Down
2 changes: 2 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"io"
"net/http"

"github.com/olivere/ndjson"
)
Expand All @@ -21,6 +22,7 @@ type Response struct {
RowsBeforeLimitAtLeast uint `json:"rows_before_limit_at_least,omitempty"` // RowsBeforeLimitAtLeast is part a tinybird response.
Statistics Statistics `json:"statistics,omitempty"` // Statistics is part a tinybird response.
Status int // Status is a HTTP status code, ej: 200, 400, 500 etc...
Header http.Header // Headers contains the HTTP response headers returned by the server
Format string // Save format setting.
}

Expand Down
23 changes: 23 additions & 0 deletions response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tinybird_test

import (
"io"
"net/http"
"strings"
"testing"

Expand Down Expand Up @@ -133,3 +134,25 @@ func TestErrorOnDecodeNDJSON(t *testing.T) {

assert.NotNil(t, err)
}

func TestResponseHeader(t *testing.T) {
// Create a mock HTTP response
mockHeader := http.Header{
"Content-Type": {"application/json"},
"X-Custom-Header": {"CustomValue"},
}
mockResponse := &http.Response{
Header: mockHeader,
}

// Create a Response object and assign the mock headers
response := tinybird.Response{}
response.Header = mockResponse.Header

// Validate Headers using testify assertions
assert.Equal(t, len(mockHeader), len(response.Header), "Header count should match")

for key, values := range mockHeader {
assert.ElementsMatch(t, values, response.Header.Values(key), "Header values should match for key: %s", key)
}
}