litespeedtech / lscache_wp

LiteSpeed Cache for WordPress
http://wordpress.org/plugins/litespeed-cache/
GNU General Public License v3.0
209 stars 111 forks source link

REST API returns http status 500 #182

Open jsvini opened 4 years ago

jsvini commented 4 years ago

When I try to consume a page content via REST API:

/wp-json/wp/v2/pages/PAGE_ID

the content is returned, but the http status is 500 and not 200.

In the server error logs I get only this message:

2019-11-01 14:51:29.589988 [ERROR] [xxx] [Module:Cache] vary request header "Origin" not defined!!!!!!!!

When I turn off the REST API cache in LSCache this error doesn't happen

WordPress 4.8.11 Report number: FEJPQWWX Report date: 11/01/2019 14:57:10

cagivacode commented 4 years ago

I have this exact issue

But on: WordPress 5.2.4 and plugin 2.9.9

hi-hai commented 4 years ago

Are you able to search vary request header "Origin" not defined in your wordpress folder to see which plugin generated that string?

cagivacode commented 4 years ago

That string is from OLS cache.cpp....

I can be clearer....with a bad bot IP example from today.

in the /usr/local/lsws/logs/error.log:

2019-11-08 10:08:37.575450 [ERROR] [163.172.128.177:49822-1#example.com] [Module:Cache] vary request header "Origin" not defined!!!!!!!!

then checking the example.com access log for the IP:

[08/Nov/2019:10:08:37 -0500] example.com 163.172.128.177 - - "GET /blog/mypage HTTP/1.1" 500 108

then testing the url that error-ed directly from my browser: I see the appropriate json for the requested page but a recorded server error 500 in the lsws errorlog

cagivacode commented 4 years ago

Sorry...in my munging of the log I cut out the pertinent part

"GET /blog/wp-json/oembed/1.0/embed?url=http://examplel.com/blog/my-page/ HTTP/1.1" 500 108

litespeedtech commented 4 years ago

About the "[ERROR] ...[Module:Cache] vary request header "Origin" not defined!!!!!!!!" message in the error log file, this is actually not an error, I already changed it to warning and it will be in the next release. If any page should be 200 but it responded a 500 error by server, you may want to raise a ticket so that our support team can help to check what is the reason.

cagivacode commented 4 years ago

As mentioned in the original post....and also worked for me, is to:

turn OFF the cache Rest Api in the litespeed wordpress cache plugin.

Then the page still displays the correct json and returns the correct code e.g. 200 in normal mode, a 401 if I turn off wp-json in wordpress or a 404 if the page is no longer there.

All three circumstances return a 500 with cache rest api turned on in the litespeed caching plugin.

thekendog commented 4 years ago

So is there a fix for this? I'm running into the same error. Does caching REST API requests just not work?

thekendog commented 4 years ago

Found a fix for this...at least me for and my custom endpoint.

https://gist.github.com/miya0001/d6508b9ba52df5aedc78fca186ff6088