Skip to content

Commit c81caa0

Browse files
kapishmaliktommysitu
authored andcommitted
review comment changes
1 parent cd8a005 commit c81caa0

File tree

9 files changed

+36
-14
lines changed

9 files changed

+36
-14
lines changed

core/handlers/v2/views.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type ModeArgumentsView struct {
3939
Stateful bool `json:"stateful,omitempty"`
4040
OverwriteDuplicate bool `json:"overwriteDuplicate,omitempty"`
4141
CaptureOnMiss bool `json:"captureOnMiss,omitempty"`
42+
CaptureDelay bool `json:"captureDelay,omitempty"`
4243
}
4344

4445
type IsWebServerView struct {

core/hoverfly_funcs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func (hf *Hoverfly) DoRequest(request *http.Request) (*http.Response, *time.Dura
3131
}
3232
start := time.Now()
3333
resp, err := client.Do(request)
34+
elapsed := time.Since(start)
3435

3536
if err != nil {
3637
return nil, nil, err
@@ -42,7 +43,6 @@ func (hf *Hoverfly) DoRequest(request *http.Request) (*http.Response, *time.Dura
4243
resp.Header.Add("Hoverfly", "Forwarded")
4344
}
4445

45-
elapsed := time.Since(start)
4646
return resp, &elapsed, nil
4747
}
4848

core/hoverfly_service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func (hf *Hoverfly) SetModeWithArguments(modeView v2.ModeView) error {
109109
Stateful: modeView.Arguments.Stateful,
110110
OverwriteDuplicate: modeView.Arguments.OverwriteDuplicate,
111111
CaptureOnMiss: modeView.Arguments.CaptureOnMiss,
112+
CaptureDelay: modeView.Arguments.CaptureDelay,
112113
}
113114

114115
hf.modeMap[hf.Cfg.GetMode()].SetArguments(modeArguments)

core/modes/capture_mode.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func (this *CaptureMode) View() v2.ModeView {
3131
Headers: this.Arguments.Headers,
3232
Stateful: this.Arguments.Stateful,
3333
OverwriteDuplicate: this.Arguments.OverwriteDuplicate,
34+
CaptureDelay: this.Arguments.CaptureDelay,
3435
},
3536
}
3637
}
@@ -68,11 +69,16 @@ func (this CaptureMode) Process(request *http.Request, details models.RequestDet
6869
respBody, _ := util.GetResponseBody(response)
6970
respHeaders := util.GetResponseHeaders(response)
7071

72+
delayInMs := 0
73+
if this.Arguments.CaptureDelay {
74+
delayInMs = int(duration.Milliseconds())
75+
}
76+
7177
responseObj := &models.ResponseDetails{
7278
Status: response.StatusCode,
7379
Body: respBody,
7480
Headers: respHeaders,
75-
FixedDelay: int(duration.Milliseconds()),
81+
FixedDelay: delayInMs,
7682
}
7783

7884
if this.Arguments.Headers == nil {

core/modes/diff_mode.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (this *DiffMode) Process(request *http.Request, details models.RequestDetai
6060
return ReturnErrorAndLog(request, err, &actualPair, "There was an error when reconstructing the request.", Diff)
6161
}
6262

63-
actualResponse, duration, err := this.Hoverfly.DoRequest(modifiedRequest)
63+
actualResponse, _, err := this.Hoverfly.DoRequest(modifiedRequest)
6464
if err != nil {
6565
return ReturnErrorAndLog(request, err, &actualPair, "There was an error when forwarding the request to the intended destination", Diff)
6666
}
@@ -74,10 +74,9 @@ func (this *DiffMode) Process(request *http.Request, details models.RequestDetai
7474
respHeaders := util.GetResponseHeaders(actualResponse)
7575

7676
actualResponseDetails := &models.ResponseDetails{
77-
Status: actualResponse.StatusCode,
78-
Body: respBody,
79-
Headers: respHeaders,
80-
FixedDelay: int(duration.Milliseconds()),
77+
Status: actualResponse.StatusCode,
78+
Body: respBody,
79+
Headers: respHeaders,
8180
}
8281

8382
this.diffResponse(simResponse, actualResponseDetails, this.Arguments.Headers)

core/modes/modes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type ModeArguments struct {
4646
Stateful bool
4747
OverwriteDuplicate bool
4848
CaptureOnMiss bool
49+
CaptureDelay bool
4950
}
5051

5152
type ProcessResult struct {

core/modes/modify_mode.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (this ModifyMode) Process(request *http.Request, details models.RequestDeta
3737
return ReturnErrorAndLog(request, err, &pair, "There was an error when rebuilding the modified http request", Modify)
3838
}
3939

40-
resp, duration, err := this.Hoverfly.DoRequest(modifiedRequest)
40+
resp, _, err := this.Hoverfly.DoRequest(modifiedRequest)
4141
if err != nil {
4242
return ReturnErrorAndLog(request, err, &pair, "There was an error when forwarding the request to the intended destination", Modify)
4343
}
@@ -48,10 +48,9 @@ func (this ModifyMode) Process(request *http.Request, details models.RequestDeta
4848
}
4949

5050
pair.Response = models.ResponseDetails{
51-
Status: resp.StatusCode,
52-
Body: string(bodyBytes),
53-
Headers: resp.Header,
54-
FixedDelay: int(duration.Milliseconds()),
51+
Status: resp.StatusCode,
52+
Body: string(bodyBytes),
53+
Headers: resp.Header,
5554
}
5655

5756
pair, err = this.Hoverfly.ApplyMiddleware(pair)

core/modes/spy_mode.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func (this *SpyMode) View() v2.ModeView {
3434
Stateful: this.Arguments.Stateful,
3535
Headers: this.Arguments.Headers,
3636
OverwriteDuplicate: this.Arguments.OverwriteDuplicate,
37+
CaptureDelay: this.Arguments.CaptureDelay,
3738
},
3839
}
3940
}
@@ -51,6 +52,7 @@ func (this *SpyMode) SetArguments(arguments ModeArguments) {
5152
Stateful: arguments.Stateful,
5253
OverwriteDuplicate: arguments.OverwriteDuplicate,
5354
CaptureOnMiss: arguments.CaptureOnMiss,
55+
CaptureDelay: arguments.CaptureDelay,
5456
}
5557
}
5658

@@ -74,12 +76,15 @@ func (this SpyMode) Process(request *http.Request, details models.RequestDetails
7476
if this.Arguments.CaptureOnMiss {
7577
respBody, _ := util.GetResponseBody(response)
7678
respHeaders := util.GetResponseHeaders(response)
77-
79+
delayInMs := 0
80+
if this.Arguments.CaptureDelay {
81+
delayInMs = int(duration.Milliseconds())
82+
}
7883
responseObj := &models.ResponseDetails{
7984
Status: response.StatusCode,
8085
Body: respBody,
8186
Headers: respHeaders,
82-
FixedDelay: int(duration.Milliseconds()),
87+
FixedDelay: delayInMs,
8388
}
8489
if this.Arguments.Headers == nil {
8590
this.Arguments.Headers = []string{}

hoverctl/cmd/mode.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var stateful bool
1616
var overwriteDuplicate bool
1717
var matchingStrategy string
1818
var captureOnMiss bool
19+
var captureDelay bool
1920

2021
var modeCmd = &cobra.Command{
2122
Use: "mode [capture|diff|simulate|spy|modify|synthesize (optional)]",
@@ -51,6 +52,7 @@ mode is shown.
5152
case modes.Capture:
5253
modeView.Arguments.Stateful = stateful
5354
modeView.Arguments.OverwriteDuplicate = overwriteDuplicate
55+
modeView.Arguments.CaptureDelay = captureDelay
5456
setHeaderArgument(modeView)
5557
break
5658
case modes.Diff:
@@ -61,6 +63,7 @@ mode is shown.
6163
modeView.Arguments.Stateful = stateful
6264
modeView.Arguments.OverwriteDuplicate = overwriteDuplicate
6365
modeView.Arguments.CaptureOnMiss = captureOnMiss
66+
modeView.Arguments.CaptureDelay = captureDelay
6467
setHeaderArgument(modeView)
6568
break
6669
}
@@ -98,6 +101,9 @@ func getExtraInfo(mode *v2.ModeView) string {
98101
extraInfo = fmt.Sprintf("and will capture the following request headers: %s", mode.Arguments.Headers)
99102
}
100103
}
104+
if captureDelay {
105+
extraInfo = fmt.Sprintf(" and will also capture the delay")
106+
}
101107
break
102108
case modes.Diff:
103109
if len(mode.Arguments.Headers) > 0 {
@@ -119,6 +125,9 @@ func getExtraInfo(mode *v2.ModeView) string {
119125
extraInfo = fmt.Sprintf("and also will capture the following request headers: %s", mode.Arguments.Headers)
120126
}
121127
}
128+
if captureDelay {
129+
extraInfo = fmt.Sprintf(" and will also capture the delay")
130+
}
122131
break
123132
}
124133

@@ -139,4 +148,5 @@ func init() {
139148
modeCmd.PersistentFlags().BoolVar(&overwriteDuplicate, "overwrite-duplicate", false,
140149
"Overwrite duplicate requests in capture mode")
141150
modeCmd.PersistentFlags().BoolVar(&captureOnMiss, "capture-on-miss", false, "Capture the request on miss in spy mode")
151+
modeCmd.PersistentFlags().BoolVar(&captureDelay, "capture-delay", false, "Capture the request delay in capture and spy mode")
142152
}

0 commit comments

Comments
 (0)