清漆 - HTTP/1.0 响应作为 HTTP/1.1

Varnish - HTTP/1.0 response served as HTTP/1.1

我正在尝试获取此请求的 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 修订版 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 响应(将 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 响应。感谢您的帮助

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"