<file_sep>FROM golang:1.19-alpine as builder
COPY main.go .
ENV CGO_ENABLED=0
RUN go build -o /app main.go

FROM alpine
RUN apk add traceroute bind-tools curl
LABEL maintainer="github.com/bukowa"

# Define GOTRACEBACK to mark this container as using the Go language runtime
# for `skaffold debug` (https://skaffold.dev/docs/workflows/debug/).
ENV GOTRACEBACK=single
ENTRYPOINT ["./app"]
COPY --from=builder /app .

<file_sep>#!/bin/bash

trap "printf '\n' && trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT

set -x

# example docker:
# CMD="docker run --rm -i -p 9001:9001 <image> --port=9001" ./test.sh
exec 3< <(${CMD="go run . --port=9001"} 2>&1)
read <&3 line

set +x

if [[ $line =~ "Starting instance" ]]; then
  echo $line
  else
    exit 1
fi

RESULT=$(curl -s -H 'User-Agent:' -H 'Header1: header1' -H 'Header2: header2' localhost:9001)

WANT='Instance name: example
Accept: [*/*]
Header1: [header1]
Header2: [header2]
Host: [localhost:9001]'

printf "===\nResult:\n===\n$RESULT\n"; printf "===\nWant:\n===\n$WANT\n===\n";

if [[ "$RESULT" != "$WANT" ]]; then
  printf "test failed"; exit 1
  else
    echo "test passed"
fi

RESULT=$(curl -s -w "%{http_code}\n" "localhost:9001/livenessProbe")

if [[ "$RESULT" != 200 ]]; then
  printf "test failed"; exit 1
    else
      echo "test passed"
fi

RESULT=$(curl -s -w "%{http_code}\n" "localhost:9001/readinessProbe")

if [[ "$RESULT" != 200 ]]; then
  printf "test failed"; exit 1
    else
      echo "test passed"
fi
<file_sep>#!/bin/bash
set -eux

echo "Building docker image for git-cliff..."

GIT_CLIFF=$(docker build -q - <<EOF
  FROM ghcr.io/orhun/git-cliff/git-cliff:sha-0f38960
  WORKDIR /workdirvol
  ENTRYPOINT ["git-cliff"]
EOF
)

echo "Running docker image for git-cliff..."
docker run --rm \
  --volume="${PWD}:/workdirvol" \
  -u "$(id -u)" \
  "${GIT_CLIFF}" \
  "$@"
<file_sep>module github.com/bukowa/http-headers

go 1.19
<file_sep>
generate-changelog:
	./scripts/generate-changelog.sh

generate-changelog-ci:
	touch CHANGELOG.md CHANGELOG.LATEST.md \
	&& \
	./scripts/generate-changelog.sh \
	-u --prepend=CHANGELOG.md \
	--include-path "*.go" \
	--include-path "*.mod" \
	--include-path "*Dockerfile" \
	&& \
	./scripts/generate-changelog.sh \
	-u --output=CHANGELOG.LATEST.md \
	--include-path "*.go" \
	--include-path "*.mod" \
	--include-path "*Dockerfile"
<file_sep>```bash
helm repo add bukowa https://bukowa.github.io/charts
helm install headers bukowa/http-headers
```

```bash
Instance name: example
Accept: [text/html,application/xhtml+xml,<cut>]
Accept-Encoding: [gzip, deflate]
Accept-Language: [en-US,en;q=0.5]
Host: [local.proxy]
Upgrade-Insecure-Requests: [1]
User-Agent: [Mozilla/5.0 <cut>]
X-Forwarded-For: [10.42.0.0]
X-Forwarded-Host: [http.mydev]
X-Forwarded-Port: [80]
X-Forwarded-Proto: [http]
X-Forwarded-Scheme: [http]
X-Real-Ip: [10.42.0.0]
X-Request-Id: [fadecae356e5fadf40b9b5b4419402ee]
X-Scheme: [http]
```
<file_sep># Changelog

All notable changes to this project will be documented in this file.

## [1.2.0]

### Features

- Add `traceroute` `bind-tools` `curl` | ( [ Commit ](https://github.com/bukowa/http-headers/commit/6ad464cebceba1936f200859279a2d2da4b22e7a) )    

## [1.1.0]

### Features

- Add `livenessProbe` & `readinessProbe` ([#24](https://github.com/bukowa/http-headers/issues/24)) | ( [ Commit ](https://github.com/bukowa/http-headers/commit/a14d8fe9d03d039f28363196955c47807577908c) )    

## [1.0.0]

### Core

- add docker to dependabot.yml

Signed-off-by: bukowa <<EMAIL>>

- add Host header manually ([#10](https://github.com/bukowa/http-headers/issues/10))



### Miscellaneous Tasks

- add new ci jobs for docker builds & changelogs ([#19](https://github.com/bukowa/http-headers/issues/19))

### Testing

- test new Dockerfile!

Signed-off-by: bukowa <<EMAIL>>


<file_sep># Changelog

All notable changes to this project will be documented in this file.

## [1.2.0]

### Features

- Add `traceroute` `bind-tools` `curl` | ( [ Commit ](https://github.com/bukowa/http-headers/commit/6ad464cebceba1936f200859279a2d2da4b22e7a) )    

<!-- generated by git-cliff -->
<file_sep>package main

import (
	"flag"
	"fmt"
	"log"
	"net/http"
	"sort"
	"strings"
)

var Name = flag.String("name", "example", "name of instance")

func headers(w http.ResponseWriter, req *http.Request) {
	log.Println("Hello! There's a request incoming!")
	log.Printf("%v %v %v %v", req.RemoteAddr, req.URL, req.Host, req.Header)

	// For incoming requests, the Host header is promoted to the
	// Request.Host field and removed from the Header map.
	req.Header.Set("host", req.Host)
	sortedKeys := make([]string, 0, len(req.Header))

	fmt.Fprintf(w, "Instance name: %s\n", *Name)
	for name, _ := range req.Header {
		sortedKeys = append(sortedKeys, name)
	}
	sort.Strings(sortedKeys)
	for _, v := range sortedKeys {
		fmt.Fprintf(w, "%v: %v\n", v, req.Header[v])
	}
}

func livenessProbe(w http.ResponseWriter, req *http.Request) {
	w.WriteHeader(200)
}

func readinessProbe(w http.ResponseWriter, req *http.Request) {
	w.WriteHeader(200)
}

func main() {
	http.HandleFunc("/livenessProbe", livenessProbe)
	http.HandleFunc("/readinessProbe", readinessProbe)
	http.HandleFunc("/", headers)

	var host = flag.String("host", "", "host to run on")
	var port = flag.String("port", "8080", "port to run on")

	flag.Parse()

	var address = strings.Join([]string{*host, *port}, ":")

	log.Printf("Starting instance %s server at %s", *Name, address)
	http.ListenAndServe(address, nil)
}
