mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 01:08:31 +02:00
feat(http/h2c): h2c test server with a Dockerfile
- Implemented a basic HTTP/2 server that responds with "ok" to requests. - Updated dev.compose.yml to include a service for it
This commit is contained in:
18
cmd/h2c_test_server/Dockerfile
Normal file
18
cmd/h2c_test_server/Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
FROM golang:1.25.5-alpine AS builder
|
||||||
|
|
||||||
|
HEALTHCHECK NONE
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
COPY main.go ./
|
||||||
|
|
||||||
|
RUN go build -o h2c_test_server main.go
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
|
||||||
|
COPY --from=builder /src/h2c_test_server /app/run
|
||||||
|
|
||||||
|
USER 1001:1001
|
||||||
|
|
||||||
|
CMD ["/app/run"]
|
||||||
7
cmd/h2c_test_server/go.mod
Normal file
7
cmd/h2c_test_server/go.mod
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
module github.com/yusing/godoxy/cmd/h2c_test_server
|
||||||
|
|
||||||
|
go 1.25.5
|
||||||
|
|
||||||
|
require golang.org/x/net v0.48.0
|
||||||
|
|
||||||
|
require golang.org/x/text v0.32.0 // indirect
|
||||||
4
cmd/h2c_test_server/go.sum
Normal file
4
cmd/h2c_test_server/go.sum
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
|
||||||
|
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
|
||||||
|
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
|
||||||
|
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
|
||||||
26
cmd/h2c_test_server/main.go
Normal file
26
cmd/h2c_test_server/main.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"golang.org/x/net/http2"
|
||||||
|
"golang.org/x/net/http2/h2c"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Write([]byte("ok"))
|
||||||
|
})
|
||||||
|
|
||||||
|
server := &http.Server{
|
||||||
|
Addr: ":80",
|
||||||
|
Handler: h2c.NewHandler(handler, &http2.Server{}),
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("H2C server listening on :8080")
|
||||||
|
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||||
|
log.Fatalf("ListenAndServe: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -54,6 +54,15 @@ services:
|
|||||||
- USERS=user:$$2a$$10$$UdLYoJ5lgPsC0RKqYH/jMua7zIn0g9kPqWmhYayJYLaZQ/FTmH2/u # user:password
|
- USERS=user:$$2a$$10$$UdLYoJ5lgPsC0RKqYH/jMua7zIn0g9kPqWmhYayJYLaZQ/FTmH2/u # user:password
|
||||||
labels:
|
labels:
|
||||||
proxy.tinyauth.port: "3000"
|
proxy.tinyauth.port: "3000"
|
||||||
|
h2c_test_server:
|
||||||
|
build:
|
||||||
|
context: cmd/h2c_test_server
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: h2c_test
|
||||||
|
restart: unless-stopped
|
||||||
|
labels:
|
||||||
|
proxy.#1.scheme: h2c
|
||||||
|
proxy.#1.port: 80
|
||||||
configs:
|
configs:
|
||||||
parca:
|
parca:
|
||||||
content: |
|
content: |
|
||||||
|
|||||||
Reference in New Issue
Block a user