[http][ctail] n parameter also on circolog-tails

This commit is contained in:
Blallo 2018-11-09 11:21:50 +01:00
parent 499c90ccda
commit a0b57e1a78
No known key found for this signature in database
GPG key ID: 0CBE577C9B72DC3F
2 changed files with 18 additions and 4 deletions

View file

@ -8,6 +8,7 @@ import (
"net/url"
"os"
"os/signal"
"strconv"
"time"
"github.com/gorilla/websocket"
@ -16,6 +17,7 @@ import (
func main() {
addr := flag.String("addr", "localhost:9080", "http service address")
querySocket := flag.String("socket", "", "Path to a unix domain socket for the HTTP server")
backlogLimit := flag.Int("n", -1, "Limit the backlog length, defaults to no limit (-1)")
flag.Parse()
interrupt := make(chan os.Signal, 1)
@ -25,6 +27,11 @@ func main() {
Host: *addr, // ignored in case of -socket; see the Dialer below
Path: "/ws",
}
q := u.Query()
if *backlogLimit >= 0 {
q.Set("l", strconv.Itoa(*backlogLimit))
}
u.RawQuery = q.Encode()
if *querySocket != "" {
d = &websocket.Dialer{
NetDial: func(network, addr string) (net.Conn, error) {

View file

@ -18,7 +18,7 @@ func setupHTTP(hub circolog.Hub) {
}
func parseParameterL(r *http.Request) (int, error) {
var requestMessageLen int
var requestMessageLen int = -1
var err error
if reqL, ok := r.Form["l"]; ok {
if len(reqL) == 1 {
@ -38,7 +38,6 @@ func parseParameterL(r *http.Request) (int, error) {
func parseParameters(w http.ResponseWriter, r *http.Request) (circolog.ClientOptions, error) {
var opts circolog.ClientOptions
opts.BacklogLength = 10 // default
err := r.ParseForm()
if err != nil {
log.Println("error parsing http request", err)
@ -83,12 +82,20 @@ func getWSHandler(hub circolog.Hub) http.HandlerFunc {
WriteBufferSize: 1024,
}
return func(w http.ResponseWriter, r *http.Request) {
opts, err := parseParameters(w, r)
if err != nil {
log.Println("Error on request parameter \"l\":", err)
w.WriteHeader(400)
return
}
opts.Nofollow = false
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
return
}
client := circolog.Client{Messages: make(chan format.LogParts, 20),
Options: circolog.ClientOptions{BacklogLength: -1},
client := circolog.Client{
Messages: make(chan format.LogParts, 20),
Options: opts,
}
hub.Register <- client