Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions http-to-https-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package main

import (
"crypto/tls"
"fmt"
"io"
"log"
"net/http"
"net/http/httputil"
"os"
"strconv"
"time"
)

var versionCode = "v0.3"
Expand Down Expand Up @@ -76,6 +78,8 @@ func handler(responseToRequest http.ResponseWriter, incomingRequest *http.Reques

defer returnConn.Close()

conn.SetDeadline(time.Now().Add(3 * time.Second))

readBuf := make([]byte, proxyBufferSize)

for {
Expand Down Expand Up @@ -106,6 +110,8 @@ func handler(responseToRequest http.ResponseWriter, incomingRequest *http.Reques

log.Println("End of handler")

io.WriteString(responseToRequest, "I am slow!\n")

}

func main() {
Expand Down Expand Up @@ -158,4 +164,14 @@ func main() {
if err := http.ListenAndServe(":"+strconv.Itoa(httpListenPort), nil); err != nil {
log.Fatal(err)
}

srv := http.Server{
Addr: ":" + strconv.Itoa(httpListenPort),
WriteTimeout: 5 * time.Second,
Handler: http.TimeoutHandler(http.HandlerFunc(handler), 1*time.Second, "Timeout!\n"),
}

if err := srv.ListenAndServe(); err != nil {
fmt.Printf("Server failed: %s\n", err)
}
}