You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

56 lines
1.4 KiB

  1. #!/bin/sh -e
  2. # This script and the accompanying program, httpr-demo.py, demonstrate how to use
  3. # httpr with Python.
  4. #
  5. # Prerequisites:
  6. # - httpr is on your path.
  7. # - The google-cloud and google-auth Python packages have been installed:
  8. # pip install --upgrade google-cloud
  9. # pip install --upgrade google-auth
  10. # Execution:
  11. # 1. Pick a project and a GCS bucket.
  12. # 2. Invoke this script to record an interaction:
  13. # http-demo.sh PROJECT BUCKET record
  14. # 3. Invoke the script again to replay:
  15. # http-demo.sh PROJECT BUCKET replay
  16. project=$1
  17. bucket=$2
  18. mode=$3
  19. if [[ $mode != "record" && $mode != "replay" ]]; then
  20. echo >&2 "usage: $0 PROJECT BUCKET record|replay"
  21. exit 1
  22. fi
  23. if [[ $(which httpr) == "" ]]; then
  24. echo >&2 "httpr is not on PATH"
  25. exit 1
  26. fi
  27. # Start the proxy and wait for it to come up.
  28. httpr -$mode /tmp/demo.replay &
  29. proxy_pid=$!
  30. # Stop the proxy on exit.
  31. # When the proxy is recording, this will cause it to write the replay file.
  32. trap "kill -2 $proxy_pid" EXIT
  33. sleep 1
  34. # Download the CA certificate from the proxy's control port
  35. # and inform Python of the cert via an environment variable.
  36. cert_file=/tmp/httpr.cer
  37. curl -s localhost:8181/authority.cer > $cert_file
  38. export REQUESTS_CA_BUNDLE=$cert_file
  39. # Tell Python to use the proxy.
  40. # If you passed the -port argument to httpr, use that port here.
  41. export HTTPS_PROXY=localhost:8080
  42. # Run the program.
  43. python httpr-demo.py $project $bucket $mode