Hi,
I'm trying resolve a problem I'm having trying to send utf-8 data and the calculation of the length of that data. If I make the following post:
(defconstant +utf-8+ (make-external-format :utf-8 :eol-style :lf)
(http-request "http://odeon:5984" :content-type "application/xml" :external-format-out +utf-8+ :content "e" :method :put)
The resulting request looks like this:
PUT / HTTP/1.1 Host: odeon:5984 User-Agent: Drakma/0.11.1 (OpenMCL Version 1.1-pre-070722 (DarwinX8664); Darwin; 9.1.0; http://weitz.de/drakma/) Accept: */* Connection: close Content-Type: application/xml Content-Length: 1
e
Which is right. But if I replace the "e" content with "é" (e accent acute), the request looks like this:
PUT / HTTP/1.1 Host: odeon:5984 User-Agent: Drakma/0.11.1 (OpenMCL Version 1.1-pre-070722 (DarwinX8664); Darwin; 9.1.0; http://weitz.de/drakma/) Accept: */* Connection: close Content-Type: application/xml Content-Length: 1
..
The hex values of the ".." are C3 A9, which is the utf-8 value for é. The problem is, of course, that the content length is really 2.
I assume I'm doing something wrong, but I don't know what exactly that would be. Should I be calculating the length myself?
thanks for any pointers or suggestions.
- Peter
On Mon, 17 Dec 2007 12:45:51 -0500, "Peter Eddy" peter.eddy@gmail.com wrote:
Should I be calculating the length myself?
Yes. See here:
http://weitz.de/drakma/#content-length
One could argue that Drakma should be able to compute the right value itself, but this is more trickier than one first thinks. Of course, if you think you know how to do this in a way that covers all corner cases, I'd be happy to accept a patch. The general design philosophy of Drakma is that it should be as easy to use as possible.
Thanks, Edi.
On Dec 17, 2007 3:25 PM, Edi Weitz edi@agharta.de wrote:
On Mon, 17 Dec 2007 12:45:51 -0500, "Peter Eddy" peter.eddy@gmail.com wrote:
Should I be calculating the length myself?
Yes. See here:
http://weitz.de/drakma/#content-length
One could argue that Drakma should be able to compute the right value itself, but this is more trickier than one first thinks. Of course, if you think you know how to do this in a way that covers all corner cases, I'd be happy to accept a patch. The general design philosophy of Drakma is that it should be as easy to use as possible.
It turns out that in my case setting content-length to nil (and therefore using chunked encoding) works perfectly. I was sure I'd tried that before, but must not have. Anyway, I think that qualifies as easy.
Thanks!
- Peter