gnegg programming with passion

2Feb/0710

The return of Expect: 100-continue

Yesterday I had to work with a PHP-application using the CURL library to send a HTTP POST request to a lighttpd server.

Strangely enough I seemed unable to get anything back from the server when using PHP and I got the correct answer when I was using wget as a reference.

This made me check the lightpd log and I once more (I recommend you to read that entry as this is very much dependent on it) came across the friendly error 417

A quick check with Wireshark confirmed: curl was sending the Expect: 100-continue header.

Personally, I think that 100-continue thing is a good thing and it even seems to me that the curl library is intelligent about it and only does that thing when the size of the data to send is larger than a certain threshold.

Also, even though people are complaining about it, I think lighttpd does the right thing. The expect-header is mandatory and if lighttpd doesn't support this particular header, the error 417 is the only viable option.

What I think though is that the libraries should detect that automatically.

This is because they are creating a behavior that's not consistent to the other types of request: GET, DELETE and HEAD requests all follow a fire-and-forget paradigm and the libraries employ a 1:1 mapping: Set up the request. Send it. Return the received data.

With POST (and maybe PUT), the library changes that paradigm and in fact sends two request to the wire while actually pretending in the interface that it's only sending one request.

If it does that, then it should at least be capable enough to handle the cases where their scheme of transparently changing semantics breaks.

Anyways: The fix for the curl-library in PHP is:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));

Though I'm not sure how pure this solution is.

Comments (10) Trackbacks (1)
  1. Thank you sooo much. Had the same problem in an other application and was trying to understand that for hours.

    regards,
    tony

  2. Thank you very much!

  3. Thanks! This saved me. I recommend fixing the typo “except” to “expect” so this pops up in searches.

  4. thanks a lot for alerting me about the typo – I have no idea what made me not notice that way earlier. Well… the words kind of look alike I guess.

  5. Thanks a lot – was having a nightmare trying to integrate SecPay’s API because they were sending a 100 response so I was getting an error. Changed my xmlrpc client and now it works!

  6. You just saved my day! Been puzzling with this problem far too long, what a relief

  7. Thanks! I had exactly the same problem and this fixed it.

    The bug should be fixed in the latest lighttpd version, but that one isn’t in the Debian stable repository yet.

    • I don’t think this is a bug in lighty – more like a missing feature. If you don’t support Expect: 100-continue, then 417 is the correct response.

      The bug, IMHO, is in curl which does something in the background that is not obvious to the caller and then bails out if the scheme failed.

      The default in curl should be to not use 100-continue or to correctly try and repost after a 417 error.

  8. Thank U very very very very very very very MUCH!!!

  9. spent several hours trying to figure out this problem. thanks!!!


Leave a comment