1
0
Fork 0
forked from boyska/circolog

[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" "net/url"
"os" "os"
"os/signal" "os/signal"
"strconv"
"time" "time"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
@ -16,6 +17,7 @@ import (
func main() { func main() {
addr := flag.String("addr", "localhost:9080", "http service address") addr := flag.String("addr", "localhost:9080", "http service address")
querySocket := flag.String("socket", "", "Path to a unix domain socket for the HTTP server") 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() flag.Parse()
interrupt := make(chan os.Signal, 1) interrupt := make(chan os.Signal, 1)
@ -25,6 +27,11 @@ func main() {
Host: *addr, // ignored in case of -socket; see the Dialer below Host: *addr, // ignored in case of -socket; see the Dialer below
Path: "/ws", Path: "/ws",
} }
q := u.Query()
if *backlogLimit >= 0 {
q.Set("l", strconv.Itoa(*backlogLimit))
}
u.RawQuery = q.Encode()
if *querySocket != "" { if *querySocket != "" {
d = &websocket.Dialer{ d = &websocket.Dialer{
NetDial: func(network, addr string) (net.Conn, error) { 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) { func parseParameterL(r *http.Request) (int, error) {
var requestMessageLen int var requestMessageLen int = -1
var err error var err error
if reqL, ok := r.Form["l"]; ok { if reqL, ok := r.Form["l"]; ok {
if len(reqL) == 1 { 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) { func parseParameters(w http.ResponseWriter, r *http.Request) (circolog.ClientOptions, error) {
var opts circolog.ClientOptions var opts circolog.ClientOptions
opts.BacklogLength = 10 // default
err := r.ParseForm() err := r.ParseForm()
if err != nil { if err != nil {
log.Println("error parsing http request", err) log.Println("error parsing http request", err)
@ -83,12 +82,20 @@ func getWSHandler(hub circolog.Hub) http.HandlerFunc {
WriteBufferSize: 1024, WriteBufferSize: 1024,
} }
return func(w http.ResponseWriter, r *http.Request) { 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) conn, err := upgrader.Upgrade(w, r, nil)
if err != nil { if err != nil {
return return
} }
client := circolog.Client{Messages: make(chan format.LogParts, 20), client := circolog.Client{
Options: circolog.ClientOptions{BacklogLength: -1}, Messages: make(chan format.LogParts, 20),
Options: opts,
} }
hub.Register <- client hub.Register <- client