Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: pure zsh implementation of wget
- X-seq: zsh-users 16399
- From: Guido van Steen <gvsteen@xxxxxxxxx>
- To: Mikael Magnusson <mikachu@xxxxxxxxx>
- Subject: Re: pure zsh implementation of wget
- Date: Thu, 22 Sep 2011 22:23:09 -0700 (PDT)
- Cc: zsh-users@xxxxxxx
- 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=;
- In-reply-to: <CAHYJk3RSzc0kReHoWDqA1qyLMkotRYu2bm3QkQvdDMJCRWOduw@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
Thanks a lot! With these additions it also works for me.
How difficult would it be to make this handle https as well?
Is there any existing implementation that handles https?
Best wishes,
Guido
--- On Fri, 23/9/11, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> From: Mikael Magnusson <mikachu@xxxxxxxxx>
> Subject: Re: pure zsh implementation of wget
> To: "Guido van Steen" <gvsteen@xxxxxxxxx>
> Cc: zsh-users@xxxxxxx
> Date: Friday, 23 September, 2011, 4:50 AM
> On 22 September 2011 23:06, Guido van
> Steen <gvsteen@xxxxxxxxx>
> wrote:
> > Hi!
> >
> > I was wondering if someone could point me to a pure
> zsh implementation of a function/script that downloads files
> like wget.
> >
> > I have been look at this (slightly modified from http://rosettacode.org/wiki/HTTP#Zsh):
> >
> > $cat wget.zsh
> > #!/usr/bin/env zsh
> > zmodload zsh/net/tcp
> > ztcp google.com 80
> > fd=$REPLY
> > print -l -u $fd -- 'GET / HTTP/1.1' 'Host: google.com'
> ''
> > while read -u $fd -r -e -t 1; do; :; done
> > ztcp -c $fd
> >
> > However, when I run this script, I do not receive any
> files. Neither do I observe any other results. I tried it
> with other sites, e.g. replacing google.com by localhost,
> and so on.
> > Does someone know what am I missing?
>
> It works for me, but there are a couple of problems. It
> uses a timeout
> of one second, so if your connection is slow it won't do
> anything, and
> it doesn't include the dos newlines i believe you should
> have in http.
> A more severe problem is that it uses read without setting
> IFS empty
> which means it will mangle initial whitespace input. All
> these issues
> (but possibly not others) are solved here (possibly):
>
> #!/bin/zsh
> zmodload zsh/net/tcp
> ztcp google.com 80
> fd=$REPLY
> print -l -u $fd -- 'GET / HTTP/1.1'$'\015' 'Host:
> www.google.com'$'\015' 'Connection: close'$'\015' $'\015'
> while IFS= read -u $fd -r -e; do; :; done
> ztcp -c $fd
>
> note that gmail will insert a newline in the print line, so
> join that
> back yourself :) Instead of the while loop you can also
> just write cat
> <&$fd
>
> > BTW, would this work with https as well?
>
> Definitely not :).
>
> --
> Mikael Magnusson
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author