diff --git a/.travis.yml b/.travis.yml index 69dedd0..d6851f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: - - 1.7.5 - - 1.8.3 + - 1.10.x + - tip os: - linux # remove osx, getting vm from travis is extremely slow diff --git a/README.md b/README.md index 26d15ca..473bbd9 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ $ go get github.com/asciimoo/wuzz $ "$GOPATH/bin/wuzz" --help ``` -Note: golang >= 1.7 required. +Note: golang >= 1.10 required. [Binary releases](https://github.com/asciimoo/wuzz/releases) are also available. diff --git a/wuzz.go b/wuzz.go index c16daf1..77a7383 100644 --- a/wuzz.go +++ b/wuzz.go @@ -715,6 +715,19 @@ func showAutocomplete(completions []string, left, top, maxWidth, maxHeight int, } } +func writeSortedHeaders(output io.Writer, h http.Header) { + hkeys := make([]string, 0, len(h)) + for hname := range h { + hkeys = append(hkeys, hname) + } + + sort.Strings(hkeys) + + for _, hname := range hkeys { + fmt.Fprintf(output, "\x1b[0;33m%v:\x1b[0;0m %v\n", hname, strings.Join(h[hname], ",")) + } +} + func (a *App) SubmitRequest(g *gocui.Gui, _ *gocui.View) error { vrb, _ := g.View(RESPONSE_BODY_VIEW) vrb.Clear() @@ -896,30 +909,33 @@ func (a *App) SubmitRequest(g *gocui.Gui, _ *gocui.View) error { a.PrintBody(g) - // print status code and sorted headers - hkeys := make([]string, 0, len(response.Header)) - for hname := range response.Header { - hkeys = append(hkeys, hname) - } - sort.Strings(hkeys) + // print status code status_color := 32 if response.StatusCode != 200 { status_color = 31 } - header_str := fmt.Sprintf( + header := &strings.Builder{} + fmt.Fprintf( + header, "\x1b[0;%dmHTTP/1.1 %v %v\x1b[0;0m\n", status_color, response.StatusCode, http.StatusText(response.StatusCode), ) - for _, hname := range hkeys { - header_str += fmt.Sprintf("\x1b[0;33m%v:\x1b[0;0m %v\n", hname, strings.Join(response.Header[hname], ",")) - } - fmt.Fprint(vrh, header_str) + + writeSortedHeaders(header, response.Header) + + // According to the Go documentation, the Trailer maps trailer + // keys to values in the same format as Header + writeSortedHeaders(header, response.Trailer) + + r.ResponseHeaders = header.String() + + fmt.Fprint(vrh, r.ResponseHeaders) if _, err := vrh.Line(0); err != nil { vrh.SetOrigin(0, 0) } - r.ResponseHeaders = header_str + return nil }) return nil