You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.



HTTP Debugging (Capturing a HTTP log)
Darin Fisher / darin at meer dot net
June 16, 2004

Ok, so you suspect that Mozilla's HTTP layer is behaving badly, or perhaps someone asked you to capture a HTTP log. What do you do? Well, if you have a nightly trunk build of Mozilla, then you can set some environment variables before running Mozilla to capture a log of HTTP activity. Follow these steps for your particular platform:

Enabling HTTP logging:

Windows
Make sure Mozilla is not running (be sure that Quick Launch is disabled). Then open a DOS prompt, and type the following (this example assumes that you have installed Mozilla in the default location):


  C:\> set NSPR_LOG_MODULES=nsHttp:5,nsSocketTransport:5,nsHostResolver:5
  C:\> set NSPR_LOG_FILE=C:\log.txt

  C:\> cd "Program Files\mozilla.org\Mozilla"
  C:\Program Files\mozilla.org\Mozilla\> .\mozilla.exe

Now reproduce whatever problem you're trying to debug, and when you are done exit Mozilla and look for the generated log file: C:\log.txt

Linux
Make sure Mozilla is not running. Then open a new shell (example assumes bash compatible), and type the following:


  bash$ export NSPR_LOG_MODULES=nsHttp:5,nsSocketTransport:5,nsHostResolver:5
  bash$ export NSPR_LOG_FILE=/tmp/log.txt

  bash$ /path/to/mozilla/mozilla

Now reproduce whatever problem you're trying to debug, and when you are done exit Mozilla and look for the generated log file: /tmp/log.txt

OSX
Make sure Mozilla is not running. Then run the Terminal application (found under the Utilities application group), and type the following commands (this example assumes that you have installed Mozilla on your desktop and that you are using the default OSX command shell, tcsh):


  [mybox:~] user% setenv NSPR_LOG_MODULES nsHttp:5,nsSocketTransport:5,nsHostResolver:5
  [mybox:~] user% setenv NSPR_LOG_FILE    ~/log.txt

  [mybox:~] user% cd Desktop/Mozilla.app/Contents/MacOS
  [mybox:Mozilla.app/Contents/MacOS] user% ./mozilla-bin

If you are using Mac OSX 10.3 or later, then you're most likely using the bash shell instead of tcsh. In that case replace setenv with export.

Now reproduce whatever problem you're trying to debug, and when you are done exit Mozilla and look for the generated log file log.txt in your home directory. NOTE: the generated log file will have UNIX style line endings, so if you want to view it you will need to use an editor that can handled a UNIX style text file.

Other options:

  • If you were only interested in logging HTTP request/response headers, then set "NSPR_LOG_MODULES=nsHttp:3" only.
  • nsSocketTransport:5 can be removed if you are not interested in socket level log output (there can be a lot of noise from logging at this level depending on what you are trying to debug).
  • nsHostResolver:5 can be removed if you are not interested in host resolver log output (i.e., DNS queries).
  • There is also a handy extension for Mozilla called livehttpheaders that can be used to capture only the HTTP request/response headers. It is a very handy tool in cases where you want to just peek at HTTP traffic.
  • Finally, there are times when the builtin logging facility of Mozilla is simply not sufficient, and one must resort to a full fledged packet tracing tool. Ethereal and ngrep are two excellent tools available for Windows and most flavors of UNIX (not including OSX last I checked). Commercially available packet tracers may offer better features, but for the most part these freely available tracers are rock solid and offer enough features to help uncover any Mozilla networking problem.

See also:

  • There are similar options available to debug mailnews protocols. See this document for more info about mailnews troubleshooting.
  • On the windows platform, nightly mozilla builds have FTP logging enabled. (Don't ask why this is only the case for windows!) To enable FTP logging, just set NSPR_LOG_MODULES=nsFtp:5 (in older versions of Mozilla, you need to use "nsFTPProtocol" instead of "nsFtp").