Skip to content

Commit 980827a

Browse files
committed
Update journal body size limit flag
1 parent 600f714 commit 980827a

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

core/cmd/hoverfly/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var logOutputFlags arrayFlags
6464
var responseBodyFilesPath string
6565
var responseBodyFilesAllowedOriginFlags arrayFlags
6666
var journalIndexingKeyFlags arrayFlags
67-
var journalBodyMemoryLimit util.MemorySize
67+
var journalBodySizeLimit util.MemorySize
6868

6969
const boltBackend = "boltdb"
7070
const inmemoryBackend = "memory"
@@ -211,7 +211,7 @@ func main() {
211211
flag.StringVar(&responseBodyFilesPath, "response-body-files-path", "", "When a response contains a relative bodyFile, it will be resolved against this absolute path (default is CWD)")
212212
flag.Var(&responseBodyFilesAllowedOriginFlags, "response-body-files-allow-origin", "When a response contains a url in bodyFile, it will be loaded only if the origin is allowed")
213213
flag.Var(&journalIndexingKeyFlags, "journal-indexing-key", "Key to setup indexing on journal")
214-
flag.Var(&journalBodyMemoryLimit, "journal-body-memory-limit", "Memory size limit for a request or response body in the journal (e.g., '128KB', '2MB'). Memory size is unbounded by default")
214+
flag.Var(&journalBodySizeLimit, "journal-body-size-limit", "Set the memory size limit for a request or response body in the journal (e.g., '128KB', '2MB'). Defaults to unbounded")
215215

216216
flag.Parse()
217217

@@ -236,8 +236,8 @@ func main() {
236236
*journalSize = 0
237237
}
238238

239-
if journalBodyMemoryLimit > 0 {
240-
log.Infof("Journal body memory limit is set to: %s", journalBodyMemoryLimit.String())
239+
if journalBodySizeLimit > 0 {
240+
log.Infof("Journal body size limit is set to: %s", journalBodySizeLimit.String())
241241
}
242242

243243
if *logsSize < 0 {
@@ -252,7 +252,7 @@ func main() {
252252

253253
hoverfly.StoreLogsHook.LogsLimit = *logsSize
254254
hoverfly.Journal.EntryLimit = *journalSize
255-
hoverfly.Journal.BodyMemoryLimit = journalBodyMemoryLimit
255+
hoverfly.Journal.BodySizeLimit = journalBodySizeLimit
256256

257257
// getting settings
258258
cfg := hv.InitSettings()

core/journal/journal.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ type PostServeActionEntry struct {
3939
}
4040

4141
type Journal struct {
42-
entries []JournalEntry
43-
Indexes []Index
44-
EntryLimit int
45-
BodyMemoryLimit util.MemorySize
46-
mutex sync.Mutex
42+
entries []JournalEntry
43+
Indexes []Index
44+
EntryLimit int
45+
BodySizeLimit util.MemorySize
46+
mutex sync.Mutex
4747
}
4848

4949
func NewJournal() *Journal {
@@ -107,9 +107,9 @@ func (this *Journal) NewEntry(request *http.Request, response *http.Response, mo
107107

108108
respBody, _ := util.GetResponseBody(response)
109109

110-
if this.BodyMemoryLimit.ToBytes() > 0 {
111-
payloadRequest.Body = util.TruncateStringWithEllipsis(payloadRequest.Body, this.BodyMemoryLimit.ToBytes())
112-
respBody = util.TruncateStringWithEllipsis(respBody, this.BodyMemoryLimit.ToBytes())
110+
if this.BodySizeLimit.ToBytes() > 0 {
111+
payloadRequest.Body = util.TruncateStringWithEllipsis(payloadRequest.Body, this.BodySizeLimit.ToBytes())
112+
respBody = util.TruncateStringWithEllipsis(respBody, this.BodySizeLimit.ToBytes())
113113
}
114114

115115
payloadResponse := &models.ResponseDetails{

core/journal/journal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func Test_Journal_NewEntryWithMemoryLimit_TruncateBody(t *testing.T) {
8080
RegisterTestingT(t)
8181

8282
unit := journal.NewJournal()
83-
unit.BodyMemoryLimit = 15
83+
unit.BodySizeLimit = 15
8484

8585
request, _ := http.NewRequest("GET", "http://hoverfly.io", io.NopCloser(bytes.NewBufferString("large request body")),)
8686

docs/pages/reference/hoverfly/hoverfly.output

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ Usage of hoverfly:
4747
Generate CA certificate and private key for MITM
4848
-import value
4949
Import from file or from URL (i.e. '-import my_service.json' or '-import http://mypage.com/service_x.json'
50+
-journal-body-size-limit value
51+
Set the memory size limit for a request or response body in the journal (e.g., '128KB', '2MB'). Defaults to unbounded
52+
-journal-indexing-key value
53+
Key to setup indexing on journal
5054
-journal-size int
5155
Set the size of request/response journal (default 1000)
52-
-journal-indexing-key string
53-
Specify the index key using which you want to index journal. Index shares same syntax as the one for templating, such as Request.QueryParam.myParam or Request.Header.X-Header-Id.[1].
54-
It is used for extracting the data from the journal entry to use as a key for that entry.
5556
-key string
5657
Private key of the CA used to sign MITM certificates
5758
-listen-on-host string
@@ -72,38 +73,34 @@ Usage of hoverfly:
7273
Set the amount of logs to be stored in memory (default 1000)
7374
-metrics
7475
Enable metrics logging to stdout
75-
-post-serve-action string
76-
Set local post serve action by passing the action name, binary and the path of the action script and delay in Ms separated by space.
77-
(i.e. -post-serve-action "<action name> python3 <script path to load> 1000" -post-serve-action "<action name> python3 <script path to load> 3000")
78-
Set remote post serve action by passing the action name, remote host and delay in Ms separated by space.
79-
(i.e. -post-serve-action "<action name> <http/https remote host> 1000" -post-serve-action "<action name> <http/https remote host> 3000")
80-
We can set multiple post serve actions and use in our simulation schema file.
8176
-middleware string
8277
Set middleware by passing the name of the binary and the path of the middleware script separated by space. (i.e. '-middleware "python script.py"')
8378
-modify
8479
Start Hoverfly in modify mode - applies middleware (required) to both outgoing and incoming HTTP traffic
8580
-no-import-check
8681
Skip duplicate request check when importing simulations
82+
-pac-file string
83+
Path to the pac file to be imported on startup
8784
-password string
8885
Password for new user
8986
-password-hash string
9087
Password hash for new user instead of password
9188
-plain-http-tunneling
9289
Use plain http tunneling to host with non-443 port
90+
-post-serve-action value
91+
Set post serve action by passing the action name, binary and the path of the action script and delay in Ms separated by space. (i.e. i.e. '-post-serve-action "webhook python script.py 2000"')
9392
-pp string
9493
Proxy port - run proxy on another port (i.e. '-pp 9999' to run proxy on port 9999)
9594
-response-body-files-allow-origin value
9695
When a response contains a url in bodyFile, it will be loaded only if the origin is allowed
9796
-response-body-files-path string
98-
When a response contains a relative bodyFile, it will be resolved against this path (default is CWD)
97+
When a response contains a relative bodyFile, it will be resolved against this absolute path (default is CWD)
9998
-spy
10099
Start Hoverfly in spy mode, similar to simulate but calls real server when cache miss
101100
-synthesize
102101
Start Hoverfly in synthesize mode (middleware is required)
103-
-templating-data-source
104-
Set templating CSV data source by passing data source name and CSV data file path separated by space.
105-
(i.e. -templating-data-source "<data source name> <file path>")
106-
We can set multiple template CSV data source and then we can query data by using templating csv helper method
102+
-templating-data-source value
103+
Set template data source (i.e. '-templating-data-source "<datasource name> <file path>"')
107104
-tls-verification
108105
Turn on/off tls verification for outgoing requests (will not try to verify certificates) (default true)
109106
-upstream-proxy string
@@ -115,3 +112,4 @@ Usage of hoverfly:
115112
Get the version of hoverfly
116113
-webserver
117114
Start Hoverfly in webserver mode (simulate mode)
115+

0 commit comments

Comments
 (0)