mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Remove magic numbers
This commit is contained in:
+1
-1
@@ -61,7 +61,7 @@ func (i *FileInput) emit() {
|
||||
buf := scanner.Bytes()
|
||||
meta := payloadMeta(buf)
|
||||
|
||||
if meta[0][0] == '1' && lastTime != 0 {
|
||||
if meta[0][0] == RequestPayload && lastTime != 0 {
|
||||
ts, _ := strconv.ParseInt(string(meta[2]), 10, 64)
|
||||
timeDiff := ts - lastTime
|
||||
|
||||
|
||||
+2
-2
@@ -72,12 +72,12 @@ func TestInputRAW100Expect(t *testing.T) {
|
||||
// We will use it to get content of raw HTTP request
|
||||
testOutput := NewTestOutput(func(data []byte) {
|
||||
switch data[0] {
|
||||
case '1':
|
||||
case RequestPayload:
|
||||
if strings.Contains(string(data), "Expect: 100-continue") {
|
||||
t.Error("Should not contain 100-continue header")
|
||||
}
|
||||
wg.Done()
|
||||
case '2':
|
||||
case ResponsePayload:
|
||||
wg.Done()
|
||||
}
|
||||
})
|
||||
|
||||
+7
-15
@@ -8,9 +8,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
RequestPayload = 1 << iota
|
||||
ResponsePayload
|
||||
ReplayedResponsePayload
|
||||
RequestPayload = '1'
|
||||
ResponsePayload = '2'
|
||||
ReplayedResponsePayload = '3'
|
||||
)
|
||||
|
||||
func uuid() []byte {
|
||||
@@ -43,26 +43,18 @@ func payloadScanner(data []byte, atEOF bool) (advance int, token []byte, err err
|
||||
|
||||
|
||||
// Timing is request start or round-trip time, depending on payloadType
|
||||
func payloadHeader(payloadType int, uuid []byte, timing int64) (header []byte) {
|
||||
func payloadHeader(payloadType byte, uuid []byte, timing int64) (header []byte) {
|
||||
sTime := strconv.FormatInt(timing, 10)
|
||||
|
||||
//Example:
|
||||
// 3 f45590522cd1838b4a0d5c5aab80b77929dea3b3 1231\n
|
||||
// `+ 1` indicates space characters or end of line
|
||||
header = make([]byte, 1+1+len(uuid)+1+len(sTime)+1)
|
||||
header[0] = payloadType
|
||||
header[1] = ' '
|
||||
header[2+len(uuid)] = ' '
|
||||
header[len(header)-1] = '\n'
|
||||
|
||||
switch payloadType {
|
||||
case RequestPayload:
|
||||
header[0] = '1'
|
||||
case ResponsePayload:
|
||||
header[0] = '2'
|
||||
case ReplayedResponsePayload:
|
||||
header[0] = '3'
|
||||
}
|
||||
|
||||
copy(header[2:], uuid)
|
||||
copy(header[3+len(uuid):], sTime)
|
||||
|
||||
@@ -81,7 +73,7 @@ func payloadMeta(payload []byte) [][]byte {
|
||||
|
||||
func isOriginPayload(payload []byte) bool {
|
||||
switch payload[0] {
|
||||
case '1', '2':
|
||||
case RequestPayload, ResponsePayload:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
@@ -89,5 +81,5 @@ func isOriginPayload(payload []byte) bool {
|
||||
}
|
||||
|
||||
func isRequestPayload(payload []byte) bool {
|
||||
return payload[0] == '1'
|
||||
return payload[0] == RequestPayload
|
||||
}
|
||||
Reference in New Issue
Block a user