Bug 16593 - PUT/If-match (etag) handling seems to be broken
Summary: PUT/If-match (etag) handling seems to be broken
Status: RESOLVED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_dav (show other bugs)
Version: 2.2.3
Hardware: PC All
: P3 normal with 7 votes (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-01-30 13:04 UTC by Julian Reschke
Modified: 2008-03-11 13:41 UTC (History)
3 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Julian Reschke 2003-01-30 13:04:32 UTC
The following scenario seems to consistently fail with a 412:

1) GET existing resource, obtain etag
2) (modify content)
3) PUT with If-match: etag header

-- windows scripting host example script -- 
var req = new ActiveXObject ("MSXML2.ServerXMLHTTP");

var uri = WScript.Arguments(0);
var user = null;
var pwd = null;

if (WScript.Arguments.length > 1) {
  user = WScript.Arguments(1);
}

if (WScript.Arguments.length > 2) {
  pwd = WScript.Arguments(2);
}


req.open("GET", uri, false, user, pwd);
req.send();

if (req.status < 200 || req.status >= 300) {
  WScript.Echo("unexpected status upon GET: " + req.status);
  WScript.Quit(2);
}

var etag = req.getResponseHeader("etag");
WScript.Echo("etag: " + etag);

var txt = req.responseText + "\nappended line";
WScript.Echo("new content: " + txt);


req.open("PUT", uri, false, user, pwd);
req.setRequestHeader("if-match", etag);
req.send(txt);

if (req.status < 200 || req.status >= 300) {
  WScript.Echo("unexpected status upon PUT: " + req.status + " " + 
req.responseText);
  WScript.Quit(2);
}
Comment 1 Justin Erenkrantz 2003-02-01 09:12:47 UTC
Yup.

We need to either call set_headers or getetag before calling ap_meets_conditions in dav_validate_resource.

Not sure yet what the course of action will be.  Message sent to dev@httpd for assistance.
Comment 2 Roy T. Fielding 2006-12-06 16:32:04 UTC
Is this still broken?
Comment 3 Julian Reschke 2006-12-07 00:52:30 UTC
Yes, just checked with the latest Windows build of 2.2.

Etag was: "762d-c9-b4876f50"

Response was:

412
Date: Thu, 07 Dec 2006 08:50:24 GMT
Server: Apache/2.2.3 (Win32) DAV/2
Content-Length: 249
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1


<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>412 Precondition Failed</title>
</head><body>
<h1>Precondition Failed</h1>
<p>The precondition on the request for the URL /uploads/foo.txt evaluated to
false.</p>
</body></html>


Comment 4 bugzilla 2007-12-21 09:47:20 UTC
See http://wiki.foxmarks.com/wiki/Foxmarks:_Error:_Precondition_Failed as an
example of a situation where this bug is a real problem.
Comment 5 Chris Darroch 2008-03-11 13:41:31 UTC
Fixed in trunk (607466, r607472, r607838) and backported to 2.2.8 (r609113) by changes to fix PR 38034.  Sample successful session below:

GET /uploads/foo.txt HTTP/1.0

HTTP/1.1 200 OK
Date: Tue, 11 Mar 2008 20:10:29 GMT
Server: Apache/2.3.0-dev (Unix) DAV/2
Last-Modified: Tue, 11 Mar 2008 20:09:46 GMT
ETag: "bec78d-1f-4482ee6ea848b"
Accept-Ranges: bytes
Content-Length: 31
Connection: close
Content-Type: text/plain

This is the original content.

PUT /uploads/foo.txt HTTP/1.0
Content-Length: 30
If-Match: "bec78d-1f-4482ee6ea848b"

This is the revised content.
HTTP/1.1 204 No Content
Date: Tue, 11 Mar 2008 20:10:45 GMT
Server: Apache/2.3.0-dev (Unix) DAV/2
Content-Length: 0
Connection: close
Content-Type: text/plain

GET /uploads/foo.txt HTTP/1.0

HTTP/1.1 200 OK
Date: Tue, 11 Mar 2008 20:11:05 GMT
Server: Apache/2.3.0-dev (Unix) DAV/2
Last-Modified: Tue, 11 Mar 2008 20:11:01 GMT
ETag: "bec78d-1e-4482eeb5f5946"
Accept-Ranges: bytes
Content-Length: 30
Connection: close
Content-Type: text/plain

This is the revised content.