git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/6] gitweb: Separate HTTP header output

From
Junio C Hamano <junkio@cox.net>
Date
Dec 28, 2006, 01:23 UTC
Message-ID
<7v7iwc4xu9.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<200612272357.56532.jnareb@gmail.com>
Jakub Narebski <jnareb@gmail.com> writes:
Show 10 quoted lines
> Always return just after HTTP header is sent when asking only about
> headers (HTTP request method 'HEAD'); first appeared in git_rss.
>
> While at it uniquify style of http_header(...) calls, formerly
> "print $cgi->header(...)", and remove default HTTP status, '200 OK'.
>
> Signed-off-by: Jakub Narebski <jnareb@gmail.com>
> ---
> This one is fairly generic, and if considered worthy, I think
> can be accepted without much ado.

Maybe I am missing something fundamental, but I cannot see how this affects anything whatsoever...

Show 11 quoted lines
> +## functions printing HTTP or HTML: header, footer, error page
> +
> +sub http_header {
> +	my @header = @_;
> +
> +	print $cgi->header(@header);
> +
> +	# Optimization: skip generating the body if client asks only
> +	# for HTTP header (e.g. cache validation).
> +	return if ($cgi->request_method() eq 'HEAD');
> +}

Ok, so this explicitly written "return" returns when it is a HEAD request not GET. Otherwise the control falls out of the end of the function. Either way you return undef.

Then the caller does...
Show 14 quoted lines
> @@ -1709,8 +1719,11 @@ sub git_header_html {
>  	} else {
>  		$content_type = 'text/html';
>  	}
> -	print $cgi->header(-type=>$content_type, -charset => 'utf-8',
> -	                   -status=> $status, -expires => $expires);
> +	http_header(
> +		-type => $content_type,
> +		-charset => 'utf-8',
> +		-status => $status,
> +		-expires => $expires);
>  	print <<EOF;
>  <?xml version="1.0" encoding="utf-8"?>
>  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

which means it does not omit generating the body anyway no matter what "sub http_header" did...

Or is there some Perl magic that makes a return from sub named *_header magically terminate the execution of the caller?

Puzzled...
Previous: Jakub NarebskiNext: Shawn Pearce
Message 3 of 11 in “gitweb: Some mod_perl specific support (but not only)”
  1. 0/6 gitweb: Some mod_perl specific support (but not only)Jakub Narebski, Dec 27, 2006
  2. 1/6 gitweb: Separate HTTP header outputJakub Narebski, Dec 27, 2006
  3. Junio C HamanoDec 28, 2006
  4. Shawn PearceDec 28, 2006
  5. 2/6 gitweb: Add mod_perl version string to "generator" meta headerJakub Narebski, Dec 27, 2006
  6. 3/6 gitweb: Precompile CGI routines for mod_perlJakub Narebski, Dec 27, 2006
  7. 4/6 gitweb: Prepare for mod_perl specific supportJakub Narebski, Dec 27, 2006
  8. 5/6 gitweb: Make possible to run under mod_perl without SetupEnvJakub Narebski, Dec 27, 2006
  9. 6/6 gitweb: Make possible to run under mod_perl without ParseHeadersJakub Narebski, Dec 28, 2006
  10. Robert FitzsimonsDec 28, 2006
  11. Jakub NarebskiDec 28, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.