Howto:How to implement HTTP PUT on an Apache Web Server

From innovaphone wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Some Web Servers (like Apache and reportedly newer IIS versions) do not support the HTTP PUT method. This method however is required by the update server mechanism. Here is how to work around this.


Applies To

This information applies to all innovaphone devices with HTTP-Client.


More Information

Problem Details

The HTTP PUT method is considered harmful in the web community since it basically allows a client to overwrite just any file on the web server. For this reason, some web servers simply do not support it by default.

The update server mechanism though is using the PUT method to upload configurations on a web server for backup. Also, the HTTP interface can be used to upload voice data on a web server.

To work around the problem, some special configuration is required on the web server.

Apache

The Apache web server requires a Script directive in its configuration file. This directive usually is placed in a <Directory> or <Virtualhost> section. Please see the Apache documentation for more details.

Script PUT url

This directive instructs the web server to redirect any HTTP PUT request to a certain page on the server. This page usually will be a cgi program or page which allows scripting, for example a PHP page. The cgi/page then can handle the PUT request.

The basic operation is:

  1. Check that request comes from the PUT method
  2. Get the file to update or create from PATH_TRANSLATED
  3. Read the data (read CONTENT_LENGTH bytes from standard input)
  4. Write the data to the file
  5. Return a 201 or 204 status.

The same scheme can be used with any scripting language available. See the scripting engine’s documentation for more details.

There is a good article regarding this issue in http://www.apacheweek.com/features/put.

IIS

IIS normally supports PUT out of the box. For more information see the article in the Micorsoft KB. We have seen some reports that WebDAV must be enabled on IIS 6 to turn on HTTP PUT.


Further Considerations

Scripting can be used for more than just implementing the file upload. For example, an appropriate script might store the file in certain places depending on the client, the time of date or other parameters. In fact, for security reasons, it might be a good idea to actually ignore the target URL presented in the PUT request and to store the file in a place which is entirely controlled by the server.

Known Problems