Skip to content

Commit

Permalink
various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Oct 15, 2023
1 parent 7787c83 commit 4c4d5d4
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ a project may be further defined and clarified by project maintainers.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at kevin+coc@dunglas.fr. All
reported by contacting the project team at kevin+coc@dunglas.dev. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## License and Copyright Attribution

When you open a Pull Request to the project, you agree to license your code under the [GNU AFFERO GENERAL PUBLIC LICENSE](LICENSE)
and to transfer the copyright on the submitted code to [Kévin Dunglas](https://dunglas.fr).
and to transfer the copyright on the submitted code to [Kévin Dunglas](https://dunglas.dev).

Be sure to you have the right to do that (if you are a professional, ask your company)!

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ tl;dr:

The Vulcain Gateway Server is licensed under [AGPL-3.0](LICENSE). This license implies that if you modify the Vulcain Gateway Server, you must share those modifications. However, the AGPL-3.0 license applies only to the gateway server itself, **not to software used behind the gateway**.

For companies not wanting, or not able to use AGPL-3.0 licensed software, commercial licenses are also available. [Contact us for more information](mailto:kevin+vulcain@dunglas.fr).
For companies not wanting, or not able to use AGPL-3.0 licensed software, commercial licenses are also available. [Contact us for more information](mailto:kevin+vulcain@dunglas.dev).

## Treeware

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/dunglas/vulcain) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

## Credits

Created by [Kévin Dunglas](https://dunglas.fr). Sponsored by [Les-Tilleuls.coop](https://les-tilleuls.coop).
Created by [Kévin Dunglas](https://dunglas.dev). Sponsored by [Les-Tilleuls.coop](https://les-tilleuls.coop).

Some ideas and code used in Vulcain's reference implementation have been taken from [Hades](https://github.com/gabesullice/hades) by [Gabe Sullice](https://github.com/gabesullice), an HTTP/2 reverse proxy for JSON:API backend.

Expand Down
2 changes: 0 additions & 2 deletions caddy/caddy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
)

func TestVulcain(t *testing.T) {
t.Skip("caddytest is currently broken because of https://github.com/caddyserver/caddy/issues/5187")

tester := caddytest.NewTester(t)
tester.InitServer(`
{
Expand Down
1 change: 1 addition & 0 deletions caddy/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ replace (
require (
github.com/caddyserver/caddy/v2 v2.7.5
github.com/dunglas/vulcain v0.5.2
go.uber.org/automaxprocs v1.5.3
go.uber.org/zap v1.26.0
)

Expand Down
4 changes: 4 additions & 0 deletions caddy/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q=
github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down Expand Up @@ -625,6 +627,8 @@ go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8=
go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo=
Expand Down
10 changes: 9 additions & 1 deletion caddy/vulcain/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
// Copied from https://github.com/caddyserver/xcaddy/blob/b7fd102f41e12be4735dc77b0391823989812ce8/environment.go#L251
package main

import (
"github.com/caddyserver/caddy/v2"
caddycmd "github.com/caddyserver/caddy/v2/cmd"

"go.uber.org/automaxprocs/maxprocs"

// plug in Caddy modules here.
_ "github.com/caddyserver/caddy/v2/modules/standard"
_ "github.com/dunglas/vulcain/caddy"
)

//nolint:gochecknoinits
func init() {
//nolint:errcheck
maxprocs.Set(maxprocs.Logger(caddy.Log().Sugar().Debugf))
}

func main() {
caddycmd.Main()
}
2 changes: 1 addition & 1 deletion docs/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The main idea is to write GraphQL queries client-side, which will be converted i
To do so, libraries such as [`apollo-link-rest`](https://www.apollographql.com/docs/link/links/rest/) can be used.
Thanks to `apollo-link-rest` you can write your request in GraphQL, use all [the tools of the frontend ecosystem relying on GraphQL](https://github.com/chentsulin/awesome-graphql#clients), but let the library send REST requests to the Vulcain server to fulfill the GraphQL query.

This approach also fixes [all the problems coming with using GraphQL server-side](https://dunglas.fr/2018/03/symfonylive-paris-slides-rest-vs-graphql-illustrated-examples-with-the-api-platform-framework/)!
This approach also fixes [all the problems coming with using GraphQL server-side](https://dunglas.dev/2018/03/symfonylive-paris-slides-rest-vs-graphql-illustrated-examples-with-the-api-platform-framework/)!

Note: a higher-level library dedicated to Vulcain is being written.

Expand Down
17 changes: 7 additions & 10 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,22 +253,19 @@ func TestPreloadHeader(t *testing.T) {
}

func TestEarlyHints(t *testing.T) {
t.Skip("Ealy hints support is inconsistent with Go 1.19.")

upstream, gateway := createServers()
defer upstream.Close()
defer gateway.Close()

expectedLinkHeaders := []string{"</books/1.jsonld>; rel=preload; as=fetch", "</books/2.jsonld>; rel=preload; as=fetch"}

// early hint should be sent when a preload header is set
var earlyHintCount int
var earlyHintsCount int
trace := &httptrace.ClientTrace{
Got1xxResponse: func(code int, header textproto.MIMEHeader) error {
switch code {
case http.StatusEarlyHints:
assert.Equal(t, expectedLinkHeaders, header["Link"])
earlyHintCount++
if code == http.StatusEarlyHints {
assert.ElementsMatch(t, expectedLinkHeaders, header["Link"])
earlyHintsCount++
}

return nil
Expand All @@ -284,9 +281,9 @@ func TestEarlyHints(t *testing.T) {
resp, _ := client.Do(req)
b, _ := io.ReadAll(resp.Body)

assert.Equal(t, 1, earlyHintCount)
assert.Equal(t, expectedLinkHeaders, resp.Header["Link"])
assert.Equal(t, []string{"Fields", "Preload"}, resp.Header["Vary"])
assert.Equal(t, 1, earlyHintsCount)
assert.ElementsMatch(t, expectedLinkHeaders, resp.Header["Link"])
assert.ElementsMatch(t, []string{"Fields", "Preload"}, resp.Header["Vary"])
assert.Equal(t, `{"hydra:member":[
"/books/1.jsonld",
"/books/2.jsonld"
Expand Down
2 changes: 1 addition & 1 deletion spec/vulcain.md
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ Used in production.

Contact Information:

Kévin Dunglas, [kevin+vulcain@dunglas.fr](mailto:kevin+vulcain@dunglas.fr) <https://vulcain.rocks>
Kévin Dunglas, [kevin+vulcain@dunglas.dev](mailto:kevin+vulcain@dunglas.dev) <https://vulcain.rocks>

Interoperability:

Expand Down
11 changes: 11 additions & 0 deletions vulcain.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,18 @@ func (v *Vulcain) Apply(req *http.Request, rw http.ResponseWriter, responseBody
})

if usePreloadLinks {
h := rw.Header()

// If responseHeaders is not the same as rw.Header() (e.g. when using the built-in reverse proxy)
// temporarly copy Link headers to send the 103 response
_, ok := h["Link"]
if !ok {
h["Link"] = responseHeaders["Link"]
}
rw.WriteHeader(http.StatusEarlyHints)
if !ok {
delete(h, "Link")
}
responseHeaders.Add("Vary", "Preload")
}

Expand Down

0 comments on commit 4c4d5d4

Please sign in to comment.