发送到HTTP代理服务器的URL格式是什么?

时间:2013-11-18 14:21:53

标签: https proxy http-redirect

当我的应用程序从服务器(通过https)请求特定URL时,它会获得301 Moved Permanently重定向。但是,Location标头格式错误。我看到这样的事情:

> GET https://myserver/url HTTP/1.1
< 301 Moved Permanently
< Location: https://redirectedserverhttp://myserver/url

如果我在没有主机的情况下发送请求,我会得到一个格式正确的网址:

> GET /url HTTP/1.1
< 301 Moved Permanently
< Location: https://redirectedserver/url

我正在通过代理服务器并根据RFC 2068第5.1.2节,&#34; 在向代理发出请求时需要absoluteURI表单&# 34;所以看起来我正在以正确的方式做到这一点,但代理响应不正确。如果我通过浏览器尝试这个,curl或wget它工作正常。我查看了wget代码,逻辑如下:

if( proxy && !https ) {
    use absoluteURI
} else {
    use relativeURI
}

Wget甚至在其源代码中有评论:

/* When using SSL over proxy, CONNECT establishes a direct
   connection to the HTTPS server.  Therefore use the same
   argument as when talking to the server directly. */

这是在某处定义的实际标准吗?如果应该使用绝对URI表单,为什么其他工具使用它,为什么它失败?

2 个答案:

答案 0 :(得分:4)

您只能使用HTTP发送绝对网址。无论如何,它们都无法使用HTTPS ,因为代理不会看到它们。它只能看到CONNECT标题,其他所有内容都已加密。

使用无效URL的代理不是代理,而是服务器本身。 代理无法查看或响应,因为它也是加密的。

答案 1 :(得分:0)

通常,您会为每个http请求发送一个http标头 这是一个用https://example.org的歌剧蜻蜓工具构建的例子:

GET / HTTPS/1.1
Host: example.org
User-Agent: Opera/9.80 (X11; Linux x86_64; Edition Next) Presto/2.12.378 Version/12.50
Accept: text/html, application/xml;q=0.9, application/xhtml xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
Accept-Language: en
Accept-Charset: iso-8859-1, utf-8, utf-16, utf-32, *;q=0.1
Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0
Connection: Keep-Alive, TE
TE: deflate, gzip, chunked, identity, trailers

响应:

HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Sun, 24 Nov 2013 01:38:41 GMT
Etag: "359670651"
Expires: Sun, 01 Dec 2013 01:38:41 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (mia/41C4)
X-Cache: HIT
x-ec-custom-error: 1
Content-Length: 1270

<!doctype html>
<html>
<head>
    <title>Example Domain</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
    body {
        background-color: #f0f0f2;
        margin: 0;
        padding: 0;
        font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;

    }
    div {
        width: 600px;
        margin: 5em auto;
        padding: 50px;
        background-color: #fff;
        border-radius: 1em;
    }
    a:link, a:visited {
        color: #38488f;
        text-decoration: none;
    }
        @media (max-width: 700px) {
            body {
                background-color: #fff;
            }
            div {
                width: auto;
                margin: 0 auto;
                border-radius: 0;
                padding: 1em;
            }
        }
        </style>    
    </head>

    <body>
        <div>
            <h1>Example Domain</h1>
            <p>This domain is established to be used for illustrative examples in documents.   You may use this
        domain in examples without prior coordination or asking for permission.</p>
            <p><a href="http://www.iana.org/domains/example">More information...</a></p>
        </div>
    </body>
</html>

由于所有浏览器都会使用相对路径发送请求,因此代理开发人员可能会认为不值得为这部分标准而烦恼...