-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
proxy mode: operate on http responses rather than requests #29
base: main
Are you sure you want to change the base?
Conversation
uri := req.RequestURI | ||
|
||
body, _ := ioutil.ReadAll(req.Body) | ||
req.Body = ioutil.NopCloser(bytes.NewBuffer(body)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the request body draining into this handleAWSRequest
function to more closely match e.g. what httputil.DumpRequest
does.
Looks like this isn't working based on my initial tests. Can you confirm whether it worked for you? |
Nice catch. I missed that because my testing didn't involve POST bodies. I've since fixed that and added a basic E2E test to avoid regression. If you add some credentials to this repo, you could have a GitHub action to exercise these tests like: on: [push, pull_request]
name: CI
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: 1.16
- name: test
run: go test -v ./...
env:
AWS_REGION: ap-southeast-2
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
parseConfig() | ||
flag.Parse() | ||
loadMaps() | ||
readServiceFiles() | ||
*modeFlag = "proxy" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty ugly, but I figured I didn't want to make bigger changes in a single PR
I moved the proxy mode logic into the response-handling function of goproxy, so that we have access to the response status code as per the TODO.
I also extracted the AWS hostname regexp to a global variable for a (probably irrelevant) speedup