From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16387 invoked by alias); 23 Sep 2011 05:28:59 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16399 Received: (qmail 4501 invoked from network); 23 Sep 2011 05:28:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at yahoo.com does not designate permitted sender hosts) X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 109469.98936.bm@omp1043.mail.ac4.yahoo.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1316755390; bh=1FBfOG+S9TSNqjTPqqbXj5zqC1/7zlpr/E3W39aGKcc=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=Vo1YAdm6NHTUMtHwgReEG8WtXdpT+PaGZu74oGtVypjxEpQGSnWeC+yQIwCIqFqxn6P0xzLuzm2U5BQFt/hFS3FNyxyHvAxTw9f9bGhW13oxFhY989vCOPgr9FU6s8Cd4IlwIauGaHhyR8XEYc5Sgomvf/N6SGrBshcBoZz8ZQw= DomainKey-Signature:a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=3+c8Cr8KkcxAs3cMRIGsd4Wle+dqy4XkrCBhnCApOVvQv2Zd3kD4qUhApIJttQqQUxo8qLPjdqUUYTLIqZ4GsJvKhdtZHpC4rpB/pSpTLz87YKWJaoPkUk8Do9PXNs5VoH7F59MF9H3475bgkG5iT97xTQ30nJw5Jo/NyIcVh4A=; X-YMail-OSG: H7LaYvYVM1mT.lZeXagy0.WNY7UMG7L2vzJGh65y4aYmXca Iq490u_QZbV83vRlEqz5wxTlSyjVA3IQHvnuSqIaOz4KXUU_YICJcioOzfSR 8bcmTkO1txr02qTvZo8eFplZizb7uTDiUyCYtgPUNGVbfUsVV5PP5O73_SHp 8sy1boVV19j0vUnb9C09.CCWt98iJIsk6m4bq1OWUaV6evTn7XgZ4zNoc8OL EVfmNT0rzgHBhxk9rinSg6AiSbvqHXm1NuxVDBL7bfqEuXM_W0mKh1uHY3If AvGkWQAlFOL3HBWvxl_NxAMQDWL6KQyfwdy78CwFUX8FA2dz5Rvn8LqneQAY H5WO3ilMa9VMSzi0oCo_b1YrVQGPrWMsJFZn1I08dkiw5s7B23jSn6eBXIvw g6LbVAZX0Gqb29hDUyhhOI_6x0HTpndb73cNdh4MvWhzwOYTO17.7lEqmlo4 fJDMz3lSoAmSL6gFfMnE08ihEDk6MsEh3ugXboc8mHMf7KW27UO4LzWmuADi 68WJQxOFRRpwbwsimHet8MhDxbI6_kdTA7B5io1ysmYgPOZvcUFBwY2eGGw- - X-Mailer: YahooMailClassic/14.0.5 YahooMailWebService/0.8.113.315625 Message-ID: <1316755389.16877.YahooMailClassic@web65616.mail.ac4.yahoo.com> Date: Thu, 22 Sep 2011 22:23:09 -0700 (PDT) From: Guido van Steen Subject: Re: pure zsh implementation of wget To: Mikael Magnusson Cc: zsh-users@zsh.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Thanks a lot! With these additions it also works for me. =0A=0AHow difficul= t would it be to make this handle https as well? =0A=0AIs there any existin= g implementation that handles https? =0A=0ABest wishes, =0A=0AGuido =0A=0A-= -- On Fri, 23/9/11, Mikael Magnusson wrote:=0A=0A> From= : Mikael Magnusson =0A> Subject: Re: pure zsh implementa= tion of wget=0A> To: "Guido van Steen" =0A> Cc: zsh-user= s@zsh.org=0A> Date: Friday, 23 September, 2011, 4:50 AM=0A> On 22 September= 2011 23:06, Guido van=0A> Steen =0A> wrote:=0A> > Hi!= =0A> >=0A> > I was wondering if someone could point me to a pure=0A> zsh im= plementation of a function/script that downloads files=0A> like wget.=0A> >= =0A> > I have been look at this (slightly modified from http://rosettacode.= org/wiki/HTTP#Zsh):=0A> >=0A> > $cat wget.zsh=0A> > #!/usr/bin/env zsh=0A> = > zmodload zsh/net/tcp=0A> > ztcp google.com 80=0A> > fd=3D$REPLY=0A> > pri= nt -l -u $fd -- 'GET / HTTP/1.1' 'Host: google.com'=0A> ''=0A> > while read= -u $fd -r -e -t 1; do; :; done=0A> > ztcp -c $fd=0A> >=0A> > However, when= I run this script, I do not receive any=0A> files. Neither do I observe an= y other results. I tried it=0A> with other sites, e.g. replacing google.com= by localhost,=0A> and so on.=0A> > Does someone know what am I missing?=0A= > =0A> It works for me, but there are a couple of problems. It=0A> uses a t= imeout=0A> of one second, so if your connection is slow it won't do=0A> any= thing, and=0A> it doesn't include the dos newlines i believe you should=0A>= have in http.=0A> A more severe problem is that it uses read without setti= ng=0A> IFS empty=0A> which means it will mangle initial whitespace input. A= ll=0A> these issues=0A> (but possibly not others) are solved here (possibly= ):=0A> =0A> #!/bin/zsh=0A> zmodload zsh/net/tcp=0A> ztcp google.com 80=0A> = fd=3D$REPLY=0A> print -l -u $fd -- 'GET / HTTP/1.1'$'\015' 'Host:=0A> www.g= oogle.com'$'\015' 'Connection: close'$'\015' $'\015'=0A> while IFS=3D read = -u $fd -r -e; do; :; done=0A> ztcp -c $fd=0A> =0A> note that gmail will ins= ert a newline in the print line, so=0A> join that=0A> back yourself :) Inst= ead of the while loop you can also=0A> just write cat=0A> <&$fd=0A> =0A> > = BTW, would this work with https as well?=0A> =0A> Definitely not :).=0A> = =0A> -- =0A> Mikael Magnusson=0A>