diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..318e671 Binary files /dev/null and b/.DS_Store differ diff --git a/Client/.DS_Store b/Client/.DS_Store new file mode 100644 index 0000000..9e8f77d Binary files /dev/null and b/Client/.DS_Store differ diff --git a/Client/Client.go b/Client/Client.go new file mode 100644 index 0000000..a37dbbc --- /dev/null +++ b/Client/Client.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "log" + "net/http" + "net/http/httputil" +) + +func main() { + url := "http://10.50.0.129:9999/hi" + req, _ := http.NewRequest("GET", url, nil) + res, err := http.Head(url) + res.Header.Set("Hello", "BasicHTTP!") + if err != nil { + log.Fatal(err) + } + + dumpRes, _ := httputil.DumpResponse(res, true) + fmt.Printf("%s", dumpRes) + + dump, _ := httputil.DumpRequestOut(req, true) + fmt.Printf("%s", dump) + +} \ No newline at end of file diff --git a/Curl.md b/Curl.md index ce6f29d..addb29a 100644 --- a/Curl.md +++ b/Curl.md @@ -1 +1,10 @@ # Please show HTTP Request and Response using curl command + + +toukaininnoMacBook-Pro% curl -i http://10.50.0.129:9999/hi +HTTP/1.1 200 OK +Date: Wed, 10 Jun 2020 18:40:05 GMT +Content-Length: 12 +Content-Type: text/plain; charset=utf-8 + +10.50.0.129 \ No newline at end of file diff --git a/README.md b/README.md index 99b6488..1f3606e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ # Exp3BasicHttp For Labo of Basic HTTP for Exp3 of Univ +## Mission + +1. show Server Directory README.md +2. show Client Directory README.md +2. show Curl.md + ## Setup 1. access 'https://github.com/Hardw01f/Exp3BasicHttp' diff --git a/Server/.DS_Store b/Server/.DS_Store new file mode 100644 index 0000000..7579756 Binary files /dev/null and b/Server/.DS_Store differ diff --git a/Server/README.md b/Server/README.md index 27b8f2a..572e856 100644 --- a/Server/README.md +++ b/Server/README.md @@ -1,5 +1,7 @@ # Please write code of simple HTTP(Web) server +write this directory + ## Specification - write by using favorit language @@ -7,3 +9,16 @@ - listen the API '/hi' - return your IP address in Response Body - return 'Hello: BasicHTTP!' Header in Response Header + +## Response Exsample + +``` +HTTP/1.1 200 OK +Hello: BasicHTTP! +Date: Tue, 26 May 2020 06:53:14 GMT +Content-Length: 13 +Content-Type: text/plain; charset=utf-8 + +10.10.11.194 + +``` diff --git a/Server/Server.go b/Server/Server.go new file mode 100644 index 0000000..127106e --- /dev/null +++ b/Server/Server.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + "net" + "net/http" +) + +func getipv4 (w http.ResponseWriter, r *http.Request){ + addrs, _ := net.InterfaceAddrs() + for _, addr := range addrs { + if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback(){ + if ipnet.IP.To4() != nil { + fmt.Fprintln(w, ipnet.IP.String()) + break + } + } + } +} + +func main() { + http.HandleFunc("/hi", getipv4) + http.ListenAndServe(":9999",nil) +} \ No newline at end of file