feat: reverse post data if header Reserve is set to true
This commit is contained in:
parent
05dc6e83ed
commit
b3efc0043f
11
main.go
11
main.go
@ -72,6 +72,14 @@ func serve(l int) bool {
|
|||||||
return C.Get() < l
|
return C.Get() < l
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reverse returns a reversed byte array of c
|
||||||
|
func reverse(c []byte) []byte {
|
||||||
|
for i, j := 0, len(c)-1; i < j; i, j = i+1, j-1 {
|
||||||
|
c[i], c[j] = c[j], c[i]
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
// handler generates the echo server response
|
// handler generates the echo server response
|
||||||
func handler(l int) http.HandlerFunc {
|
func handler(l int) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -94,6 +102,9 @@ func handler(l int) http.HandlerFunc {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Error reading body", http.StatusBadRequest)
|
http.Error(w, "Error reading body", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
if r.Header.Get("Reverse") == "true" {
|
||||||
|
v = reverse(v)
|
||||||
|
}
|
||||||
fmt.Fprintf(w, "%s", v)
|
fmt.Fprintf(w, "%s", v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user