Forum OpenACS Q&A: Re: Res: Re: http requests with XoTCL

Collapse
Posted by Malte Sussdorff on
Ehm.... I just struggled for a couple of hours figuring out why my jodconverter service was complaining for an invalid output mime/type. After digging through their java code I realized that the Accept Header was set to */*. So I thought I set it with request_header_fields in ::xo:HttpRequest. Still no luck. Until I found that send_request sets this automatically to */*......

To get this to work nicely I made a change like this, which allows me to call the jodconverter with Accept: application/pdf to tell it that I want to have a PDF document returned to me. Byte the way, this makes the whole code for OpenOffice document PDF generation even easier than it was before. And I thought I could make a consulting business out of it.... Bad luck ......

Index: tcl/http-client-procs.tcl
===================================================================
--- tcl/http-client-procs.tcl (Revision 475)
+++ tcl/http-client-procs.tcl (Arbeitskopie)
@@ -144,6 +144,7 @@
Attribute port
Attribute path -default "/"
Attribute url
+ Attribute accept -default "*/*"
Attribute post_data -default ""
Attribute content_type -default "text/plain"
Attribute request_header_fields -default {}
@@ -302,11 +303,11 @@
}

HttpCore instproc send_request {} {
- my instvar S post_data host
+ my instvar S post_data host accept
if {[catch {
set method [expr {$post_data eq "" ? "GET" : "POST"}]
puts $S "$method [my path] HTTP/1.0"
- puts $S "Accept: */*"
+ puts $S "Accept: $accept"
puts $S "Host: $host"
puts $S "User-Agent: [my user_agent]"
foreach {tag value} [my request_header_fields] {

Collapse
Posted by Gustaf Neumann on
Malte,

good catch. I have actually no idea, why "accept: */*" was there (the rfc says, it is optional). It is certainly not a good idea to hard-code the transmission.

Since i see no good reason to set this header-field differently than other request header fields, i took another approach and removed the automatic transmission of "accept" altogether. If a client wants to specify "accept", it can be done - like for all other header fields - via request_header_fields, seems that it was your first guess as well.

-gustaf neumann
PS: fixed in CVS head.