|
1 | 1 | # validate-http-headers |
2 | | -Utility to validate HTTP headers of multiple URL based on a JSON spec |
| 2 | +Utility to validate HTTP headers of multiple URLs based on a JSON spec. Useful |
| 3 | +to quickly set default request headers and automate network deployment testing. |
| 4 | + |
| 5 | +Write a JSON spec file for the validator to use: e.g. urls.json |
| 6 | + |
| 7 | +Pass it to the validator |
| 8 | + |
| 9 | + $ ./validate-http-headers urls.json |
| 10 | + |
| 11 | + ------------------------------------------------------------------------ |
| 12 | + FILE: urls.json |
| 13 | + |
| 14 | + URL: https://www.google.com/ |
| 15 | + SUCCESS: Expected 'X-Frame-Options' to have 'SAMEORIGIN' match 'SAMEORIGIN' |
| 16 | + SUCCESS: Expected 'Expires' to have '-1' match '-1' |
| 17 | + |
| 18 | + URL: https://drive.google.com/ |
| 19 | + SUCCESS: Response header 'X-Frame-Options' should not exist |
| 20 | + |
| 21 | +Multiple JSON specs can be passed |
| 22 | + |
| 23 | + $ ./validate-http-headers internal.json external.json mtv.json |
| 24 | + |
| 25 | +Simple spec: |
| 26 | + |
| 27 | + { |
| 28 | + "default": { |
| 29 | + "requestHeaders": { |
| 30 | + "Referer": ["https://bad-website.com"] |
| 31 | + }, |
| 32 | + "responseHeaders": { |
| 33 | + "X-Frame-Options": ["SAMEORIGIN"] |
| 34 | + } |
| 35 | + }, |
| 36 | + |
| 37 | + "specs": [ |
| 38 | + { |
| 39 | + "url": "https://www.google.com/" |
| 40 | + }, |
| 41 | + { |
| 42 | + "url": "https://drive.google.com/" |
| 43 | + } |
| 44 | + ] |
| 45 | + } |
| 46 | + |
| 47 | +Complex spec with overrides: |
| 48 | + |
| 49 | + { |
| 50 | + "default": { |
| 51 | + "requestHeaders": { |
| 52 | + "Referer": ["https://golang.org"] |
| 53 | + }, |
| 54 | + "responseHeaders": { |
| 55 | + "X-Frame-Options": ["SAMEORIGIN"] |
| 56 | + } |
| 57 | + }, |
| 58 | + |
| 59 | + "specs": [ |
| 60 | + { |
| 61 | + "url": "https://www.google.com/", |
| 62 | + "requestHeaders": { |
| 63 | + "Referer": ["https://drive.google.com"] |
| 64 | + }, |
| 65 | + "responseHeaders": { |
| 66 | + "Expires": ["-1"] |
| 67 | + } |
| 68 | + }, |
| 69 | + { |
| 70 | + "url": "https://drive.google.com/", |
| 71 | + "responseHeaders": { |
| 72 | + "X-Frame-Options": [""] |
| 73 | + } |
| 74 | + } |
| 75 | + ] |
| 76 | + } |
| 77 | + |
0 commit comments