mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-09 00:00:03 +01:00
add echo server from http://www.gopl.io as test for Go's IP stack
This commit is contained in:
parent
70f92265ab
commit
78bfdc07bd
3 changed files with 54 additions and 3 deletions
1
hermit/.gitignore
vendored
1
hermit/.gitignore
vendored
|
@ -19,6 +19,7 @@ usr/tests/thr_hello
|
|||
usr/tests/pi
|
||||
usr/tests/RCCE_minimum
|
||||
usr/tests/signals
|
||||
usr/tests/server
|
||||
usr/benchmarks/RCCE_pingping
|
||||
usr/benchmarks/RCCE_pingpong
|
||||
usr/benchmarks/stream
|
||||
|
|
|
@ -49,7 +49,7 @@ endif
|
|||
|
||||
default: all
|
||||
|
||||
all: hello hello++ thr_hello jacobi hellof RCCE_minimum signals pi
|
||||
all: hello hello++ thr_hello jacobi hellof RCCE_minimum signals pi server
|
||||
|
||||
hello++: hello++.o
|
||||
@echo [LD] $@
|
||||
|
@ -79,6 +79,13 @@ pi: pi.o
|
|||
$Q$(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $@
|
||||
$Qchmod a-x $@.sym
|
||||
|
||||
server: server.o
|
||||
@echo [LD] $@
|
||||
$Q$(GO_FOR_TARGET) -pthread -o $@ $< $(LDFLAGS_FOR_TARGET) $(GOFLAGS_FOR_TARGET) -lnetgo
|
||||
$Q$(OBJCOPY_FOR_TARGET) $(KEEP_DEBUG) $@ $@.sym
|
||||
$Q$(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $@
|
||||
$Qchmod a-x $@.sym
|
||||
|
||||
jacobi: jacobi.o
|
||||
@echo [LD] $@
|
||||
$Q$(CC_FOR_TARGET) -o $@ $< $(LDFLAGS_FOR_TARGET) $(CFLAGS_FOR_TARGET)
|
||||
|
@ -117,11 +124,11 @@ RCCE_minimum: RCCE_minimum.o
|
|||
|
||||
clean:
|
||||
@echo Cleaning tests
|
||||
$Q$(RM) hello hello++ hellof jacobi thr_hello RCCE_minimum signals pi *.sym *.o *~
|
||||
$Q$(RM) hello hello++ hellof jacobi thr_hello RCCE_minimum signals pi server *.sym *.o *~
|
||||
|
||||
veryclean:
|
||||
@echo Propper cleaning tests
|
||||
$Q$(RM) hello hello++ hellof jacobi thr_hello RCCE_minimum pi *.sym *.o *~
|
||||
$Q$(RM) hello hello++ hellof jacobi thr_hello RCCE_minimum pi server *.sym *.o *~
|
||||
|
||||
depend:
|
||||
$Q$(CC_FOR_TARGET) -MM $(CFLAGS_FOR_TARGET) *.c > Makefile.dep
|
||||
|
|
43
hermit/usr/tests/server.go
Normal file
43
hermit/usr/tests/server.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
|
||||
// The original code was published at http://www.gopl.io, see page 21.
|
||||
|
||||
// This is an "echo" server that displays request parameters.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("This is an \"echo\" server that displays request parameters.")
|
||||
fmt.Println("Start the server and send a http request to it (e.g. curl http://localhost:8000/help).")
|
||||
fmt.Println("The server uses port 8000. Please open the port by setting the")
|
||||
fmt.Println("environment variable HERMIT_APP_PORT to 8000.")
|
||||
|
||||
http.HandleFunc("/", handler)
|
||||
log.Fatal(http.ListenAndServe(":8000", nil))
|
||||
}
|
||||
|
||||
//!+handler
|
||||
// handler echoes the HTTP request.
|
||||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "%s %s %s\n", r.Method, r.URL, r.Proto)
|
||||
for k, v := range r.Header {
|
||||
fmt.Fprintf(w, "Header[%q] = %q\n", k, v)
|
||||
}
|
||||
fmt.Fprintf(w, "Host = %q\n", r.Host)
|
||||
fmt.Fprintf(w, "RemoteAddr = %q\n", r.RemoteAddr)
|
||||
if err := r.ParseForm(); err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
for k, v := range r.Form {
|
||||
fmt.Fprintf(w, "Form[%q] = %q\n", k, v)
|
||||
}
|
||||
}
|
||||
|
||||
//!-handler
|
Loading…
Add table
Reference in a new issue