zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: pure zsh implementation of wget
Date: Sat, 24 Sep 2011 10:58:34 -0700	[thread overview]
Message-ID: <110924105834.ZM24858@torch.brasslantern.com> (raw)
In-Reply-To: <1316882951.6522.YahooMailClassic@web65610.mail.ac4.yahoo.com>

On Sep 24,  9:49am, Guido van Steen wrote:
}
} One more question: How should I modify that snippet to download a
} random url, such as like
} http://security.debian.org/pool/updates/main/i/isc-dhcp/dhcp3-client_4.1.1-P1-15+squeeze3_all.deb

I think you mean "arbitrary" rather than "random"?

Which in turn means you want to parse the URL.  A quick way is probably

  IFS=/ read scheme empty server resource <<<$theurl

which leads to

zwget() {
    emulate -LR zsh
    local scheme empty server resource fd
    IFS=/ read scheme empty server resource <<<$1
    case $scheme in
    (https:) print -u2 SSL unsupported, falling back on HTTP ;&
    (http:)
	zmodload zsh/net/tcp
	ztcp $server 80 && fd=$REPLY || exit 1;;
    (*) print -u2 $scheme unsupported; exit 1;;
    esac
    print -l -u$fd -- \
	"GET /$resource HTTP/1.1"$'\015' \
	"Host: $server"$'\015' \
	'Connection: close'$'\015' $'\015'
    while IFS= read -u $fd -r -e; do; :; done
    ztcp -c $fd
}

You can probably work out how to support ftp: using the zsh/zftp module.


  reply	other threads:[~2011-09-24 17:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-22 21:06 Guido van Steen
2011-09-22 21:50 ` Mikael Magnusson
2011-09-23  5:23   ` Guido van Steen
2011-09-23  6:57     ` Mikael Magnusson
2011-09-23  7:13       ` Guido van Steen
2011-09-23 12:06         ` Guillaume Brunerie
2011-09-23 12:12           ` İsmail Dönmez
2011-09-23  7:01     ` Bart Schaefer
2011-09-23  7:16       ` Guido van Steen
2011-09-27  9:02     ` Oliver Kiddle
2011-09-24 16:49   ` Guido van Steen
2011-09-24 17:58     ` Bart Schaefer [this message]
2011-09-24 20:23       ` Guido van Steen
2011-09-24 21:11         ` Guido van Steen
2011-09-24 21:42         ` Bart Schaefer
2011-09-22 21:53 ` Stephane Bortzmeyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=110924105834.ZM24858@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).