Skip to content

Commit

Permalink
Merge pull request #1 from treasure-data/add-x-forwarded-headers
Browse files Browse the repository at this point in the history
Add X-Forwarded headers
  • Loading branch information
frsyuki authored Dec 4, 2020
2 parents 44fc5b3 + f14e821 commit 38af0b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ $ go build

See (GoReleaser)[https://goreleaser.com/] documents.

Cheat sheet:

```
# Build packages in ./dist
goreleaser --snapshot --skip-publish --rm-dist
# Release
git push # make sure you pushed
git push --tags # code and tags.
env GITHUB_TOKEN=... goreleaser
```

## License

Apache License, Version 2.0.
Expand Down
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package main

import (
"flag"
"fmt"
"log"
"net/http"
"flag"
"os"
"fmt"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/lambda"
Expand Down Expand Up @@ -59,6 +60,11 @@ func MakeLambdaClient(endpoint string) *lambda.Lambda {

func MakeInvokeLambdaHandler(client *lambda.Lambda, functionName string, pb PayloadBuilder) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
// Add proxy headers
r.Header.Add("x-forwarded-for", r.RemoteAddr[0:strings.LastIndex(r.RemoteAddr, ":")])
r.Header.Add("x-forwarded-proto", "http")
r.Header.Add("x-forwarded-port", "8080")

// Parse HTTP response and create an event
payload, err := pb.BuildRequest(r)
if err != nil {
Expand Down

0 comments on commit 38af0b2

Please sign in to comment.