Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting headers in HTTP transports #2590

Merged
merged 1 commit into from
Mar 24, 2023

Conversation

RatkoR
Copy link
Contributor

@RatkoR RatkoR commented Mar 22, 2023

Currently gqlgen sets Content-Type header to 'application/json'. There's no easy way to change it or add additional headers.

This commit adds struct variable ResponseHeaders that can hold any headers you want to be returned with response. It is standard map[string][]string variable.

If user does not set this map, we default to the Content-Type header with 'application/json' value - nothing will be changed for existing users.

Usage:

as simple as:

headers := map[string][]string{
    "Content-Type": {"application/json; charset: utf8"},
    "Other-Header": {"dummy-post-header","another-value"},
}

h.AddTransport(transport.POST{ResponseHeaders: headers})

Added tests in transport/headers_test.go.

Describe your PR and link to any relevant issues.

I have:

  • Added tests covering the bug / feature (see testing)
  • [?] Updated any relevant documentation (see docs)

Currently gqlgen sets Content-Type header to 'application/json'. There's
no easy way to change it or add additional headers.

This commit adds struct variable ResponseHeaders that can hold any
headers you want to be returned with response. It is standard
`map[string][]string` variable.

If user does not set this map, we default to the Content-Type
header with 'application/json' value - nothing will be changed
for existing users.

Usage:

as simple as:

```
headers := map[string][]string{
    "Content-Type": {"application/json; charset: utf8"},
    "Other-Header": {"dummy-post-header","another-value"},
}

h.AddTransport(transport.POST{ResponseHeaders: headers})
```

Added tests in transport/headers_test.go.
@RatkoR RatkoR changed the title Simple PR: allow setting headers in HTTP transports Allow setting headers in HTTP transports Mar 23, 2023
@coveralls
Copy link

Coverage Status

Coverage: 75.456% (-3.3%) from 78.755% when pulling 65b4f32 on RatkoR:http_transport_headers into 65ec8b5 on 99designs:master.

@StevenACoffman
Copy link
Collaborator

Thanks! This seems like a great addition, and I really appreciate you making it backward compatible.

@StevenACoffman StevenACoffman merged commit 677d854 into 99designs:master Mar 24, 2023
@RatkoR RatkoR deleted the http_transport_headers branch March 25, 2023 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants