Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

设置Host头无效 #12

Closed
sylingd opened this issue Oct 3, 2018 · 1 comment
Closed

设置Host头无效 #12

sylingd opened this issue Oct 3, 2018 · 1 comment
Labels
bug Something isn't working fixed

Comments

@sylingd
Copy link

sylingd commented Oct 3, 2018

测试代码:

<?php
require('vendor/autoload.php');

go(function() {
	$saber = Swlib\Saber::create([
		'base_uri' => 'http://127.0.0.1',
		'headers' => [
			'Host' => 'example.com',
			'X-Test' => 'test'
		]
	]);

	echo $saber->get('/host.php');
	
	echo "\n-------------------\n";
	
	$saber = Swlib\Saber::create([
		'base_uri' => 'http://127.0.0.1'
	]);
	$saber->setOptions([
		'headers' => [
			'Host' => 'example.com',
			'X-Test' => 'test'
		]
	]);

	echo $saber->get('/host.php');
});

服务器输出内容是:(打印了$_SERVER):

HTTP/1.1 200 OK
Server: nginx
Date: Wed, 03 Oct 2018 02:57:14 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Content-Encoding: gzip

Array
(
    [TEMP] => /tmp
    [TMPDIR] => /tmp
    [TMP] => /tmp
    [PATH] => /usr/local/bin:/usr/bin:/bin
    [USER] => www
    [HOME] => /home/www
    [HTTP_X_TEST] => test
    [HTTP_CONTENT_TYPE] => application/x-www-form-urlencoded
    [HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
    [HTTP_ACCEPT_ENCODING] => gzip
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
    [HTTP_HOST] => 127.0.0.1
    [HTTP_CONNECTION] => keep-alive
    [REDIRECT_STATUS] => 200
    [SERVER_NAME] => _
    [SERVER_PORT] => 80
    [SERVER_ADDR] => 127.0.0.1
    [REMOTE_PORT] => 46126
    [REMOTE_ADDR] => 127.0.0.1
    [SERVER_SOFTWARE] => nginx/1.12.2
    [GATEWAY_INTERFACE] => CGI/1.1
    [REQUEST_SCHEME] => http
    [SERVER_PROTOCOL] => HTTP/1.1
    [DOCUMENT_ROOT] => /web/wwwroot/default
    [DOCUMENT_URI] => /host.php
    [REQUEST_URI] => /host.php
    [SCRIPT_NAME] => /host.php
    [CONTENT_LENGTH] =>
    [CONTENT_TYPE] => application/x-www-form-urlencoded
    [REQUEST_METHOD] => GET
    [QUERY_STRING] =>
    [SCRIPT_FILENAME] => /web/wwwroot/default/host.php
    [FCGI_ROLE] => RESPONDER
    [PHP_SELF] => /host.php
    [REQUEST_TIME_FLOAT] => 1538535434.4496
    [REQUEST_TIME] => 1538535434
)

-------------------
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 03 Oct 2018 02:57:14 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Content-Encoding: gzip

Array
(
    [TEMP] => /tmp
    [TMPDIR] => /tmp
    [TMP] => /tmp
    [PATH] => /usr/local/bin:/usr/bin:/bin
    [USER] => www
    [HOME] => /home/www
    [HTTP_X_TEST] => test
    [HTTP_CONTENT_TYPE] => application/x-www-form-urlencoded
    [HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
    [HTTP_ACCEPT_ENCODING] => gzip
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
    [HTTP_HOST] => 127.0.0.1
    [HTTP_CONNECTION] => keep-alive
    [REDIRECT_STATUS] => 200
    [SERVER_NAME] => _
    [SERVER_PORT] => 80
    [SERVER_ADDR] => 127.0.0.1
    [REMOTE_PORT] => 46128
    [REMOTE_ADDR] => 127.0.0.1
    [SERVER_SOFTWARE] => nginx/1.12.2
    [GATEWAY_INTERFACE] => CGI/1.1
    [REQUEST_SCHEME] => http
    [SERVER_PROTOCOL] => HTTP/1.1
    [DOCUMENT_ROOT] => /web/wwwroot/default
    [DOCUMENT_URI] => /host.php
    [REQUEST_URI] => /host.php
    [SCRIPT_NAME] => /host.php
    [CONTENT_LENGTH] =>
    [CONTENT_TYPE] => application/x-www-form-urlencoded
    [REQUEST_METHOD] => GET
    [QUERY_STRING] =>
    [SCRIPT_FILENAME] => /web/wwwroot/default/host.php
    [FCGI_ROLE] => RESPONDER
    [PHP_SELF] => /host.php
    [REQUEST_TIME_FLOAT] => 1538535434.4521
    [REQUEST_TIME] => 1538535434
)

可以看到,X-Test头是成功了的,Host头修改无效

@twose twose closed this as completed in dbe817f Oct 3, 2018
@twose
Copy link
Member

twose commented Oct 3, 2018

设计失误, 被URI对象中的Host覆盖了两次, 一般场景都是直接填host的, 所以没有发现.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants