Forked from mttjohnson/mock-varnish-backend-request.sh
Created
April 5, 2019 15:43
-
-
Save davidalger/39d38ffa01be2e878cda9dc1a32090ef to your computer and use it in GitHub Desktop.
Mock Varnish Backend Request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Capture the log output from varnishlog and look for BereqHeader | |
| varnishlog -n stage | |
| # Use those values in building a curl request | |
| # * << BeReq >> 3 | |
| # - Begin bereq 2 fetch | |
| # - Timestamp Start: 1482951822.860979 0.000000 0.000000 | |
| # - BereqMethod GET | |
| # - BereqURL /the-url-path-i-requested | |
| # - BereqProtocol HTTP/1.1 | |
| # - BereqHeader X-Real-IP: 127.0.0.1 | |
| # - BereqHeader X-Forwarded-Port: 80 | |
| # - BereqHeader X-Forwarded-Proto: http | |
| # - BereqHeader Host: example.com | |
| # - BereqHeader Pragma: no-cache | |
| # - BereqHeader Upgrade-Insecure-Requests: 1 | |
| # - BereqHeader User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36 | |
| # - BereqHeader Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 | |
| # - BereqHeader Referer: http://example.com/the-url-path-i-requested | |
| # - BereqHeader Accept-Language: en-US,en;q=0.8 | |
| # - BereqHeader Cookie: PHPSESSID | |
| # - BereqHeader X-Forwarded-For: 127.0.0.1, 127.0.0.1 | |
| # - BereqHeader Accept-Encoding: gzip | |
| # - BereqHeader X-Varnish: 3 | |
| # - VCL_call BACKEND_FETCH | |
| # - VCL_return fetch | |
| # - BackendOpen 23 boot.default 127.0.0.1 8081 127.0.0.1 46958 | |
| # - BackendStart 127.0.0.1 8081 | |
| # - Timestamp Bereq: 1482951822.861428 0.000449 0.000449 | |
| # - FetchError http read error: overflow | |
| # - BackendClose 23 boot.default | |
| # - Timestamp Beresp: 1482951824.284536 1.423558 1.423108 | |
| # - Timestamp Error: 1482951824.284547 1.423568 0.000010 | |
| # - BerespProtocol HTTP/1.1 | |
| # - BerespStatus 503 | |
| # - BerespReason Service Unavailable | |
| # - BerespReason Backend fetch failed | |
| # - BerespHeader Date: Wed, 28 Dec 2016 19:03:44 GMT | |
| # - BerespHeader Server: Varnish | |
| # - VCL_call BACKEND_ERROR | |
| # - BerespHeader Content-Type: text/html; charset=utf-8 | |
| # - BerespHeader Retry-After: 5 | |
| # - VCL_return deliver | |
| # - Storage malloc Transient | |
| # - ObjProtocol HTTP/1.1 | |
| # - ObjStatus 503 | |
| # - ObjReason Backend fetch failed | |
| # - ObjHeader Date: Wed, 28 Dec 2016 19:03:44 GMT | |
| # - ObjHeader Server: Varnish | |
| # - ObjHeader Content-Type: text/html; charset=utf-8 | |
| # - ObjHeader Retry-After: 5 | |
| # - Length 278 | |
| # - BereqAcct 910 0 910 32767 0 32767 | |
| # - End | |
| # Construct a curl command to simulate the backend request from Varnish | |
| # Gets the headers only | |
| curl -I \ | |
| -H "X-Real-IP: 127.0.0.1" \ | |
| -H "X-Forwarded-Port: 80" \ | |
| -H "X-Forwarded-Proto: http" \ | |
| -H "Host: example.com" \ | |
| -H "Pragma: no-cache" \ | |
| -H "Upgrade-Insecure-Requests: 1" \ | |
| -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36" \ | |
| -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" \ | |
| -H "Referer: http://example.com/the-url-path-i-requested" \ | |
| -H "Accept-Language: en-US,en;q=0.8" \ | |
| -H "Cookie: PHPSESSID" \ | |
| -H "X-Forwarded-For: 127.0.0.1, 127.0.0.1" \ | |
| -H "Accept-Encoding: gzip" \ | |
| -H "X-Varnish: 3" \ | |
| http://127.0.0.1:8081/the-url-path-i-requested | |
| # To get the size of the headers and body of the response | |
| curl -s -w \%{size_header}:\%{size_download} -o /dev/null \ | |
| -H "X-Real-IP: 127.0.0.1" \ | |
| -H "X-Forwarded-Port: 80" \ | |
| -H "X-Forwarded-Proto: http" \ | |
| -H "Host: example.com" \ | |
| -H "Pragma: no-cache" \ | |
| -H "Upgrade-Insecure-Requests: 1" \ | |
| -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36" \ | |
| -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" \ | |
| -H "Referer: http://example.com/the-url-path-i-requested" \ | |
| -H "Accept-Language: en-US,en;q=0.8" \ | |
| -H "Cookie: PHPSESSID" \ | |
| -H "X-Forwarded-For: 127.0.0.1, 127.0.0.1" \ | |
| -H "Accept-Encoding: gzip" \ | |
| -H "X-Varnish: 3" \ | |
| http://127.0.0.1:8081/the-url-path-i-requested | |
| # Gets the request contents and all verbose details (just remember to remove the "Accept-Encoding: gzip" header. | |
| curl -v \ | |
| -H "X-Real-IP: 127.0.0.1" \ | |
| -H "X-Forwarded-Port: 80" \ | |
| -H "X-Forwarded-Proto: http" \ | |
| -H "Host: example.com" \ | |
| -H "Pragma: no-cache" \ | |
| -H "Upgrade-Insecure-Requests: 1" \ | |
| -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36" \ | |
| -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" \ | |
| -H "Referer: http://example.com/the-url-path-i-requested" \ | |
| -H "Accept-Language: en-US,en;q=0.8" \ | |
| -H "Cookie: PHPSESSID" \ | |
| -H "X-Forwarded-For: 127.0.0.1, 127.0.0.1" \ | |
| -H "X-Varnish: 3" \ | |
| http://127.0.0.1:8081/the-url-path-i-requested | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment