Varnish - HTTP / 1.0响应用作HTTP / 1.1

时间:2016-10-31 11:04:15

标签: http http-headers varnish

我正在尝试为此请求获取HTTP 1.0响应:

 curl -v -A "VLSub" -0 http://api.opensubtitles.org/xml-rpc
*   Trying 92.240.234.122...
* Connected to api.opensubtitles.org (92.240.234.122) port 80 (#0)
> GET /xml-rpc HTTP/1.0
> Host: api.opensubtitles.org
> User-Agent: VLSub
> Accept: */*
> 
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, OPTIONS
< Access-Control-Allow-Headers: Origin,X-Requested-With,Content-Type,Accept,DNT,Keep-Alive,User-Agent,If-Modified-Since,Cache-Control
< Content-type: text/xml;charset=UTF-8
< Date: Mon, 31 Oct 2016 04:19:36 GMT
< X-Cache-Backend: web2
< X-Cache: MISS
< Accept-Ranges: bytes
< Content-Length: 305
< Connection: close
< Age: 0
< 
* Closing connection 0
[data]

varnishd(varnish-4.1.3 revision 5e3b6d2):

*   << BeReq    >> 399913921 
-   Begin          bereq 399913920 pass
-   Timestamp      Start: 1477887576.236176 0.000000 0.000000
-   BereqMethod    GET
-   BereqURL       /xml-rpc
-   BereqProtocol  HTTP/1.0
-   BereqHeader    Host: api.opensubtitles.org
-   BereqHeader    User-Agent: VLSub
-   BereqHeader    Accept: */*
-   BereqHeader    If-Modified-Since: Mon, 31 Oct 2016 04:18:26 GMT
-   BereqHeader    Cache-Control: max-stale=0
-   BereqHeader    X-Forwarded-For: x.x.x.x
-   BereqHeader    X-Varnish: 399913921
-   VCL_call       BACKEND_FETCH
-   VCL_return     fetch
-   BackendOpen    922 14.web2 172.20.100.2 80 172.20.10.253 60531
-   BackendStart   172.20.100.2 80
-   Timestamp      Bereq: 1477887576.236208 0.000032 0.000032
-   Timestamp      Beresp: 1477887576.244435 0.008259 0.008227
-   BerespProtocol HTTP/1.0
-   BerespStatus   200
-   BerespReason   OK
-   BerespHeader   Access-Control-Allow-Origin: *
-   BerespHeader   Access-Control-Allow-Methods: GET, POST, OPTIONS
-   BerespHeader   Access-Control-Allow-Headers: Origin,X-Requested-With,Content-Type,Accept,DNT,Keep-Alive,User-Agent,If-Modified-Since,Cache-Control
-   BerespHeader   Content-type: text/xml;charset=UTF-8
-   BerespHeader   Content-Length: 305
-   BerespHeader   Connection: close
-   BerespHeader   Date: Mon, 31 Oct 2016 04:19:36 GMT
-   BerespHeader   Server: Lighttpd 1.4.x
-   TTL            RFC 120 10 -1 1477887576 1477887576 1477887576 0 0
-   VCL_call       BACKEND_RESPONSE
-   BerespUnset    Server: Lighttpd 1.4.x
-   BerespHeader   X-Cache-Backend: web2
-   TTL            VCL 120 10 0 1477887576
-   VCL_return     deliver
-   Storage        malloc Transient
-   ObjProtocol    HTTP/1.0
-   ObjStatus      200
-   ObjReason      OK
-   ObjHeader      Access-Control-Allow-Origin: *
-   ObjHeader      Access-Control-Allow-Methods: GET, POST, OPTIONS
-   ObjHeader      Access-Control-Allow-Headers: Origin,X-Requested-With,Content-Type,Accept,DNT,Keep-Alive,User-Agent,If-Modified-Since,Cache-Control
-   ObjHeader      Content-type: text/xml;charset=UTF-8
-   ObjHeader      Content-Length: 305
-   ObjHeader      Date: Mon, 31 Oct 2016 04:19:36 GMT
-   ObjHeader      X-Cache-Backend: web2
-   Fetch_Body     3 length stream
-   BackendClose   922 14.web2
-   Timestamp      BerespBody: 1477887576.244481 0.008305 0.000046
-   Length         305
-   BereqAcct      218 0 218 373 305 678
-   End   

添加了清漆响应(将Varnish升级到5.0.0)

# varnishlog -q "ReqHeader ~ 'xxx.6.249.201' and ReqHeader ~ 'VLSub'"
*   << Request  >> 983658552 
-   Begin          req 983658551 rxreq
-   Timestamp      Start: 1478109092.896425 0.000000 0.000000
-   Timestamp      Req: 1478109092.896425 0.000000 0.000000
-   ReqStart       xxx.6.249.201 60135
-   ReqMethod      GET
-   ReqURL         /xml-rpc
-   ReqProtocol    HTTP/1.0
-   ReqHeader      Host: api.opensubtitles.org
-   ReqHeader      User-Agent: VLSub
-   ReqHeader      Accept: */*
-   ReqHeader      If-Modified-Since: Wed, 02 Nov 2016 17:47:21 GMT
-   ReqHeader      Cache-Control: max-stale=0
-   ReqHeader      Connection: Keep-Alive
-   ReqHeader      X-Forwarded-For: xxx.6.249.201
-   VCL_call       RECV
-   VCL_return     pass
-   VCL_call       HASH
-   VCL_return     lookup
-   VCL_call       PASS
-   VCL_return     fetch
-   Link           bereq 983658553 pass
-   Timestamp      Fetch: 1478109092.904685 0.008260 0.008260
-   RespProtocol   HTTP/1.0
-   RespStatus     200
-   RespReason     OK
-   RespHeader     Access-Control-Allow-Origin: *
-   RespHeader     Access-Control-Allow-Methods: GET, POST, OPTIONS
-   RespHeader     Access-Control-Allow-Headers: Origin,X-Requested-With,Content-Type,Accept,DNT,Keep-Alive,User-Agent,If-Modified-Since,Cache-Control
-   RespHeader     Content-type: text/xml;charset=UTF-8
-   RespHeader     Content-Length: 305
-   RespHeader     Date: Wed, 02 Nov 2016 17:51:32 GMT
-   RespHeader     X-Cache-Backend: web3
-   RespUnset      HTTP/1.0
-   RespProtocol   HTTP/1.1
-   RespHeader     X-Varnish: 983658552
-   RespHeader     Age: 0
-   RespHeader     Via: 1.1 varnish (Varnish/5.0)
-   VCL_call       DELIVER
-   RespHeader     X-Cache: MISS
-   RespUnset      X-Varnish: 983658552
-   RespUnset      Via: 1.1 varnish (Varnish/5.0)
-   VCL_return     deliver
-   Timestamp      Process: 1478109092.904700 0.008274 0.000014
-   RespHeader     Accept-Ranges: bytes
-   Debug          "RES_MODE 2"
-   RespHeader     Connection: keep-alive
-   Timestamp      Resp: 1478109092.904718 0.008292 0.000018
-   ReqAcct        188 0 188 422 305 727
-   End    

它应该有用。但为什么curl正在获得HTTP 1.1响应?我看到Varnish正在提供HTTP / 1.0响应。谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

Varnish肯定会回应HTTP 1.1协议:

-   RespUnset      HTTP/1.0
-   RespProtocol   HTTP/1.1

Varnish似乎默认明智(见https://www.varnish-cache.org/trac/ticket/641

你可以尝试在vcl_deliver中覆盖它,resp.proto是可写的(参见https://www.varnish-cache.org/docs/4.0/reference/vcl.html#resp

set resp.proto = "HTTP/1.0"