Skip to content

Commit d5aacc9

Browse files
committed
Inprove scholar experience
Visiting /scholar without cookie, redirect to 404 page bug is fixed.
1 parent c584dba commit d5aacc9

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/ngx_http_google_inject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ ngx_http_google_inject_subs_domain(ngx_conf_t * cf)
9191
if (ngx_http_google_inject_subs_args(cf,
9292
"subs_filter", 2,
9393
"$google_schema_reverse://$google_host",
94-
"$google_schema://" "$google_host"))
94+
"$google_schema" "://$google_host"))
9595
return NGX_CONF_ERROR;
9696
else
9797
return NGX_CONF_OK;

src/ngx_http_google_request.c

+12-7
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ ngx_http_google_request_parse_scholar(ngx_http_request_t * r,
138138
{
139139
if (ngx_http_google_request_parse_cookie_conf(r, ctx)) return NGX_ERROR;
140140

141-
if (ctx->uri->len == 12 && ctx->args) {
141+
if (ctx->uri->len == 12 && ctx->args && ctx->args->nelts) {
142142

143143
u_char * refer = ctx->uri->data + 9;
144144

@@ -183,10 +183,18 @@ ngx_http_google_request_parse_scholar(ngx_http_request_t * r,
183183

184184
if (!ngx_strncasecmp(ctx->uri->data, (u_char *)"/scholar", 8))
185185
{
186+
ngx_str_t uri = *ctx->uri;
187+
188+
// strip "/scholar" uri
189+
uri.data += 8;
190+
uri.len -= 8;
191+
186192
ngx_uint_t i, strip = 1;
187193
ngx_keyval_t * kv, * hd = ctx->args->elts;
188194

189-
for (i = 0; i < ctx->args->nelts; i++) {
195+
// traverse args
196+
for (i = 0; i < ctx->args->nelts; i++)
197+
{
190198
kv = hd + i;
191199
if (!kv->key.len) continue;
192200
if (kv->key.len == 1 && *kv->key.data == 'q')
@@ -206,15 +214,12 @@ ngx_http_google_request_parse_scholar(ngx_http_request_t * r,
206214

207215
}
208216

209-
if (ctx->uri->len > 8) switch (ctx->uri->data[8]) {
217+
if (uri.len) switch (*uri.data) {
210218
case '?': case '/': break;
211219
default: strip = 0; break;
212220
}
213221

214-
if (strip) {
215-
ctx->uri->data += 8;
216-
ctx->uri->len -= 8;
217-
}
222+
if (strip) *ctx->uri = uri;
218223
}
219224
}
220225

0 commit comments

Comments
 (0)