lox / httpcache

An RFC7234 compliant golang http.Handler for caching HTTP responses
MIT License
264 stars 28 forks source link

Set X-Cache header properly #21

Closed hnakamur closed 8 years ago

hnakamur commented 8 years ago

First of all, thanks for a nice software!

I ran the cli example and thought X-Cache header was not set properly. This pull request fix the problem.

Without this fix:

$ curl -I -X GET http://localhost:8080
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 612
Content-Type: text/html
Date: Tue, 20 Oct 2015 16:11:08 GMT
Etag: "55f2cf52-264"
Last-Modified: Fri, 11 Sep 2015 12:55:46 GMT
Server: nginx/1.8.0

$ curl -I -X GET http://localhost:8080
HTTP/1.1 200 OK
Accept-Ranges: bytes
Age: 6
Content-Length: 612
Content-Type: text/html
Date: Tue, 20 Oct 2015 16:11:08 GMT
Etag: "55f2cf52-264"
Last-Modified: Fri, 11 Sep 2015 12:55:46 GMT
Proxy-Date: Tue, 20 Oct 2015 16:11:08 GMT
Server: nginx/1.8.0
Via: 1.1 httpcache
X-Cache: MISS

server logs

2015/10/21 01:11:08 [::1] "GET http://127.0.0.1:80/ HTTP/1.1" (OK) 612 MISS 1.970606ms
2015/10/21 01:11:13 [::1] "GET / HTTP/1.1" (OK) 612 HIT 704.282µs

With this fix:

$ curl -I -X GET http://localhost:8080
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 612
Content-Type: text/html
Date: Tue, 20 Oct 2015 16:17:42 GMT
Etag: "55f2cf52-264"
Last-Modified: Fri, 11 Sep 2015 12:55:46 GMT
Server: nginx/1.8.0
X-Cache: MISS

$ curl -I -X GET http://localhost:8080
HTTP/1.1 200 OK
Accept-Ranges: bytes
Age: 4
Content-Length: 612
Content-Type: text/html
Date: Tue, 20 Oct 2015 16:17:42 GMT
Etag: "55f2cf52-264"
Last-Modified: Fri, 11 Sep 2015 12:55:46 GMT
Proxy-Date: Tue, 20 Oct 2015 16:17:42 GMT
Server: nginx/1.8.0
Via: 1.1 httpcache
X-Cache: HIT

server logs

2015/10/21 01:17:42 [::1] "GET http://127.0.0.1:80/ HTTP/1.1" (OK) 612 MISS 1.126493ms
2015/10/21 01:17:45 [::1] "GET / HTTP/1.1" (OK) 612 HIT 607.92µs
dahankzter commented 8 years ago

This is probably why I see only misses even though the cache clearly serves to content.

hnakamur commented 8 years ago

Yes, I think so.

I also created a plugin for the Apache Traffic Server. Apache Traffic Server stores cache objects with associated the response headers, just like httpcache here.

https://docs.trafficserver.apache.org/en/latest/admin-guide/storage/index.en.html#the-traffic-server-cache

The object store indexes cache objects according to URLs and associated headers

And I found I need to overwrite the X-Cache header, not just adding it. https://github.com/hnakamur/trafficserver-add_cache_lookup_status_header-plugin/blob/0.1.1/add_cache_lookup_status_header.c#L82-L108

When I just added the X-Cache header, I saw two X-Cache headers, one with the value MISS, and one with the value HIT.

sleaze commented 8 years ago

HttpCache looks really neat but I am concerned about PR's which look good yet lay abandoned for week or more at a time!

Is this project being actively maintained or is it abandonware?

Love, Sleaze

lox commented 8 years ago

It's not abandonware, I'm hoping to have some time to more actively develop it soon.

sleaze commented 8 years ago

Wonderful, thanks for the info! Looking forward to a bright future here!!!