From: Jeff Hobbs on
On Feb 21, 9:21 am, Zbigniew Diaczyszyn <z....(a)gmx.de> wrote:
> Thank you very much. I found the file, copied it to http-2.7.5.tcl,
> adapted it to my needs (some "puts" commands, renaming http::Log to
> http::_Log and redefining it with: "http::Log {msg} {puts $msg}" and so
...
> Here is some output in Tkcon:

Since you are using tkcon, you can use its built-in debug and tracing
commands to get something similar to your changes without touching the
code. e.g., try 'observe command http::Log':
http://tkcon.sourceforge.net/docs/observe.html

Jeff
From: Zbigniew Diaczyszyn on
Jeff Hobbs schrieb:

> Since you are using tkcon, you can use its built-in debug and tracing
> commands to get something similar to your changes without touching the
> code. e.g., try 'observe command http::Log':
> http://tkcon.sourceforge.net/docs/observe.html

Thank you for the hint but http::Log is not presenting enough
information. Since the Amazon Webserver (amazonaws.com) is not allowing
TRACE and wireshark cannot be used so I have to get the request by
tracing all "puts $sock" commands in the http.tcl code. In fact, even
such details as a space character too much or a cr-lf too little can
cause problems.

The Amazon Webserver needs a request somehow like that (example taken
from the Amazon webserver site:

POST / HTTP/1.1
Host: johnsmith.s3.amazonaws.com

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.10)
Gecko/20071115 Firefox/2.0.0.10

Accept: */*
Content-Type: multipart/form-data; boundary=9431149156168
Content-Length: 2661134

--9431149156168
Content-Disposition: form-data; name="key"

user/eric/MyPicture.jpg
--9431149156168
Content-Disposition: form-data; name="acl"

public-read
[...]
--9431149156168
Content-Disposition: form-data; name="file"; filename="MyFilename.jpg"

Content-Type: image/jpeg

....file content...
--9431149156168

As a quick and dirty workaround I added the following lines after the
headers managing lines in http-2.7.5.tcl:

if {[info exists state(-type)] && [regexp {multipart} $state(-type)]} {
puts $sock $http::formdata
puts $http::formdata
}

And the multipart request is done by:

set http::formdata "Content-Type: multipart/form-data;
boundary=$boundary\r\n\r\n$formdata"

set response [http::geturl "$url/" -headers "Host
github.s3.amazonaws.com" -method "POST" -type "multipart/form-data;
boundary=$boundary" -keepalive 1]

Perhaps future versions enable "multipart/form-data" POST requests :-)

Apropos: The chapter HTTP in the book "Practical Programming in Tcl and
Tk was very informative and well-written. To study the actual 2.7.5 code
was like reading a good book, too. I really like Tcl.

Zbigniew Diaczyszyn
From: Zbigniew Diaczyszyn on
drscrypt(a)gmail.com schrieb:

> So, it looks like it is working just fine from here. Is this the url
> that is giving you trouble?

No, my apache is working fine. It is the Amazonian part which is making
trouble ...

>
> However, it does not support the -method option you are using. Maybe
> turn that into a query parameter?
>

I tried but the request is complicated. You have to put all the
credentials in the query string which is no good idea.

Zbigniew Diaczyszyn
From: Zbigniew Diaczyszyn on
tom.rmadilo schrieb:

> I guess this is a side issue. Are you unable to configure which
> version of HTTP you send with the ::http::geturl ? That would be too
> bad, since one way to disable chunked responses is to send only an
> HTTP/1.0 request.

I am working now with http package version 2.5.7 which is handling
chunked responses and presenting HTTP/1.1 requests.

After adapting the source code I am getting now good debugging informations
>
> My experimental HTTP client (htclient) allows you to choose the HTTP
> version. Then you can print the request using:
>
> % ::htclient::getVar client1 request
> GET /files/ HTTP/1.0
> Host: rmadilo.com
> User-Agent: TclClient/1.0
> Connection: close
>
> For instance the above request is generated like this:
> % ::htclient::addClient rmadilo.com 80 /files/ GET {User-Agent
> TclClient/1.0 Connection close} {} 1.0
> client23
>
> client23 is the handle, so you can prepare the request (testing only):
>
> % ::htclient::htPrepare client23
> GET /files/ HTTP/1.0
> Host: rmadilo.com
> User-Agent: TclClient/1.0
> Connection: close
>
> Otherwise to perform the request:
>
> % ::htclient::machine client23
> % catch {vwait forsomething}
> %
> Now the content is in ::htclient::clientContent(client23)
>

Is your client able to perform a "multipart/form-data" request?

Zbigniew
From: tom.rmadilo on
On Feb 22, 12:56 pm, Zbigniew Diaczyszyn <z....(a)gmx.de> wrote:
> tom.rmadilo schrieb:
>
> > I guess this is a side issue. Are you unable to configure which
> > version of HTTP you send with the ::http::geturl ? That would be too
> > bad, since one way to disable chunked responses is to send only an
> > HTTP/1.0 request.
>
> I am working now with http package version 2.5.7 which is handling
> chunked responses and presenting HTTP/1.1 requests.
>
> After adapting the source code I am getting now good debugging informations


Cool, BTW, I usually start with code which has "puts ..." and do a
replace to substitute in the "log $level". IMHO it is better to add
logging statements everywhere the developer sees the need. They are
extremely easy to transform as needed.


>
> > My experimental HTTP client (htclient) allows you to choose the HTTP
> > version. Then you can print the request using:
>
> > % ::htclient::getVar client1 request
> > GET /files/ HTTP/1.0
> > Host: rmadilo.com
> > User-Agent: TclClient/1.0
> > Connection: close
>
> > For instance the above request is generated like this:
> > % ::htclient::addClient rmadilo.com 80 /files/ GET {User-Agent
> > TclClient/1.0 Connection close} {} 1.0
> > client23
>
> > client23 is the handle, so you can prepare the request (testing only):
>
> > % ::htclient::htPrepare client23
> > GET /files/ HTTP/1.0
> > Host: rmadilo.com
> > User-Agent: TclClient/1.0
> > Connection: close
>
> > Otherwise to perform the request:
>
> > % ::htclient::machine client23
> > % catch {vwait forsomething}
> > %
> > Now the content is in ::htclient::clientContent(client23)


> Is your client able to perform a "multipart/form-data" request?

Of course, but you have to write the payload yourself. hclient
provides an API which is focused on the basics: sending a request and
receiving the response (of course this is all event driven, non-
blocking...unlike geturl with chunked encoding). The response gets
parsed into tokens and validated at a very simple syntax level. I
consider this a benefit: the headers are broken into tokens, minus any
optional whitespace and required whitespace (required whitespace
delimits tokens, so it isn't needed after parsing). So application
developers can start with a list of tokens instead of spending time
validating or fixing the parsing code. It is somewhat painful to loop
over whitespace.

Also, htclient is significantly faster/more efficient than geturl. I
haven't figure out exactly why yet, but I think geturl spends too much
time in string manipulations. Basically I would say htclient is good
for developers, not so good for the casual user.
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8
Prev: hard drive serial number
Next: uploading a file and form data