Add expect_final_byte_offset argument to CopyAndValidateTrailers().

This will be used in cr/231494986 where trailers sent on the
request/response stream should not have the :final-offset pseudo-header.

gfe-relnote: n/a.  No functional change.
PiperOrigin-RevId: 243730777
Change-Id: I1a5c729fb5aab3e3abdb0ce64dad5667faf794bf
diff --git a/quic/core/http/spdy_utils.cc b/quic/core/http/spdy_utils.cc
index 2d94fd4..721ae33 100644
--- a/quic/core/http/spdy_utils.cc
+++ b/quic/core/http/spdy_utils.cc
@@ -86,6 +86,7 @@
 }
 
 bool SpdyUtils::CopyAndValidateTrailers(const QuicHeaderList& header_list,
+                                        bool expect_final_byte_offset,
                                         size_t* final_byte_offset,
                                         SpdyHeaderBlock* trailers) {
   bool found_final_byte_offset = false;
@@ -94,7 +95,8 @@
 
     // Pull out the final offset pseudo header which indicates the number of
     // response body bytes expected.
-    if (!found_final_byte_offset && name == kFinalOffsetHeaderKey &&
+    if (expect_final_byte_offset && !found_final_byte_offset &&
+        name == kFinalOffsetHeaderKey &&
         QuicTextUtils::StringToSizeT(p.second, final_byte_offset)) {
       found_final_byte_offset = true;
       continue;
@@ -116,7 +118,7 @@
     trailers->AppendValueOrAddHeader(name, p.second);
   }
 
-  if (!found_final_byte_offset) {
+  if (expect_final_byte_offset && !found_final_byte_offset) {
     QUIC_DLOG(ERROR) << "Required key '" << kFinalOffsetHeaderKey
                      << "' not present";
     return false;