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

Conflict with multiple currency plugin #80

Closed
duylddev opened this issue Sep 11, 2019 · 8 comments
Closed

Conflict with multiple currency plugin #80

duylddev opened this issue Sep 11, 2019 · 8 comments

Comments

@duylddev
Copy link

Our Wordpress website has a mutilple currency plugin and here's the thing

With the same url like: https://example.com/products/product-name
The plugin basiclly check user Geolocation and return the match currency, but SRCache return the HTML content before the plugin run so US or AU or UK user see the US price
That's not true

What should I do now?

@kapouer
Copy link
Contributor

kapouer commented Sep 11, 2019

Your website varies the response using the request IP.
That setup doesn't go well with a cache in the proxy.
The right way to do this is to map the request IP to a request Header before srcache handles the request, and Vary the response upon that header.

  • Request:
    IP: a.b.c.d
    host: domain.com
    Accept: text/html
  • Geolocation nginx plugin (using e.g. ngx_http_geoip_module)
    IP: a.b.c.d
    host: domain.com
    Accept: text/html
    X-ClientCountry: France
  • Srcache:
    Here you should build the request key using X-ClientCountry header
  • Application:
    response.append('X-ClientCountry', 'Actual detected country')
    response.append('Vary', 'X-ClientCountry')
  • Srcache:
    Build store key using response X-ClientCountry header

@kapouer
Copy link
Contributor

kapouer commented Sep 11, 2019

I wrote Actual detected country because the Country detected by geoip might not be the one you actually choose in the application. For example you might map 'FR' and 'ES' to 'EU' in the application, so you have to tell the cache (as done above) to set its store key accordingly.

@duylddev
Copy link
Author

Thank you for replying, I understand that solution but I don't know how to build store key using response X-ClientCountry header.

Could you give more information?

@duylddev
Copy link
Author

It's great if you give me an example

@kapouer
Copy link
Contributor

kapouer commented Sep 11, 2019

From the documentation example (assuming you're using X-Client-Country header)

  more_set_headers 'X-Country-Code: $geoip_city_country_code3';
  set $fetchKey "$geoip_city_country_code3-$uri?$args";
  set $storeKey "$sent_http_x_client_country-$uri?$args";
  srcache_fetch GET /memc $fetchKey;
  srcache_store PUT /memc $storeKey;

Cool huh ?!?

@duylddev
Copy link
Author

set $key "example.com_page:https$http_cf_ipcountry$request_method$host$request_uri";

I'm using Cloudflare so that's my config and it's worked =))))

Thank you so much :D

@kapouer
Copy link
Contributor

kapouer commented Sep 11, 2019

Cool ! If you're using Cloudflare then yes, there is already a http header available, so indeed there is no need to set one up.
You might want to close this issue...

@duylddev
Copy link
Author

Oh, I forgot it
too much focus on coding =))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants