Changeset 4 in code for trunk


Ignore:
Timestamp:
Oct 17, 2016, 11:26:20 PM (9 years ago)
Author:
asciimoo
Message:

[enh] add request timeout

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/morty.go

    r3 r4  
    1515        "regexp"
    1616        "strings"
     17        "time"
    1718
    1819        "github.com/valyala/fasthttp"
     
    9596
    9697type Proxy struct {
    97         Key []byte
     98        Key            []byte
     99        RequestTimeout time.Duration
    98100}
    99101
     
    112114</div>
    113115<style>
    114 #mortyheader { position: fixed; top: 15%%; left: 0; max-width: 10em; color: #444; overflow: hidden; z-index: 1000; }
     116#mortyheader { position: fixed; top: 15%%; left: 0; max-width: 10em; color: #444; overflow: hidden; z-index: 110000; }
    115117#mortyheader a { color: #3498db; }
    116118#mortyheader div { padding: 8px; font-size: 0.9em; border-width: 4px 4px 4px 0; border-style: solid; border-color: #3498db; background: #FFF; }
     
    169171        }
    170172
    171         if p.breakOnError(ctx, CLIENT.Do(req, resp)) {
     173        if p.breakOnError(ctx, CLIENT.DoTimeout(req, resp, p.RequestTimeout)) {
    172174                return
    173175        }
     
    516518                return false
    517519        }
     520        log.Println("error:", err)
    518521        ctx.SetStatusCode(404)
    519522        ctx.SetContentType("text/html")
     
    543546        listen := flag.String("listen", "127.0.0.1:3000", "Listen address")
    544547        key := flag.String("key", "", "HMAC url validation key (hexadecimal encoded) - leave blank to disable")
     548        requestTimeout := flag.Uint("timeout", 2, "Request timeout")
    545549        flag.Parse()
    546550
    547         p := &Proxy{}
     551        p := &Proxy{RequestTimeout: time.Duration(*requestTimeout) * time.Second}
    548552
    549553        if *key != "" {
Note: See TracChangeset for help on using the changeset viewer.