Compare commits
38 commits
Author | SHA1 | Date | |
---|---|---|---|
92aa6b341f | |||
1f089236dc | |||
ee1bc68760 | |||
09cd37aa3b | |||
8a11deed01 | |||
6c05d9f126 | |||
5291903718 | |||
c08af75dc5 | |||
5fac42f17b | |||
9993d9a8ef | |||
d6e0b063e0 | |||
0afdce8c5f | |||
bcc4a9f4ab | |||
3e6600113c | |||
bd0781aec7 | |||
174a06e8b5 | |||
cf97958081 | |||
94537e9238 | |||
528b3c1da8 | |||
989e7689fc | |||
baf19d935c | |||
57654afc2d | |||
c5392885bd | |||
3d9aeaf2d3 | |||
be35ef8809 | |||
97c5ce0b7b | |||
Simon Vieille | 4fee95a165 | ||
d1a1058f28 | |||
67ec75e6ea | |||
2c0904ff1a | |||
26f7c9c40e | |||
d1dd93ee23 | |||
8f1f62787a | |||
9deb71e082 | |||
cd5d927e7a | |||
06a8ee8fe2 | |||
ef3a1d88dd | |||
4a3b19497f |
4
.dockerignore
Normal file
4
.dockerignore
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
/build
|
||||||
|
/.woodpecker.yml
|
||||||
|
/.git
|
||||||
|
/.gitignore
|
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -1,5 +1 @@
|
||||||
.idea
|
/build
|
||||||
debug
|
|
||||||
debug.test
|
|
||||||
*.exe
|
|
||||||
capture
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
variables:
|
variables:
|
||||||
- &golang "golang:1.19"
|
- &golang "golang:1.19"
|
||||||
- &volumes
|
- &volumes
|
||||||
- /var/www/html/artifacts/capture/deblan:/artifacts
|
- /var/www/html/artifacts/deblan/capture:/artifacts
|
||||||
|
|
||||||
pipeline:
|
steps:
|
||||||
test:
|
test:
|
||||||
image: *golang
|
image: *golang
|
||||||
commands:
|
commands:
|
||||||
|
@ -13,9 +13,10 @@ pipeline:
|
||||||
image: *golang
|
image: *golang
|
||||||
volumes: *volumes
|
volumes: *volumes
|
||||||
commands:
|
commands:
|
||||||
- go build -o /artifacts/capture
|
- make
|
||||||
|
- cp build/* /artifacts
|
||||||
|
|
||||||
push-release:
|
push_release:
|
||||||
image: plugins/gitea-release
|
image: plugins/gitea-release
|
||||||
volumes: *volumes
|
volumes: *volumes
|
||||||
settings:
|
settings:
|
||||||
|
@ -23,6 +24,20 @@ pipeline:
|
||||||
from_secret: gitnet_api_key
|
from_secret: gitnet_api_key
|
||||||
base_url: https://gitnet.fr
|
base_url: https://gitnet.fr
|
||||||
note: ${CI_COMMIT_MESSAGE}
|
note: ${CI_COMMIT_MESSAGE}
|
||||||
files: /artifacts/capture
|
files: build/*
|
||||||
when:
|
when:
|
||||||
event: [tag]
|
event: [tag]
|
||||||
|
|
||||||
|
docker_build_push:
|
||||||
|
image: docker:dind
|
||||||
|
secrets:
|
||||||
|
- registry_user
|
||||||
|
- registry_password
|
||||||
|
commands:
|
||||||
|
- echo "$REGISTRY_PASSWORD" | docker login -u "$REGISTRY_USER" --password-stdin
|
||||||
|
- "docker build -t deblan/capture:${CI_PIPELINE_DEPLOY_TARGET} ."
|
||||||
|
- "docker push deblan/capture:${CI_PIPELINE_DEPLOY_TARGET}"
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
when:
|
||||||
|
event: [deployment]
|
||||||
|
|
20
CHANGELOG.md
20
CHANGELOG.md
|
@ -1,5 +1,25 @@
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## v1.4.0
|
||||||
|
### Added
|
||||||
|
- add option to skil TLS verification
|
||||||
|
### Changed
|
||||||
|
- build binaries are nenamed
|
||||||
|
|
||||||
|
## v1.3.1
|
||||||
|
### Added
|
||||||
|
- add makefile to manage build
|
||||||
|
|
||||||
|
## v1.3.0
|
||||||
|
### Added
|
||||||
|
- add argument to define the configuration file
|
||||||
|
|
||||||
|
## v1.2.0
|
||||||
|
### Added
|
||||||
|
- allow to use a configuration file
|
||||||
|
- add logo
|
||||||
|
- replace the clear button with a SVG
|
||||||
|
|
||||||
## v1.1.0
|
## v1.1.0
|
||||||
### Added
|
### Added
|
||||||
- add query string in the request log
|
- add query string in the request log
|
||||||
|
|
15
Dockerfile
Normal file
15
Dockerfile
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
FROM golang:1.21-bullseye as builder
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN BUILD_DIR=/app make
|
||||||
|
|
||||||
|
FROM debian:bullseye-slim
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y ca-certificates
|
||||||
|
COPY --from=builder /app/capture-linux-amd64 /usr/bin/capture
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/bin/capture"]
|
24
Makefile
Normal file
24
Makefile
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
CGO_ENABLED = 0
|
||||||
|
CC = go build
|
||||||
|
CFLAGS = -trimpath
|
||||||
|
LDFLAGS = all=-w -s
|
||||||
|
GCFLAGS = all=
|
||||||
|
ASMFLAGS = all=
|
||||||
|
GOARCH = amd64
|
||||||
|
|
||||||
|
BUILD_DIR ?= build
|
||||||
|
LINUX_BIN ?= capture-linux-amd64
|
||||||
|
WIN_BIN ?= capture-window-amd64.exe
|
||||||
|
|
||||||
|
all: build
|
||||||
|
|
||||||
|
deps:
|
||||||
|
go install github.com/GeertJohan/go.rice/rice@latest
|
||||||
|
rice embed-go
|
||||||
|
|
||||||
|
.PHONY:
|
||||||
|
build: deps
|
||||||
|
export CGO_ENABLED=$(CGO_ENABLED)
|
||||||
|
export GOARCH=$(GOARCH)
|
||||||
|
GOOS=linux $(CC) $(CFLAGS) -o $(BUILD_DIR)/$(LINUX_BIN) -ldflags="$(LDFLAGS)" -gcflags="$(GCFLAGS)" -asmflags="$(ASMFLAGS)"
|
||||||
|
GOOS=windows $(CC) $(CFLAGS) -o $(BUILD_DIR)/$(WIN_BIN) -ldflags="$(LDFLAGS)" -gcflags="$(GCFLAGS)" -asmflags="$(ASMFLAGS)"
|
27
README.md
27
README.md
|
@ -1,13 +1,20 @@
|
||||||
|
|
||||||
**Capture** is a reverse proxy that takes an incoming HTTP request and sends it to another server,
|
**Capture** is a reverse proxy that takes an incoming HTTP request and sends it to another server,
|
||||||
proxying the response back to the client, while showing them in a dashboard.
|
proxying the response back to the client, while showing them in a dashboard.
|
||||||
|
|
||||||
|
Forked from [ofabricio/capture](https://github.com/ofabricio/capture).
|
||||||
|
|
||||||
[![status-badge](https://ci.gitnet.fr/api/badges/deblan/capture/status.svg)](https://ci.gitnet.fr/deblan/capture)
|
[![status-badge](https://ci.gitnet.fr/api/badges/deblan/capture/status.svg)](https://ci.gitnet.fr/deblan/capture)
|
||||||
|
|
||||||
## Running
|
## Running
|
||||||
|
|
||||||
```
|
```
|
||||||
./capture -url=https://example.com/
|
./capture -url=https://example.com/ -port 9000 -dashboard 9001 -captures 16
|
||||||
|
```
|
||||||
|
|
||||||
|
Via docker:
|
||||||
|
|
||||||
|
```
|
||||||
|
docker run -p 9000:9000 -p 9001:9001 deblan/capture -url=https://example.com/ -port 9000 -dashboard 9001 -captures 16
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Settings
|
#### Settings
|
||||||
|
@ -18,7 +25,18 @@ proxying the response back to the client, while showing them in a dashboard.
|
||||||
| `-port` | Set the proxy port. Default: *9000* |
|
| `-port` | Set the proxy port. Default: *9000* |
|
||||||
| `-dashboard` | Set the dashboard port. Default: *9001* |
|
| `-dashboard` | Set the dashboard port. Default: *9001* |
|
||||||
| `-captures` | Set how many captures to show in the dashboard. Default: *16* |
|
| `-captures` | Set how many captures to show in the dashboard. Default: *16* |
|
||||||
|
| `-tls-skip-verify` | Skip TLS vertificaton. Default: *false* |
|
||||||
|
| `-config` | Set the configuration file. Default: *.capture.ini* |
|
||||||
|
|
||||||
|
You can create a file named `.capture.ini` and set the configuration inside:
|
||||||
|
|
||||||
|
```
|
||||||
|
url = https://example.com/
|
||||||
|
port = 9000
|
||||||
|
dashboard = 9001
|
||||||
|
captures = 16
|
||||||
|
tls_skip_verify = false
|
||||||
|
```
|
||||||
|
|
||||||
## Using
|
## Using
|
||||||
|
|
||||||
|
@ -27,14 +45,13 @@ address. Hence, calling `http://localhost:9000/users/1` is like calling `http://
|
||||||
|
|
||||||
*Capture* saves all requests and responses so that you can see them in the dashboard.
|
*Capture* saves all requests and responses so that you can see them in the dashboard.
|
||||||
|
|
||||||
|
|
||||||
## Dashboard
|
## Dashboard
|
||||||
|
|
||||||
To access the dashboard go to `http://localhost:9001/`
|
To access the dashboard go to `http://127.0.0.1:9001/`
|
||||||
|
|
||||||
##### Preview
|
##### Preview
|
||||||
|
|
||||||
![dashboard](https://upload.deblan.org/u/2023-05/6470ba9d.png)
|
![dashboard](https://upload.deblan.org/u/2023-05/64746afd.png)
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
|
|
43
config.go
43
config.go
|
@ -2,6 +2,9 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"gopkg.in/ini.v1"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config has all the configuration parsed from the command line.
|
// Config has all the configuration parsed from the command line.
|
||||||
|
@ -9,20 +12,52 @@ type Config struct {
|
||||||
TargetURL string
|
TargetURL string
|
||||||
ProxyPort string
|
ProxyPort string
|
||||||
DashboardPort string
|
DashboardPort string
|
||||||
|
TLSSkipVerify bool
|
||||||
MaxCaptures int
|
MaxCaptures int
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadConfig reads the arguments from the command line.
|
// ReadConfig reads the arguments from the command line.
|
||||||
func ReadConfig() Config {
|
func ReadConfig() Config {
|
||||||
targetURL := flag.String("url", "https://jsonplaceholder.typicode.com", "Required. Set the url you want to proxy")
|
defaultTargetURL := "https://jsonplaceholder.typicode.com"
|
||||||
proxyPort := flag.String("port", "9000", "Set the proxy port")
|
defaultProxyPort := "9000"
|
||||||
dashboardPort := flag.String("dashboard", "9001", "Set the dashboard port")
|
defaultDashboardPort := "9001"
|
||||||
maxCaptures := flag.Int("captures", 16, "Set how many captures to show in the dashboard")
|
defaultMaxCaptures := 16
|
||||||
|
defaultConfigFile := ".capture.ini"
|
||||||
|
defaultTLSSkipVerify := false
|
||||||
|
|
||||||
|
targetURL := flag.String("url", defaultTargetURL, "Required. Set the url you want to proxy")
|
||||||
|
configFile := flag.String("config", defaultConfigFile, "Set the configuration file")
|
||||||
|
proxyPort := flag.String("port", defaultProxyPort, "Set the proxy port")
|
||||||
|
dashboardPort := flag.String("dashboard", defaultDashboardPort, "Set the dashboard port")
|
||||||
|
maxCaptures := flag.Int("captures", defaultMaxCaptures, "Set how many captures to show in the dashboard")
|
||||||
|
TLSSkipVerify := flag.Bool("tls-skip-verify", defaultTLSSkipVerify, "Skip TLS vertification")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if _, err := os.Stat(*configFile); err == nil {
|
||||||
|
cfg, err := ini.Load(*configFile)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Fail to read file %s: %v", *configFile, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
section := cfg.Section("")
|
||||||
|
|
||||||
|
return Config{
|
||||||
|
TargetURL: section.Key("url").MustString(*targetURL),
|
||||||
|
ProxyPort: section.Key("port").MustString(*proxyPort),
|
||||||
|
MaxCaptures: section.Key("captures").MustInt(*maxCaptures),
|
||||||
|
DashboardPort: section.Key("dashboard").MustString(*dashboardPort),
|
||||||
|
TLSSkipVerify: section.Key("tls_skip_verify").MustBool(*TLSSkipVerify),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Config{
|
return Config{
|
||||||
TargetURL: *targetURL,
|
TargetURL: *targetURL,
|
||||||
ProxyPort: *proxyPort,
|
ProxyPort: *proxyPort,
|
||||||
MaxCaptures: *maxCaptures,
|
MaxCaptures: *maxCaptures,
|
||||||
DashboardPort: *dashboardPort,
|
DashboardPort: *dashboardPort,
|
||||||
|
TLSSkipVerify: *TLSSkipVerify,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
|
<link rel="icon" href="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG9kaS5zb3VyY2Vmb3JnZS5uZXQvRFREL3NvZGlwb2RpLTAuZHRkIgogICB4bWxuczppbmtzY2FwZT0iaHR0cDovL3d3dy5pbmtzY2FwZS5vcmcvbmFtZXNwYWNlcy9pbmtzY2FwZSIKICAgd2lkdGg9IjEzMC40MDQxN21tIgogICBoZWlnaHQ9IjEzMC40MDQxN21tIgogICB2aWV3Qm94PSIwIDAgMTMwLjQwNDE3IDEzMC40MDQxNyIKICAgdmVyc2lvbj0iMS4xIgogICBpZD0ic3ZnOCIKICAgaW5rc2NhcGU6dmVyc2lvbj0iMS4wLjIgKGU4NmM4NzA4NzksIDIwMjEtMDEtMTUpIgogICBzb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HJva2UtbGluZWpvaW49InJvdW5kIgogICAgICAgICBpZD0icGF0aDMwIgogICAgICAgICBzdHlsZT0ic3Ryb2tlOiNiN2M0Yzg7c3Ryb2tlLXdpZHRoOjEuMTA3Nzk7c3Ryb2tlLW1pdGVybGltaXQ6NDtzdHJva2UtZGFzaGFycmF5Om5vbmUiIC8+CiAgICA8L2c+CiAgPC9nPgo8L3N2Zz4K"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.0"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.0"></script>
|
||||||
<link href="https://fonts.googleapis.com/css?family=Inconsolata:400,700" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css?family=Inconsolata:400,700" rel="stylesheet">
|
||||||
<title>Capture</title>
|
<title>Capture</title>
|
||||||
|
@ -220,10 +219,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.controls {
|
.controls {
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(5, 1fr);
|
|
||||||
gap: .5rem;
|
|
||||||
justify-content: start;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
|
@ -246,17 +241,25 @@
|
||||||
background: var(--btn-hover);
|
background: var(--btn-hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
.retry {
|
.button-svg {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
background: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.retry svg {
|
.button-svg svg {
|
||||||
width: 16px;
|
width: 16px;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-svg[disabled] svg {
|
||||||
|
opacity: 0.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-svg svg {
|
||||||
stroke: #9a9996;
|
stroke: #9a9996;
|
||||||
}
|
}
|
||||||
|
|
||||||
.retry:hover svg * {
|
.button-svg:not([disabled]):hover svg * {
|
||||||
stroke: #fff;
|
stroke: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +336,9 @@
|
||||||
<div class="dashboard" id="app" v-cloak>
|
<div class="dashboard" id="app" v-cloak>
|
||||||
<div class="list">
|
<div class="list">
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<button :disabled="items.length == 0" @click="clearDashboard">clear</button>
|
<button class="button-svg" :disabled="items.length == 0" @click="clearDashboard">
|
||||||
|
<svg viewBox="0 0 24 24" stroke-width="3" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M20 9l-1.995 11.346A2 2 0 0116.035 22h-8.07a2 2 0 01-1.97-1.654L4 9M21 6h-5.625M3 6h5.625m0 0V4a2 2 0 012-2h2.75a2 2 0 012 2v2m-6.75 0h6.75" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"></path></svg>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="list-inner">
|
<div class="list-inner">
|
||||||
<div class="list-item" v-for="item in items" :key="item.id" @click="show(item)"
|
<div class="list-item" v-for="item in items" :key="item.id" @click="show(item)"
|
||||||
|
@ -344,7 +349,7 @@
|
||||||
<span class="status" :class="statusColor(item)">
|
<span class="status" :class="statusColor(item)">
|
||||||
{{ item.status == 999 ? 'failed' : item.status }}
|
{{ item.status == 999 ? 'failed' : item.status }}
|
||||||
</span>
|
</span>
|
||||||
<button class="retry" @click="retry(item.id)">
|
<button class="button-svg" @click="retry(item.id)">
|
||||||
<svg stroke-width="3" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M21.888 13.5C21.164 18.311 17.013 22 12 22 6.477 22 2 17.523 2 12S6.477 2 12 2c4.1 0 7.625 2.468 9.168 6" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"></path><path d="M17 8h4.4a.6.6 0 00.6-.6V3" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"></path></svg>
|
<svg stroke-width="3" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M21.888 13.5C21.164 18.311 17.013 22 12 22 6.477 22 2 17.523 2 12S6.477 2 12 2c4.1 0 7.625 2.468 9.168 6" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"></path><path d="M17 8h4.4a.6.6 0 00.6-.6V3" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"></path></svg>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -378,11 +383,9 @@
|
||||||
<span>Proxying {{ targetURL }}</span>
|
<span>Proxying {{ targetURL }}</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
<script>
|
||||||
<script type="text/javascript">
|
new Vue({
|
||||||
var app = new Vue({
|
|
||||||
el: '#app',
|
el: '#app',
|
||||||
data: {
|
data: {
|
||||||
items: [],
|
items: [],
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,3 +1,5 @@
|
||||||
module github.com/ofabricio/capture
|
module github.com/ofabricio/capture
|
||||||
|
|
||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
|
require gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -0,0 +1,2 @@
|
||||||
|
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||||
|
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
15
main.go
15
main.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"crypto/tls"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -30,12 +31,13 @@ var dashboardHTML []byte
|
||||||
func main() {
|
func main() {
|
||||||
cfg := ReadConfig()
|
cfg := ReadConfig()
|
||||||
|
|
||||||
fmt.Printf("\nListening on http://localhost:%s", cfg.ProxyPort)
|
fmt.Printf("Target is %s\n", cfg.TargetURL)
|
||||||
fmt.Printf("\nDashboard on http://localhost:%s", cfg.DashboardPort)
|
fmt.Printf("Listening on http://127.0.0.1:%s\n", cfg.ProxyPort)
|
||||||
|
fmt.Printf("Dashboard on http://127.0.0.1:%s\n", cfg.DashboardPort)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
srv := NewCaptureService(cfg.MaxCaptures)
|
srv := NewCaptureService(cfg.MaxCaptures)
|
||||||
hdr := NewRecorderHandler(srv, NewPluginHandler(NewProxyHandler(cfg.TargetURL)))
|
hdr := NewRecorderHandler(srv, NewPluginHandler(NewProxyHandler(cfg.TargetURL, cfg.TLSSkipVerify)))
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
fmt.Println(http.ListenAndServe(":"+cfg.DashboardPort, NewDashboardHandler(hdr, srv, cfg)))
|
fmt.Println(http.ListenAndServe(":"+cfg.DashboardPort, NewDashboardHandler(hdr, srv, cfg)))
|
||||||
|
@ -229,9 +231,14 @@ func NewRecorderHandler(srv *CaptureService, next http.HandlerFunc) http.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewProxyHandler is the reverse proxy handler.
|
// NewProxyHandler is the reverse proxy handler.
|
||||||
func NewProxyHandler(URL string) http.HandlerFunc {
|
func NewProxyHandler(URL string, TLSSkipVerify bool) http.HandlerFunc {
|
||||||
url, _ := url.Parse(URL)
|
url, _ := url.Parse(URL)
|
||||||
proxy := httputil.NewSingleHostReverseProxy(url)
|
proxy := httputil.NewSingleHostReverseProxy(url)
|
||||||
|
insecureTransport := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: TLSSkipVerify},
|
||||||
|
}
|
||||||
|
proxy.Transport = insecureTransport
|
||||||
|
|
||||||
proxy.ErrorHandler = func(rw http.ResponseWriter, req *http.Request, err error) {
|
proxy.ErrorHandler = func(rw http.ResponseWriter, req *http.Request, err error) {
|
||||||
fmt.Printf("Uh oh | %v | %s %s\n", err, req.Method, req.URL)
|
fmt.Printf("Uh oh | %v | %s %s\n", err, req.Method, req.URL)
|
||||||
rw.WriteHeader(StatusInternalProxyError)
|
rw.WriteHeader(StatusInternalProxyError)
|
||||||
|
|
|
@ -22,7 +22,7 @@ func TestProxyHandler(t *testing.T) {
|
||||||
for _, tc := range tt {
|
for _, tc := range tt {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
service := httptest.NewServer(http.HandlerFunc(tc.service))
|
service := httptest.NewServer(http.HandlerFunc(tc.service))
|
||||||
capture := httptest.NewServer(NewProxyHandler(service.URL))
|
capture := httptest.NewServer(NewProxyHandler(service.URL, false))
|
||||||
|
|
||||||
// when
|
// when
|
||||||
resp := tc.request(capture.URL)
|
resp := tc.request(capture.URL)
|
||||||
|
|
Loading…
Reference in a new issue