telnet で proxy サーバーを使って HTTP

http://example.com/resource リソースを参照するときに proxy サーバー proxy.domain.jp ポート 8080 を通さなければならない。そして telnet で HTTP コマンドを使いたいときにどうするか?

まず、 proxy サーバーに telnet する:

$ telnet proxy.domain.jp 8080
Trying xxx.xxx.xxx.xxx...
Connected to proxy.domain.jp.
Escape character is '^]'.

proxy サーバーにつながったら HTTP リクエストを発行する:

GET http://example.com/resource HTTP/1.0

なぜこんな面倒なことが必要になったかというと、転送されるリソースを取得するときに curl -O では中身を取れなかったから。
(あ、でもひょっとして curl に転送先のリソースを取得するためのオプションがあったりするんだろうか…?)

もとい。

転送先のデータの URL を確認したときの操作メモ:

$ telnet proxy.domain.jp 8080
Trying xxx.xxx.xxx.xxx...
Connected to proxy.domain.jp.
Escape character is '^]'.
GET http://downloads.sourceforge.net/project/cunit/CUnit/2.1-0/CUnit-2.1-0-src.tar.gz HTTP/1.0     

HTTP/1.1 302 Found
X-Powered-By: PHP/5.2.9
Content-Disposition: attachment; filename="CUnit-2.1-0-src.tar.gz"
Location: http://jaist.dl.sourceforge.net/project/cunit/CUnit/2.1-0/CUnit-2.1-0-src.tar.gz
Content-type: text/html
Date: Fri, 03 Sep 2010 02:46:54 GMT
Server: lighttpd/1.4.26
Content-Length: 0
Connection: close

Connection closed by foreign host.

レスポンスの Location ヘッダーに実際のリソースの配置場所が、 Content-Disposition ヘッダーにファイル名が書かれていることがわかる。