Slide 1

Slide 1 text

Debugging HTTP Lorna Mitchell, PHP UK 2014

Slide 2

Slide 2 text

6 Stages of Debugging

Slide 3

Slide 3 text

Denial That can't happen.

Slide 4

Slide 4 text

Frustration That doesn't happen on my machine.

Slide 5

Slide 5 text

Disbelief That shouldn't happen.

Slide 6

Slide 6 text

Testing Why does that happen?

Slide 7

Slide 7 text

Gotcha Oh, I see.

Slide 8

Slide 8 text

Relief How did that ever work?

Slide 9

Slide 9 text

Fault-Finding HTTP ... is just like fault-finding elsewhere in a web project Seeing the problem is usually harder than fixing it • Can you reproduce the problem? • Start wireshark, inspect traffic • Use Curl to try simplest case, then step up • Charles can transform requests

Slide 10

Slide 10 text

Tools

Slide 11

Slide 11 text

Curl Curl (or cURL) is command-line multitool for HTTP http://curl.haxx.se/

Slide 12

Slide 12 text

Curl is Your Friend -X [verb] The verb to use for this request -H "[Header: value]" A header to send. Use as many times as needed -d [value] Either the whole body data as a string, a filename, or a key/value pair -s The "silent" switch, to hide curl's progress meter when piping the output to something else -c [filename] Where to store any incoming cookies for future use -b [filename] Cookies to send with the request -v to both body and headers, in the request and response

Slide 13

Slide 13 text

Meet Curl Demo 1: I'd like to introduce you to curl

Slide 14

Slide 14 text

Python's JSON Library A python tool, handily available via CLI [some json] | python -mjson.tool http://docs.python.org/2/library/json.html

Slide 15

Slide 15 text

Wireshark Copies traffic from your network card to allow you to view it • Quick way to observe without adding debug to your application • Can use tcpdump to capture on a server, wireshark to inspect later • Save and load sessions https://www.wireshark.org/

Slide 16

Slide 16 text

Debugging Across Layers

Slide 17

Slide 17 text

Debugging Across Layers Demo 2: why doesn't this work? ... oh.

Slide 18

Slide 18 text

Charles Proxy Multi-platform Web Debugging Proxy http://www.charlesproxy.com/ • Observe requests • Firefox plugin • Change requests • Use Charles as a network proxy • Repeat/save requests (detailed article: http://lrnja.net/ZuiDYJ)

Slide 19

Slide 19 text

Charles Proxy Demo 3: A few Charles Proxy tricks

Slide 20

Slide 20 text

Debugging on Mobile Demo 4: WTF is this app doing?

Slide 21

Slide 21 text

Debugging SSL Charles can perform a man-in-the-middle attack

Slide 22

Slide 22 text

Debugging SSL You need to authorise the attack Add an exception, or install the Charles CA in your browser

Slide 23

Slide 23 text

Other Excellent Tools • httpie https://github.com/jkbr/httpie • Fiddler http://www.telerik.com/fiddler • Postman (Chrome) http://getpostman.com/ • RESTClient (Firefox) http://restclient.net/ • mitmproxy http://mitmproxy.org/ • jq http://stedolan.github.io/jq/

Slide 24

Slide 24 text

Make Debugging Your Super Power

Slide 25

Slide 25 text

Questions? Feedback please! https://joind.in/10702 Contact: http://lornajane.net - @lornajane