资源说明:Low level tools to send and receive custom HTTP messages.
This application consists of a simple raw TCP client and server; they can be used to send custom HTTP messages from file and also capture incoming HTTP messages to file.
OVERVIEW
In web application development, it is sometimes necessary to do low-level testing and debugging of the HTTP headers. For example, you might want to check if your server responds as intended to certain HTTP request header fields (such as referrer, accept-encoding, user-agent and many others) related to security, caching, presentation, etc. There are a huge variety of HTTP debugging tools available; however, they are often complicated and inconvenient to use, and/or don't give you enough control over the HTTP headers for the task you're trying to do.
For example, tools like Firebug and http://web-sniffer.net are very convenient and easy, but they only show you the HTTP request headers and don't let you compose custom headers. Raw TCP tools like netcat and socat give you complete control over the HTTP message composition, but you spend a lot time figuring out their syntax and writing commands.
This application is meant to be very simple to use and yet give you complete control over sending and receiving HTTP messages. It uses a working directory, in which several files are stored that contain the settings, the HTTP message to be sent, and the HTTP message received. The user simply accesses these files in a text editor to compose and view HTTP messages.
The application consists of two tools: a TCP client and a TCP server that work independently of each other. You choose which tool to start by providing a command line argument when running the program (see RUNING THE PROGRAM); you can also start both tools on the same machine by running them from separate terminals with different command line arguments.
How the client tool works:
- The client opens a TCP connection to the host and port provided in the file “propertiesClient”.
- It sends the contents of the file “clientMessageToSend” over this connection
- It receives the response from the host and saves it to the “clientMessageReceived” file (overwritten by each run) and “clientMessageReceivedLog” file (appended to by each run).
- If headerOnly=true in “propertiesClient”, the client closes the TCP connection and exits the program after receiving and saving a HTTP message header.
- If headerOnly=false, the client does not close the connection. It keeps receiving and saving TCP data indefinitely. If the connection is closed by the other end, the program exits.
Example uses of the client tool:
- Compose an arbitrary HTTP request ( to make this easier, you can capture a standard browser request with the server tool - described later - and then modify it as you wish). This lets you test how your server responds to certain header field values or to requests that you want to prohibit (such as PUT, DELETE, PATCH).
- Capture HTTP responses from your server to verify that it includes the header field values you want.
How the server tool works:
- It listens on the TCP port provided in the file “propertiesServer”
- It accepts an incoming TCP connection, and starts saving the incoming message in the “serverMessageReceived” file (overwritten by each run) and the “serverMessageReceivedLog” file (appended to by each run).
- If headerOnly=true in “propertiesServer”, the server tool stops receiving the incoming message after an HTTP header has been received and saved. Then, it sends the contents of the file “serverMessageToSend” as a response, it closes the TCP connection, and exits the program.
- If headerOnly=false, the server tool does not close the connection. It keeps receiving and saving the incoming TCP data indefinitely. If the connection is closed by the other end, the program exits.
- This is a one-shot server, i.e. it can accept only a single connection from a single client.
Example uses of the server tool:
- Compose an arbitrary HTTP server response (to make this easier, you can capture the response from an actual server using the client tool and then modify it as you wish). This can be used to test how a browser or other client is affected by certain header fields in the response.
- Capture HTTP requests from various clients. For example, you can compare the HTTP requests from the popular browsers or test how the requests change with different browser settings.
- Check if your network configuration/firewall allows external access to a given port. Start the server tool on that port with headerOnly=true, and then use http://web-sniffer.net/ to see if you get a response from your machine.
RUNNING THE PROGRAM
- No installation is necessary if you already have Java 6 or later installed
- Prepare a working directory that contains the relevant input files. If you are running the server tool, the working directory must contain the files serverMessageToSend and propertiesServer; if you are running the client tool, it must contain the files clientMessageToSend and propertiesClient. Modify these files with custom messages and properties. Output files such as serverMessageReceived and serverMessageReceivedLog are not required; they will be automatically created if not already present in the directory.
- From the command line type "java -jar httpTools.jar args" whrere args is descirbed below. This assumes that java is added to your system path, and the file "httpTools.jar" is downloaded to the current command line directory.
- you must provide the following command line arguments:
dir {s|c}
Where:
dir - the working directory where relevant files are located. The directory syntax is OS dependent.
s - run the server application
c - run the client application
Examples:
java -jar httpTools.jar "/home/user/exampledir" s
java -jar httpTools.jar "/home/user/exampledir" c
java -jar httpTools.jar "C:\user\exampledir" c
IMPORTANT
Most text editors use only a LF character as a line terminator. However, the HTTP protocol requires the use of CR+LF (some applications may accept LF as valid but that is not guaranteed). Therefore, when editing the files serverMessageToSend and clientMessgeToSend, make sure to include the correct line terminators. This can be done with a HEX editor, or with text editor that uses CR+LF (Microsoft's notepad uses that, and it's available on Linux through Wine).
When receiving messages, this application treats both CR+LF and LF as valid line terminators. The client and server tools are essentially raw TCP applications and do not understand HTTP messages, but they still look at line terminators to detect when an HTTP header ends (by convention, this is marked by two consecutive line terminators).
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。
English
