Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4ac23c133a | |||
| 54847f6d1d |
+38
-30
@@ -140,6 +140,8 @@ NgxConnection* NgxConnection::Connect(ngx_peer_connection_t* pc,
|
||||
|
||||
int rc = ngx_event_connect_peer(pc);
|
||||
if (rc == NGX_ERROR || rc == NGX_DECLINED || rc == NGX_BUSY) {
|
||||
ngx_log_error(NGX_LOG_DEBUG, pc->log, 0,
|
||||
"NgxFetch: ngx_event_connect_peer failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -363,14 +365,17 @@ bool NgxFetch::Init() {
|
||||
|
||||
GoogleString s_ipaddress(reinterpret_cast<char*>(tmp_url->host.data),
|
||||
tmp_url->host.len);
|
||||
ngx_memzero(&sin_, sizeof(sin_));
|
||||
sin_.sin_family = AF_INET;
|
||||
sin_.sin_port = htons(tmp_url->port);
|
||||
sin_.sin_addr.s_addr = inet_addr(s_ipaddress.c_str());
|
||||
|
||||
if (sin_.sin_addr.s_addr == INADDR_NONE) {
|
||||
// inet_addr returned INADDR_NONE, which means the hostname
|
||||
// isn't a valid IP address. Check DNS.
|
||||
ngx_memzero(&sin_, sizeof(sin_));
|
||||
if (s_ipaddress[0] == '[') {
|
||||
s_ipaddress = s_ipaddress.substr(1);
|
||||
}
|
||||
if (s_ipaddress[s_ipaddress.size() - 1] == ']') {
|
||||
s_ipaddress = s_ipaddress.substr(0, s_ipaddress.size()-2);
|
||||
}
|
||||
ngx_int_t res = ngx_parse_addr(pool_, &sin_, (u_char*)s_ipaddress.c_str(), s_ipaddress.size());
|
||||
if (res != NGX_OK) {
|
||||
// Hostname isn't a valid IP address. Check DNS.
|
||||
ngx_resolver_ctx_t temp;
|
||||
temp.name.data = tmp_url->host.data;
|
||||
temp.name.len = tmp_url->host.len;
|
||||
@@ -405,6 +410,16 @@ bool NgxFetch::Init() {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
u_char text[NGX_SOCKADDR_STRLEN];
|
||||
ngx_str_t addrtext;
|
||||
addrtext.len = ngx_sock_ntop(fetch->sin_.sockaddr, fetch->sin_.socklen,
|
||||
text, NGX_SOCKADDR_STRLEN, htons(fetcher->proxy_.url.len ? htons(fetcher->proxy_.port) : fetch->url_.port));
|
||||
ngx_log_error(NGX_LOG_DEBUG, fetch->log_, 0,
|
||||
"NgxFetch %p: Resolved host [%V] to [%V]", fetch,
|
||||
&resolver_ctx->name, &addrtext);
|
||||
*/
|
||||
((struct sockaddr_in *)sin_.sockaddr)->sin_port = htons(fetcher_->proxy_.url.len ? htons(fetcher_->proxy_.port) : url_.port);
|
||||
if (InitRequest() != NGX_OK) {
|
||||
message_handler()->Message(kError, "NgxFetch: InitRequest failed");
|
||||
return false;
|
||||
@@ -535,14 +550,14 @@ void NgxFetch::ResolveDoneHandler(ngx_resolver_ctx_t* resolver_ctx) {
|
||||
}
|
||||
|
||||
ngx_uint_t i;
|
||||
// Find the first ipv4 address. We don't support ipv6 yet.
|
||||
// Find the first ipv4 address. We don't support ipv6 yet in dns results.
|
||||
for (i = 0; i < resolver_ctx->naddrs; i++) {
|
||||
// Old versions of nginx and tengine have a different definition of addrs,
|
||||
// work around to make sure we are using the right type (ngx_addr_t*).
|
||||
ngx_addr_t* ngx_addrs = reinterpret_cast<ngx_addr_t*>(resolver_ctx->addrs);
|
||||
if (typeid(*ngx_addrs) == typeid(*resolver_ctx->addrs)) {
|
||||
if (reinterpret_cast<struct sockaddr_in*>(ngx_addrs[i].sockaddr)
|
||||
->sin_family == AF_INET) {
|
||||
->sin_family == AF_INET) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -566,37 +581,30 @@ void NgxFetch::ResolveDoneHandler(ngx_resolver_ctx_t* resolver_ctx) {
|
||||
ngx_memzero(&fetch->sin_, sizeof(fetch->sin_));
|
||||
|
||||
#if (nginx_version < 1005008)
|
||||
// TODO(oschaaf): need to test this again, might be broken.
|
||||
fetch->sin_.sin_addr.s_addr = resolver_ctx->addrs[i];
|
||||
#else
|
||||
struct sockaddr_in* sin;
|
||||
|
||||
sin = reinterpret_cast<struct sockaddr_in*>(
|
||||
resolver_ctx->addrs[i].sockaddr);
|
||||
|
||||
fetch->sin_.sin_family = sin->sin_family;
|
||||
fetch->sin_.sin_addr.s_addr = sin->sin_addr.s_addr;
|
||||
fetch->sin_ = resolver_ctx->addrs[i];
|
||||
#endif
|
||||
|
||||
fetch->sin_.sin_family = AF_INET;
|
||||
fetch->sin_.sin_port = htons(fetch->url_.port);
|
||||
|
||||
// Maybe we have Proxy
|
||||
if (0 != fetcher->proxy_.url.len) {
|
||||
fetch->sin_.sin_port = htons(fetcher->proxy_.port);
|
||||
}
|
||||
|
||||
char* ip_address = inet_ntoa(fetch->sin_.sin_addr);
|
||||
((struct sockaddr_in *)fetch->sin_.sockaddr)->sin_port =
|
||||
htons(fetcher->proxy_.url.len ? htons(fetcher->proxy_.port) : fetch->url_.port);
|
||||
|
||||
u_char text[NGX_SOCKADDR_STRLEN];
|
||||
ngx_str_t addrtext;
|
||||
addrtext.len = ngx_sock_ntop(fetch->sin_.sockaddr, fetch->sin_.socklen,
|
||||
text, NGX_SOCKADDR_STRLEN, htons(fetcher->proxy_.url.len ? htons(fetcher->proxy_.port) : fetch->url_.port));
|
||||
addrtext.data = text;
|
||||
ngx_log_error(NGX_LOG_DEBUG, fetch->log_, 0,
|
||||
"NgxFetch %p: Resolved host [%V] to [%s]", fetch,
|
||||
&resolver_ctx->name, ip_address);
|
||||
|
||||
fetch->release_resolver();
|
||||
"NgxFetch %p: Resolved host [%V] to [%V]", fetch,
|
||||
&resolver_ctx->name, &addrtext);
|
||||
|
||||
if (fetch->InitRequest() != NGX_OK) {
|
||||
fetch->message_handler()->Message(kError, "NgxFetch: InitRequest failed");
|
||||
fetch->CallbackDone(false);
|
||||
}
|
||||
fetch->release_resolver();
|
||||
}
|
||||
|
||||
// Prepare the request data for this fetch, and hook the write event.
|
||||
@@ -692,8 +700,8 @@ int NgxFetch::InitRequest() {
|
||||
int NgxFetch::Connect() {
|
||||
ngx_peer_connection_t pc;
|
||||
ngx_memzero(&pc, sizeof(pc));
|
||||
pc.sockaddr = (struct sockaddr*)&sin_;
|
||||
pc.socklen = sizeof(struct sockaddr_in);
|
||||
pc.sockaddr = sin_.sockaddr;
|
||||
pc.socklen = sin_.socklen;
|
||||
pc.name = &url_.host;
|
||||
|
||||
// get callback is dummy function, it just returns NGX_OK
|
||||
|
||||
+2
-1
@@ -191,7 +191,8 @@ class NgxFetch : public PoolElement<NgxFetch> {
|
||||
int64 content_length_;
|
||||
bool content_length_known_;
|
||||
|
||||
struct sockaddr_in sin_;
|
||||
|
||||
ngx_addr_t sin_;
|
||||
ngx_log_t* log_;
|
||||
ngx_buf_t* out_;
|
||||
ngx_buf_t* in_;
|
||||
|
||||
@@ -85,8 +85,6 @@ http {
|
||||
pagespeed StatisticsLogging on;
|
||||
pagespeed LogDir "@@TEST_TMP@@/logdir";
|
||||
|
||||
pagespeed MaxFetchRedirects 3;
|
||||
|
||||
# Expanded to CentralControllerPort directive when RUN_CONTROLLER_TEST=on
|
||||
@@CONTROLLER@@
|
||||
|
||||
@@ -1674,50 +1672,6 @@ http {
|
||||
pagespeed MessagesDomains Disallow *;
|
||||
pagespeed FileCachePath "@@FILE_CACHE@@";
|
||||
}
|
||||
|
||||
server {
|
||||
listen @@SECONDARY_PORT@@;
|
||||
listen [::]:@@SECONDARY_PORT@@;
|
||||
server_name redirecting-fetch.example.com;
|
||||
pagespeed FileCachePath "@@FILE_CACHE@@";
|
||||
pagespeed Domain redirecting-fetch.example.com:@@SECONDARY_PORT@@;
|
||||
pagespeed MapOriginDomain 127.0.0.1:@@SECONDARY_PORT@@
|
||||
redirecting-fetch.example.com:@@SECONDARY_PORT@@;
|
||||
pagespeed Disallow *styles/disallowed.css;
|
||||
pagespeed InPlaceResourceOptimization off;
|
||||
|
||||
location /redir_to_test/styles/blue.css {
|
||||
return 301 /mod_pagespeed_example/styles/yellow.css;
|
||||
}
|
||||
location /redir_to_test/styles/1.css {
|
||||
return 301 /redir_to_test/styles/2.css;
|
||||
}
|
||||
location /redir_to_test/styles/2.css {
|
||||
return 301 /mod_pagespeed_example/styles/yellow.css;
|
||||
}
|
||||
location /redir_to_test/styles/redirtodisallowed.css {
|
||||
return 301 /redir_to_test/styles/disallowed.css;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen @@SECONDARY_PORT@@;
|
||||
listen [::]:@@SECONDARY_PORT@@;
|
||||
server_name redirecting-fetch-single-only.example.com;
|
||||
pagespeed FileCachePath "@@FILE_CACHE@@";
|
||||
pagespeed MaxFetchRedirects 1;
|
||||
pagespeed Domain redirecting-fetch.example.com:@@SECONDARY_PORT@@;
|
||||
pagespeed MapOriginDomain 127.0.0.1:@@SECONDARY_PORT@@
|
||||
redirecting-fetch-single-only.example.com:@@SECONDARY_PORT@@;
|
||||
|
||||
location /redir_to_test/styles/1.css {
|
||||
return 301 /redir_to_test/styles/2.css;
|
||||
}
|
||||
location /redir_to_test/styles/2.css {
|
||||
return 301 /mod_pagespeed_example/styles/yellow.css;
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
server_name nothing-explicitly-allowed.example.com;
|
||||
pagespeed FileCachePath "@@FILE_CACHE@@";
|
||||
@@ -1831,6 +1785,25 @@ http {
|
||||
pagespeed DisableFilters add_instrumentation;
|
||||
pagespeed CriticalImagesBeaconEnabled false;
|
||||
}
|
||||
server {
|
||||
pagespeed on;
|
||||
listen @@SECONDARY_PORT@@;
|
||||
listen [::]:@@SECONDARY_PORT@@;
|
||||
server_name image-rewrite-with-flush.example.com;
|
||||
pagespeed FileCachePath "@@FILE_CACHE@@";
|
||||
pagespeed RewriteLevel PassThrough;
|
||||
pagespeed UrlValuedAttribute li data-thumb image;
|
||||
pagespeed EnableFilters core;
|
||||
location ~ \.php$ {
|
||||
fastcgi_param SCRIPT_FILENAME $request_filename;
|
||||
fastcgi_param QUERY_STRING $query_string;
|
||||
fastcgi_param REQUEST_METHOD $request_method;
|
||||
fastcgi_param CONTENT_TYPE $content_type;
|
||||
fastcgi_param CONTENT_LENGTH $content_length;
|
||||
fastcgi_pass 127.0.0.1:9000;
|
||||
fastcgi_buffering off;
|
||||
}
|
||||
}
|
||||
server {
|
||||
listen @@PRIMARY_PORT@@;
|
||||
listen [::]:@@PRIMARY_PORT@@;
|
||||
|
||||
Submodule testing-dependencies/mod_pagespeed updated: a41cdab05e...0d9cf2928a
Reference in New Issue
Block a user