From nobody@FreeBSD.org  Thu Jul  4 08:53:45 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	by hub.freebsd.org (Postfix) with ESMTP id 4186DA90
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  4 Jul 2013 08:53:45 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	by mx1.freebsd.org (Postfix) with ESMTP id 34DE81820
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  4 Jul 2013 08:53:45 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r648rihu022022
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 4 Jul 2013 08:53:44 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r648ri3t022014;
	Thu, 4 Jul 2013 08:53:44 GMT
	(envelope-from nobody)
Message-Id: <201307040853.r648ri3t022014@oldred.freebsd.org>
Date: Thu, 4 Jul 2013 08:53:44 GMT
From: "Oleg A. Mamontov" <oleg@mamontov.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: libfetch https/HTTP_PROXY bug
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         180253
>Category:       kern
>Synopsis:       [libfetch] [patch] libfetch https/HTTP_PROXY bug
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    des
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jul 04 09:00:00 UTC 2013
>Closed-Date:    Fri Jul 05 09:36:08 UTC 2013
>Last-Modified:  Fri Jul 05 09:36:08 UTC 2013
>Originator:     Oleg A. Mamontov
>Release:        9.1-RELEASE-p4
>Organization:
>Environment:
FreeBSD bsd.moda.local 9.1-RELEASE-p4 FreeBSD 9.1-RELEASE-p4 #0: Mon Jun 17 11:42:37 UTC 2013     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
/usr/bin/fetch utility does not download files over https when environment variable HTTP_PROXY is set.
When establishing tcp ssl connection, host and port are chosen correctly (regardless of the variable HTTP_PROXY):
if (purl && strcasecmp(URL->scheme, SCHEME_HTTPS) != 0) {
    URL = purl;

But GET string is formed not quite correct:
if (purl) {
    http_cmd(conn, "%s %s://%s%s HTTP/1.1",
        op, url->scheme, host, url->doc);

As a result, the https request string looks like this:
GET https://some.host/uri HTTP/1.1

While this is technically correct, some web servers do not serve these requests and returns '400 Bad Request'.
>How-To-Repeat:
env HTTP_PROXY=foo fetch https://github.com/simpl/ngx_devel_kit/tarball/v0.2.18/simpl-ngx_devel_kit-v0.2.18-0-g48bc5dd.tar.gz
fetch: https://github.com/simpl/ngx_devel_kit/tarball/v0.2.18/simpl-ngx_devel_kit-v0.2.18-0-g48bc5dd.tar.gz: Bad Request
>Fix:
--- /usr/src/lib/libfetch/http.c.orig	2013-07-04 12:31:44.743957898 +0400
+++ /usr/src/lib/libfetch/http.c	2013-07-04 12:32:14.552958838 +0400
@@ -1566,7 +1566,7 @@
 		if (verbose)
 			fetch_info("requesting %s://%s%s",
 			    url->scheme, host, url->doc);
-		if (purl) {
+		if (purl && strcasecmp(URL->scheme, SCHEME_HTTPS) != 0) {
 			http_cmd(conn, "%s %s://%s%s HTTP/1.1",
 			    op, url->scheme, host, url->doc);
 		} else {



env HTTP_PROXY=foo fetch https://github.com/simpl/ngx_devel_kit/tarball/v0.2.18/simpl-ngx_devel_kit-v0.2.18-0-g48bc5dd.tar.gz
simpl-ngx_devel_kit-v0.2.18-0-g48bc5dd.tar.gz 100% of   63 kB  237 kBps

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Jul 5 08:25:27 UTC 2013 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=180253 
State-Changed-From-To: open->closed 
State-Changed-By: des 
State-Changed-When: Fri Jul 5 09:36:06 UTC 2013 
State-Changed-Why:  
Won't fix, please upgrade to 9-STABLE or wait for 9.2-RELEASE. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=180253 
>Unformatted:
