Skip to content
This repository has been archived by the owner on Oct 10, 2019. It is now read-only.

Commit

Permalink
add first prototype.
Browse files Browse the repository at this point in the history
  • Loading branch information
akrennmair committed Jul 4, 2012
1 parent 3c5401f commit bc9f359
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SRC := $(wildcard *.go)
TARGET := hipsterd

all: $(TARGET)

$(TARGET): $(SRC)
go build -o $@

clean:
$(RM) $(TARGET)

.PHONY: clean
52 changes: 52 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"net/http"
"log"
"io"
"os"
"fmt"
)

func HandleRequest(w http.ResponseWriter, r *http.Request) {
log.Printf("incoming request: %#v", *r)
log.Printf("URL: %#v", *r.URL)
client := &http.Client{}
r.RequestURI = ""
r.URL.Scheme = "http"
r.URL.Host = "127.0.0.1:8000"

resp, err := client.Do(r)
if err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
fmt.Fprintf(w, "Error: %v", err)
return
}

for k, v := range resp.Header {
for _, vv := range v {
w.Header().Add(k, vv)
}
}

w.WriteHeader(resp.StatusCode)

io.Copy(w, resp.Body)
resp.Body.Close()
}

func main() {
listen_addr := ":9000"

mux := http.NewServeMux()
mux.HandleFunc("/", HandleRequest)

srv := &http.Server{Handler: mux, Addr: listen_addr}

err := srv.ListenAndServe()

if err != nil {
log.Printf("ListenAndServe: %v", err)
os.Exit(1)
}
}

0 comments on commit bc9f359

Please sign in to comment.