Okay, so you've installed niwt. Now what?
At this point in time, niwt still needs a lot of work before it can do anything terribly useful. It can fetch web pages that are specified on the command line:
niwt niwt.addictivecode.org/TryingOutNiwt/
(That should leave results in ./niwt.addictivecode.org/TryingOutNiwt/index.html.) But if you try the same command again, right now it'll refuse to save the file (soon I'll change this to saving to a new, unique name, like wget does).
It can't do recursion (yet), and it can't even recover from download interruption (yet). It can't really do much of anything else yet, but the point of the current pre-pre-prerelease isn't so much to show what niwt is capable of, as to show what it could be capable of, how it's put together, and how customizing and extending niwt's behavior is managed.
If, for instance, you'd like to have a peek at the HTTP request messages that niwt would be sending to the server, you can redefine niwt's underlying shell pipeline to consist just of the request-generating part, leaving off the fetching and storing bits:
niwt --pline it=pline:requests-generate niwt.addictivecode.org/TryingOutNiwt/
Result:
GET /TryingOutNiwt/ HTTP/1.1 User-Agent: Niwt/0.1-devel Accept: */* Niwt-Pt-Request-Uri: http://niwt.addictivecode.org/TryingOutNiwt/ Host: niwt.addictivecode.org Connection: close
(Fun fact: the Niwt-Pt-Request-Uri will be used later on in the pipeline to choose the name of the file to be saved; the "Pt" stands for "pass-through", and indicates that the fetcher (which communicates with the server), should remove the header field before transmitting to the server, and reinsert it in the response.)
You can tweak the headers that niwt will send to the server. For instance, see how the output changes if you run:
niwt --pline it=pline:requests-generate --chain requests-filter+'chainsh HTTP_HELLO=World!' niwt.addictivecode.org/TryingOutNiwt/
Find a new header present?
We mentioned the Niwt-Pt-Request-Uri header is used to help determine the file name; if you modify that header, you can change the name Niwt saves to:
niwt --chain requests-filter+'chainsh "HTTP_NIWT_PT_REQUEST_URI=http://notniwt.com/notniwt.html"' niwt.addictivecode.org/TryingOutNiwt/
To ask niwt to spit out the server response headers (after some adjustments from Niwt), try this one:
niwt --pline consume='{ hdr; cat >/dev/null; }' niwt.addictivecode.org/TryingOutNiwt/Do an rm -fr niwt.addictivecode.org (so the existing download isn't there anymore—remember I said the current niwt milestone refuses to save if the file's already there?), and try inserting a content filter; this example translates the contents into 1337speak:
niwt --pline fetch+'niwt-content-filter "tr olneasbtg 012345679"' micah.cowan.name/resume/resume.txt
(URL chosen because it was the first text/plain link that sprang to mind, not because I'm trying to shill myself out
)
Guess what? You can even extend niwt with your own custom option that does the same thing. Write the following to the file ~/.niwtrc:
plines_opt_reg --1337 'Transform content body into 1337speak.'
plines_opt_fn_1337() {
plines_pline_append fetch 'niwt-content-filter "tr olneasbtg 012345679"'
}Now check out niwt --help | grep -C 3 l337 to see your new option in the help message output, and try it out (remember to remove any existing files):
niwt --1337 micah.cowan.name/resume/resume.txt
For any of the above commands, try adding --expand it or --show it to see how your command changes the shell code that niwt runs.
To understand the mechanics behind how these command-line directives are altering the shell pipelines, try reading Plines, NiwtInternals, PlinesExecChain and HeaderFilterChain.
If you'd like to keep abreast of niwt as it progresses—or better yet, take part in helping develop it into the full-fledged, fully-customizable web client it's intended to be, then join the MailingList and climb aboard!
