Explorar el Código

Sort headers in YAML output

Lu Stadler %!s(int64=7) %!d(string=hace) años
padre
commit
beccb991f6
Se han modificado 2 ficheros con 17 adiciones y 0 borrados
  1. 9 0
      go/fake-http/README.md
  2. 8 0
      go/fake-http/fake-http.go

+ 9 - 0
go/fake-http/README.md

@ -4,6 +4,15 @@
4 4
5 5
## TODO
6 6
7
- replay from log instantly (i.e. operate like a request cache)
8
    - ensure every request is cached max once?  at least in the response
9
      defn?
10
    - make it possible to download the cache
11
        - /_cache, analogous to /_log?
12
        - or reuse /_log, which wouldn't need new code, but would make
13
          it impossible to download the log.  damn...
14
            - how about /_log?cache=true?
15
            - or make /_log redirect to /_cache if `-cache` is enabled
7 16
- /_clear endpoint
8 17
- some kind of templating (request info + random functions?)
9 18
- lua integration? ;)

+ 8 - 0
go/fake-http/fake-http.go

@ -15,6 +15,7 @@ import (
15 15
	"os"
16 16
	"os/exec"
17 17
	"path"
18
	"sort"
18 19
	"strings"
19 20
	"time"
20 21
@ -278,6 +279,12 @@ type LogEntry struct {
278 279
	responseBody *bytes.Buffer
279 280
}
280 281
282
type byHeaderName []Header
283
284
func (hs byHeaderName) Len() int           { return len(hs) }
285
func (hs byHeaderName) Swap(i, j int)      { hs[i], hs[j] = hs[j], hs[i] }
286
func (hs byHeaderName) Less(i, j int) bool { return hs[i].Name < hs[j].Name }
287
281 288
// AsResponse returns a Response representation of the entry.
282 289
func (e LogEntry) AsResponse() Response {
283 290
	headers := make([]Header, 0, len(e.response.Header))
@ -286,6 +293,7 @@ func (e LogEntry) AsResponse() Response {
286 293
			headers = append(headers, Header{Name: name, Value: val})
287 294
		}
288 295
	}
296
	sort.Sort(byHeaderName(headers))
289 297
	return Response{
290 298
		Method:  e.request.Method,
291 299
		Path:    e.request.URL.Path,