You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Matthew Darwin <ma...@davin.ottawa.on.ca> on 2001/04/16 21:11:12 UTC

sending a response without a Content-Type header

I'm buiding an HTTP gateway in mod_perl and trying to send back to the
client exactly what I get from the remote server.  The remote server
doesn't set a Content-Type on the document being returned, so I don't want
to set one either.

However, Mod_perl (or Apache), doesn't like it when I don't send a
Content-type and seems to send a default of text/plain regardless.  I
don't want this.  I don't want any Content-type at all.

What I have now is sending mod_perl a Content-Type of ''.  This sends a
blank Content-Type to the browser.  How can I avoid doing this?

Suggestions?


Here is an abbreviated program:


sub handler {
	my $r = Apache->request;
	my $ip = '1.2.3.4'; my $port = 80;

	my $ua = new LWP::UserAgent;
	my $request = new HTTP::Request $r->method, "http://$ip:$port" . $r->uri;
	my $response = $ua->request($request);

	if (defined $response->header('Content-type')) {
		$r->content_type($res->header('Content-type'));
	} else {
		$r->content_type('');   # don't want to do this
	}
	$r->status($response->code);
	$r->status_line(join " ", $response->code, $response->message);
	$response->scan(sub {
		$r->header_out(@_);
	});

	$r->send_http_header;
	$r->print($response->content);
}

This is actually what the device returns:


% telnet realdevice 80
Trying 1.2.3.4...
Connected to realdevice.
Escape character is '^]'.
GET /

HTTP/1.0 200 OK

<HTML>
[chop]
</HTML>

-- 
Matthew Darwin
matthew@davin.ottawa.on.ca


Re: sending a response without a Content-Type header

Posted by Doug MacEachern <do...@covalent.net>.
On Mon, 16 Apr 2001, Matthew Darwin wrote:

> 
> I'm buiding an HTTP gateway in mod_perl and trying to send back to the
> client exactly what I get from the remote server.  The remote server
> doesn't set a Content-Type on the document being returned, so I don't want
> to set one either.
> 
> However, Mod_perl (or Apache), doesn't like it when I don't send a
> Content-type and seems to send a default of text/plain regardless.  I
> don't want this.  I don't want any Content-type at all.
> 
> What I have now is sending mod_perl a Content-Type of ''.  This sends a
> blank Content-Type to the browser.  How can I avoid doing this?
... 
> 	$r->send_http_header;

roll your own version of send_http_header.  apache's send_http_header will
always send a content-type, part of being rfc compliant i guess.