From c98cf045d680f212f94bc3f53536709a1609fc3c Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 24 Feb 2015 14:43:01 +0900 Subject: [PATCH] nghttpx: Use omit minor version in case of HTTP/2 in via header and accesslog --- integration-tests/nghttpx_http1_test.go | 4 ++-- integration-tests/nghttpx_http2_test.go | 4 ++-- src/shrpx_http.cc | 6 ++++-- src/shrpx_log.cc | 6 ++++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/integration-tests/nghttpx_http1_test.go b/integration-tests/nghttpx_http1_test.go index d035f081..b84e3059 100644 --- a/integration-tests/nghttpx_http1_test.go +++ b/integration-tests/nghttpx_http1_test.go @@ -349,7 +349,7 @@ func TestH1H2GenerateVia(t *testing.T) { if err != nil { t.Fatalf("Error st.http1() = %v", err) } - if got, want := res.header.Get("Via"), "2.0 nghttpx"; got != want { + if got, want := res.header.Get("Via"), "2 nghttpx"; got != want { t.Errorf("Via: %v; want %v", got, want) } } @@ -374,7 +374,7 @@ func TestH1H2AppendVia(t *testing.T) { if err != nil { t.Fatalf("Error st.http1() = %v", err) } - if got, want := res.header.Get("Via"), "bar, 2.0 nghttpx"; got != want { + if got, want := res.header.Get("Via"), "bar, 2 nghttpx"; got != want { t.Errorf("Via: %v; want %v", got, want) } } diff --git a/integration-tests/nghttpx_http2_test.go b/integration-tests/nghttpx_http2_test.go index 4e967d9e..6d9edf7f 100644 --- a/integration-tests/nghttpx_http2_test.go +++ b/integration-tests/nghttpx_http2_test.go @@ -125,7 +125,7 @@ func TestH2H1StripAddXff(t *testing.T) { // from backend server. func TestH2H1GenerateVia(t *testing.T) { st := newServerTester(nil, t, func(w http.ResponseWriter, r *http.Request) { - if got, want := r.Header.Get("Via"), "2.0 nghttpx"; got != want { + if got, want := r.Header.Get("Via"), "2 nghttpx"; got != want { t.Errorf("Via: %v; want %v", got, want) } }) @@ -146,7 +146,7 @@ func TestH2H1GenerateVia(t *testing.T) { // header field to and from backend server. func TestH2H1AppendVia(t *testing.T) { st := newServerTester(nil, t, func(w http.ResponseWriter, r *http.Request) { - if got, want := r.Header.Get("Via"), "foo, 2.0 nghttpx"; got != want { + if got, want := r.Header.Get("Via"), "foo, 2 nghttpx"; got != want { t.Errorf("Via: %v; want %v", got, want) } w.Header().Add("Via", "bar") diff --git a/src/shrpx_http.cc b/src/shrpx_http.cc index 7f2fcb64..004b3b64 100644 --- a/src/shrpx_http.cc +++ b/src/shrpx_http.cc @@ -55,8 +55,10 @@ std::string create_error_html(unsigned int status_code) { std::string create_via_header_value(int major, int minor) { std::string hdrs; hdrs += static_cast(major + '0'); - hdrs += "."; - hdrs += static_cast(minor + '0'); + if (major < 2) { + hdrs += "."; + hdrs += static_cast(minor + '0'); + } hdrs += " nghttpx"; return hdrs; } diff --git a/src/shrpx_log.cc b/src/shrpx_log.cc index 2c4d8f71..ca669eac 100644 --- a/src/shrpx_log.cc +++ b/src/shrpx_log.cc @@ -197,8 +197,10 @@ void upstream_accesslog(const std::vector &lfv, LogSpec *lgsp) { std::tie(p, avail) = copy(lgsp->path, avail, p); std::tie(p, avail) = copy(" HTTP/", avail, p); std::tie(p, avail) = copy(util::utos(lgsp->major).c_str(), avail, p); - std::tie(p, avail) = copy(".", avail, p); - std::tie(p, avail) = copy(util::utos(lgsp->minor).c_str(), avail, p); + if (lgsp->major < 2) { + std::tie(p, avail) = copy(".", avail, p); + std::tie(p, avail) = copy(util::utos(lgsp->minor).c_str(), avail, p); + } break; case SHRPX_LOGF_STATUS: std::tie(p, avail) = copy(util::utos(lgsp->status).c_str(), avail, p);