ref: 9c79deb130cc64d12a567efbe372e366eb9a53fa
parent: a2e26ffd4c8d65368503fb36ced68353e3cfdb52
author: cinap_lenrek <[email protected]>
date: Mon Apr 30 18:09:57 EDT 2012
mothra: handle http compression out of band
--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -825,6 +825,7 @@
int urlopen(Url *url, int method, char *body){
int conn, ctlfd, fd, n;
char buf[1024+1], *p;
+ char encoding[64];
if(debug) fprint(2, "urlopen %s (%s)\n", url->reltext, url->basename);
@@ -863,11 +864,19 @@
}
snprint(buf, sizeof buf, "%s/%d/body", mtpt, conn);
if((fd = open(buf, OREAD)) < 0)
- goto ErrOut;
+ goto ErrOut;
snprint(buf, sizeof buf, "%s/%d/parsed", mtpt, conn);
readstr(url->fullname, sizeof(url->fullname), buf, "url");
readstr(url->tag, sizeof(url->tag), buf, "fragment");
+ snprint(buf, sizeof buf, "%s/%d", mtpt, conn);
+ readstr(encoding, sizeof(encoding), buf, "contentencoding");
close(ctlfd);
+ if(!cistrcmp(encoding, "compress"))
+ fd = pipeline("/bin/uncompress", fd);
+ else if(!cistrcmp(encoding, "gzip"))
+ fd = pipeline("/bin/gunzip", fd);
+ else if(!cistrcmp(encoding, "bzip2"))
+ fd = pipeline("/bin/bunzip2", fd);
return fd;
}
@@ -955,17 +964,8 @@
message("getting %s", selection->fullname);
if(mothmode && !plumb)
typ = -1;
- else {
+ else
typ = snooptype(fd);
- if(typ == GUNZIP){
- fd=pipeline("/bin/gunzip", fd);
- typ = snooptype(fd);
- }
- if(typ == COMPRESS){
- fd=pipeline("/bin/uncompress", fd);
- typ = snooptype(fd);
- }
- }
switch(typ){
default:
if(plumb){
--- a/sys/src/cmd/mothra/mothra.h
+++ b/sys/src/cmd/mothra/mothra.h
@@ -52,8 +52,6 @@
BMP,
ICO,
- GUNZIP,
- COMPRESS,
PAGE,
};
--- a/sys/src/cmd/mothra/snoop.c
+++ b/sys/src/cmd/mothra/snoop.c
@@ -102,9 +102,6 @@
"image/bmp", BMP,
"image/x-icon", ICO,
- "application/x-gzip", GUNZIP,
- "application/x-compress", COMPRESS,
-
"application/pdf", PAGE,
"application/postscript", PAGE,
"application/ghostscript", PAGE,