xref: /unit/test/go/variables/app.go (revision 2592:e079c44a8340)
1package main
2
3import (
4	"fmt"
5	"io"
6	"net/http"
7	"unit.nginx.org/go"
8)
9
10func handler(w http.ResponseWriter, r *http.Request) {
11	var buf [4096]byte
12	len, _ := r.Body.Read(buf[:])
13
14	w.Header().Set("Request-Method", r.Method)
15	w.Header().Set("Request-Uri", r.RequestURI)
16	w.Header().Set("Server-Protocol", r.Proto)
17	w.Header().Set("Server-Protocol-Major", fmt.Sprintf("%v", r.ProtoMajor))
18	w.Header().Set("Server-Protocol-Minor", fmt.Sprintf("%v", r.ProtoMinor))
19	w.Header().Set("Content-Length", fmt.Sprintf("%v", len))
20	w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
21	w.Header().Set("Custom-Header", r.Header.Get("Custom-Header"))
22	w.Header().Set("Http-Host", r.Header.Get("Host"))
23
24	io.WriteString(w, string(buf[:len]))
25}
26
27func main() {
28	http.HandleFunc("/", handler)
29	unit.ListenAndServe(":8080", nil)
30}
31