You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Organize Caching configuration params on its own section using bullet points
- Put all Caching configuration params together
- Add Ruby syntax highlighting to some blocks that were missing
Copy file name to clipboardExpand all lines: README.md
+82-80Lines changed: 82 additions & 80 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -289,6 +289,11 @@ you can turn on cache persistence. This way you don't have to manually mock out
289
289
everything as requests are automatically recorded and played back. With cache
290
290
persistence you can take tests completely offline.
291
291
292
+
The cache works with all types of requests and will distinguish between
293
+
different POST requests to the same URL.
294
+
295
+
### Params
296
+
292
297
```ruby
293
298
Billy.configure do |c|
294
299
c.cache =true
@@ -319,89 +324,123 @@ Billy.configure do |c|
319
324
end
320
325
```
321
326
322
-
The cache works with all types of requests and will distinguish between
323
-
different POST requests to the same URL.
324
-
325
-
`c.cache_request_headers` is used to store the outgoing request headers in the cache.
327
+
-`c.cache_request_headers` is used to store the outgoing request headers in the cache.
326
328
It is also saved to yml if `persist_cache` is enabled. This additional information
327
329
is useful for debugging (for example: viewing the referer of the request).
328
330
329
-
`c.ignore_params` is used to ignore parameters of certain requests when
331
+
-`c.ignore_params` is used to ignore parameters of certain requests when
330
332
caching. You should mostly use this for analytics and various social buttons as
331
333
they use cache avoidance techniques, but return practically the same response
332
334
that most often does not affect your test results.
333
335
334
-
`c.allow_params` is used to allow parameters of certain requests when caching. This is best used when a site
335
-
has a large number of analytics and social buttons. `c.allow_params` is the opposite of `c.ignore_params`,
336
-
a whitelist to a blacklist. In order to toggle between using one or the other, use `c.use_ignore_params`.
337
-
338
-
`c.strip_query_params` is used to strip query parameters when you stub some requests
339
-
with query parameters. Default value is true. For example, `proxy.stub('http://myapi.com/user/?country=FOO')`
340
-
is considered the same as: `proxy.stub('http://myapi.com/user/?anything=FOO')` and
341
-
generally the same as: `proxy.stub('http://myapi.com/user/')`. When you need to distinguish between all these requests,
342
-
you may set this config value to false.
343
-
344
-
`c.dynamic_jsonp` is used to rewrite the body of JSONP responses based on the
345
-
callback parameter. For example, if a request to `http://example.com/foo?callback=bar`
346
-
returns `bar({"some": "json"});` and is recorded, then a later request to
347
-
`http://example.com/foo?callback=baz` will be a cache hit and respond with
348
-
`baz({"some": "json"});` This is useful because most JSONP implementations
349
-
base the callback name off of a timestamp or something else dynamic.
350
-
351
-
`c.dynamic_jsonp_keys` is used to configure which parameters to ignore when
352
-
using `c.dynamic_jsonp`. This is helpful when JSONP APIs use cache-busting
353
-
parameters. For example, if you want `http://example.com/foo?callback=bar&id=1&cache_bust=12345` and `http://example.com/foo?callback=baz&id=1&cache_bust=98765` to be cache hits for each other, you would set `c.dynamic_jsonp_keys = ['callback', 'cache_bust']` to ignore both params. Note
354
-
that in this example the `id` param would still be considered important.
355
-
356
-
`c.dynamic_jsonp_callback_name` is used to configure the name of the JSONP callback
357
-
parameter. The default is `callback`.
358
-
359
-
`c.path_blacklist = []` is used to always cache specific paths on any hostnames,
336
+
-`c.path_blacklist = []` is used to always cache specific paths on any hostnames,
360
337
including whitelisted ones. This is useful if your AUT has routes that get data
361
338
from external services, such as `/api` where the ajax request is a local URL but
362
339
the actual data is coming from a different application that you want to cache.
363
340
364
-
`c.merge_cached_responses_whitelist = []` is used to group together the cached
341
+
-`c.merge_cached_responses_whitelist = []` is used to group together the cached
365
342
responses for specific uri regexes that match any part of the url. This is useful
366
343
for ensuring that any kind of analytics and various social buttons that have
367
344
slightly different urls each time can be recorded once and reused nicely. Note
368
345
that the request body is ignored for requests that contain a body.
369
346
370
-
`c.ignore_cache_port` is used to strip the port from the URL if it exists. This
347
+
-`c.ignore_cache_port` is used to strip the port from the URL if it exists. This
371
348
is useful when caching local paths (via `path_blacklist`) or other local rack apps
372
349
that are running on random ports.
373
350
374
-
`c.non_successful_cache_disabled` is used to not cache responses without 200-series
351
+
-`c.non_successful_cache_disabled` is used to not cache responses without 200-series
375
352
or 304 status codes. This prevents unauthorized or internal server errors from
376
353
being cached and used for future test runs.
377
354
378
-
`c.non_successful_error_level` is used to log when non-successful responses are
355
+
-`c.non_successful_error_level` is used to log when non-successful responses are
379
356
received. By default, it just writes to the log file, but when set to `:error`
380
357
it throws an error with the URL and status code received for easier debugging.
381
358
382
-
`c.non_whitelisted_requests_disabled` is used to disable hitting new URLs when
359
+
-`c.non_whitelisted_requests_disabled` is used to disable hitting new URLs when
383
360
no cache file exists. Only whitelisted URLs (on non-blacklisted paths) are
384
361
allowed, all others will throw an error with the URL attempted to be accessed.
385
362
This is useful for debugging issues in isolated environments (ie.
386
363
continuous integration).
387
364
388
-
`c.cache_path` can be used to locate the cache directory to a different place
365
+
-`c.cache_path` can be used to locate the cache directory to a different place
389
366
other than `system temp directory/puffing-billy`.
390
367
391
-
`c.certs_path` can be used to locate the directory for dynamically generated
368
+
-`c.certs_path` can be used to locate the directory for dynamically generated
392
369
SSL certificates to a different place other than `system temp
393
370
directory/puffing-billy/certs`.
394
371
395
-
`c.proxy_host` and `c.proxy_port` are used for the Billy proxy itself which runs locally.
372
+
-`c.proxy_host` and `c.proxy_port` are used for the Billy proxy itself which runs locally.
396
373
397
-
`c.proxied_request_host` and `c.proxied_request_port` are used if an internal proxy
374
+
-`c.proxied_request_host` and `c.proxied_request_port` are used if an internal proxy
398
375
server is required to access the internet. Most common in larger companies.
399
376
400
-
`c.record_requests` can be used to record all requests that puffing billy proxied.
377
+
-`c.allow_params` is used to allow parameters of certain requests when caching. This is best used when a site
378
+
has a large number of analytics and social buttons. `c.allow_params` is the opposite of `c.ignore_params`,
379
+
a whitelist to a blacklist. In order to toggle between using one or the other, use `c.use_ignore_params`.
380
+
381
+
-`c.strip_query_params` is used to strip query parameters when you stub some requests
382
+
with query parameters. Default value is true. For example, `proxy.stub('http://myapi.com/user/?country=FOO')`
383
+
is considered the same as: `proxy.stub('http://myapi.com/user/?anything=FOO')` and
384
+
generally the same as: `proxy.stub('http://myapi.com/user/')`. When you need to distinguish between all these requests,
385
+
you may set this config value to false.
386
+
387
+
-`c.dynamic_jsonp` is used to rewrite the body of JSONP responses based on the
388
+
callback parameter. For example, if a request to `http://example.com/foo?callback=bar`
389
+
returns `bar({"some": "json"});` and is recorded, then a later request to
390
+
`http://example.com/foo?callback=baz` will be a cache hit and respond with
391
+
`baz({"some": "json"});` This is useful because most JSONP implementations
392
+
base the callback name off of a timestamp or something else dynamic.
393
+
394
+
-`c.dynamic_jsonp_keys` is used to configure which parameters to ignore when
395
+
using `c.dynamic_jsonp`. This is helpful when JSONP APIs use cache-busting
396
+
parameters. For example, if you want `http://example.com/foo?callback=bar&id=1&cache_bust=12345` and `http://example.com/foo?callback=baz&id=1&cache_bust=98765` to be cache hits for each other, you would set `c.dynamic_jsonp_keys = ['callback', 'cache_bust']` to ignore both params. Note
397
+
that in this example the `id` param would still be considered important.
398
+
399
+
-`c.dynamic_jsonp_callback_name` is used to configure the name of the JSONP callback
400
+
parameter. The default is `callback`.
401
+
402
+
-`c.record_requests` can be used to record all requests that puffing billy proxied.
401
403
This can be useful for debugging purposes, for instance if you are unsure why
402
404
your stubbed requests are not being successfully proxied.
403
405
404
-
Example usage:
406
+
-`c.cache_request_body_methods` is used to specify HTTP methods of requests that you would like to cache separately based on the contents of the request body. The default is ['post'].
407
+
408
+
-`c.use_ignore_params` is used to choose whether to use the ignore_params blacklist or the allow_params whitelist. Set to `true` to use `c.ignore_params`,
409
+
`false` to use `c.allow_params`
410
+
411
+
-`c.before_handle_request` is used to modify `method`, `url`, `headers`, `body` before handle request by `stubs`, `cache` or `proxy`. Method accept 4 argumens and must return array of this arguments:
-`c.cache_simulates_network_delays` is used to add some delay before cache returns response. When set to `true`, cached requests will wait from configured delay time before responding. This allows to catch various race conditions in asynchronous front-end requests. The default is `false`.
421
+
422
+
-`c.cache_simulates_network_delay_time` is used to configure time (in seconds) to wait until responding from cache. The default is `0.1`.
423
+
424
+
-`c.after_cache_handles_request` is used to configure a callback that can operate on the response after it has been retrieved from the cache but before it is returned. The callback receives the request and response as arguments, with a request object like: `{ method: method, url: url, headers: headers, body: body }`. An example usage would be manipulating the Access-Control-Allow-Origin header so that your test server doesn't always have to run on the same port in order to accept cached responses to CORS requests:
require'table_print'# Add this dependency to your gemfile
@@ -455,43 +494,6 @@ The handler column indicates how Puffing Billy handled your request:
455
494
If your `status` is set to `inflight` this request has not yet been handled fully. Either puffing billy crashed
456
495
internally on this request, or your test ended before it could complete successfully.
457
496
458
-
`c.cache_request_body_methods` is used to specify HTTP methods of requests that you would like to cache separately based on the contents of the request body. The default is ['post'].
459
-
460
-
`c.after_cache_handles_request` is used to configure a callback that can operate on the response after it has been retrieved from the cache but before it is returned. The callback receives the request and response as arguments, with a request object like: `{ method: method, url: url, headers: headers, body: body }`. An example usage would be manipulating the Access-Control-Allow-Origin header so that your test server doesn't always have to run on the same port in order to accept cached responses to CORS requests:
`c.use_ignore_params` is used to choose whether to use the ignore_params blacklist or the allow_params whitelist. Set to `true` to use `c.ignore_params`,
480
-
`false` to use `c.allow_params`
481
-
482
-
`c.before_handle_request` is used to modify `method`, `url`, `headers`, `body` before handle request by `stubs`, `cache` or `proxy`. Method accept 4 argumens and must return array of this arguments:
`c.cache_simulates_network_delays` is used to add some delay before cache returns response. When set to `true`, cached requests will wait from configured delay time before responding. This allows to catch various race conditions in asynchronous front-end requests. The default is `false`.
492
-
493
-
`c.cache_simulates_network_delay_time` is used to configure time (in seconds) to wait until responding from cache. The default is `0.1`.
494
-
495
497
### Cache Scopes
496
498
497
499
If you need to cache different responses to the same HTTP request, you can use
@@ -618,7 +620,7 @@ end
618
620
619
621
## Proxy timeouts
620
622
621
-
By default, the Puffing Billy proxy will use the EventMachine:HttpRequest timeouts of 5 seconds
623
+
By default, the Puffing Billy proxy will use the `EventMachine::HttpRequest` timeouts of 5 seconds
622
624
for connect and 10 seconds for inactivity when talking to downstream servers.
0 commit comments