Last active
October 19, 2017 07:03
-
-
Save siadat/0e18be6f246a58f879cdcedb5fc7cf10 to your computer and use it in GitHub Desktop.
Chunked Response
This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "net/http" | |
| "time" | |
| ) | |
| // Test with: | |
| // curl -N localhost:9090 | |
| func main() { | |
| http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
| flusher, ok := w.(http.Flusher) | |
| if !ok { | |
| w.WriteHeader(http.StatusInternalServerError) | |
| return | |
| } | |
| for i := 0; i < 10; i++ { | |
| time.Sleep(200 * time.Millisecond) | |
| w.Write([]byte(fmt.Sprintf("chunk %d", i))) | |
| flusher.Flush() | |
| } | |
| }) | |
| log.Println("starting on :9090") | |
| log.Fatal(http.ListenAndServe(":9090", nil)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment