-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"sort" | ||
"flag" | ||
"strings" | ||
"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) | ||
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]) | ||
} | ||
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 main() { | ||
http.HandleFunc("/", headers) | ||
http.HandleFunc("/", headers) | ||
|
||
var host = flag.String("host", "", "host to run on") | ||
var port = flag.String("port", "8080", "port to run on") | ||
var host = flag.String("host", "", "host to run on") | ||
var port = flag.String("port", "8080", "port to run on") | ||
|
||
flag.Parse() | ||
flag.Parse() | ||
|
||
var address = strings.Join([]string{*host, *port}, ":") | ||
var address = strings.Join([]string{*host, *port}, ":") | ||
|
||
log.Printf("Starting instance %s server at %s", *Name, address) | ||
http.ListenAndServe(address, nil) | ||
log.Printf("Starting instance %s server at %s", *Name, address) | ||
http.ListenAndServe(address, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters