Lu Stadler лет назад: 7
Родитель
Сommit
beccb991f6
2 измененных файлов с 17 добавлено и 0 удалено
  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
4
5
## TODO
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
- /_clear endpoint
16
- /_clear endpoint
8
- some kind of templating (request info + random functions?)
17
- some kind of templating (request info + random functions?)
9
- lua integration? ;)
18
- lua integration? ;)

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

15
	"os"
15
	"os"
16
	"os/exec"
16
	"os/exec"
17
	"path"
17
	"path"
18
	"sort"
18
	"strings"
19
	"strings"
19
	"time"
20
	"time"
20
21
278
	responseBody *bytes.Buffer
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
// AsResponse returns a Response representation of the entry.
288
// AsResponse returns a Response representation of the entry.
282
func (e LogEntry) AsResponse() Response {
289
func (e LogEntry) AsResponse() Response {
283
	headers := make([]Header, 0, len(e.response.Header))
290
	headers := make([]Header, 0, len(e.response.Header))
286
			headers = append(headers, Header{Name: name, Value: val})
293
			headers = append(headers, Header{Name: name, Value: val})
287
		}
294
		}
288
	}
295
	}
296
	sort.Sort(byHeaderName(headers))
289
	return Response{
297
	return Response{
290
		Method:  e.request.Method,
298
		Method:  e.request.Method,
291
		Path:    e.request.URL.Path,
299
		Path:    e.request.URL.Path,