@@ -66,6 +66,20 @@ inline uint64_t ReadBE64(const uint8_t* buf) {
6666 (static_cast <uint64_t >(buf[5 ]) << 16 ) |
6767 (static_cast <uint64_t >(buf[6 ]) << 8 ) | static_cast <uint64_t >(buf[7 ]);
6868}
69+
70+ // Serialize an nghttp3_pri into an RFC 9218 priority field value
71+ // (e.g., "u=3" or "u=0, i"). Returns the number of bytes written.
72+ // This is used only for setting the priority field of HTTP/3 streams on
73+ // the client side.
74+ inline size_t FormatPriority (char * buf, size_t buflen, const nghttp3_pri& pri) {
75+ int len;
76+ if (pri.inc ) {
77+ len = snprintf (buf, buflen, " u=%d, i" , pri.urgency );
78+ } else {
79+ len = snprintf (buf, buflen, " u=%d" , pri.urgency );
80+ }
81+ return static_cast <size_t >(len);
82+ }
6983} // namespace
7084
7185struct Http3HeadersTraits {
@@ -506,17 +520,24 @@ class Http3ApplicationImpl final : public Session::Application {
506520 }
507521 if (session ().is_server ()) {
508522 nghttp3_conn_set_server_stream_priority (*this , stream.id (), &pri);
523+ } else {
524+ // The client API takes a serialized RFC 9218 priority field value
525+ // (e.g., "u=0, i") rather than an nghttp3_pri struct.
526+ char buf[8 ];
527+ size_t len = FormatPriority (buf, sizeof (buf), pri);
528+ nghttp3_conn_set_client_stream_priority (
529+ *this , stream.id (), reinterpret_cast <const uint8_t *>(buf), len);
509530 }
510- // Client-side priority is set at request submission time via
511- // nghttp3_conn_submit_request and is not typically changed
512- // after the fact. The client API takes a serialized RFC 9218
513- // field value rather than an nghttp3_pri struct.
514531 }
515532
516533 StreamPriorityResult GetStreamPriority (const Stream& stream) override {
517- // nghttp3_conn_get_stream_priority is only available on the server side.
534+ // nghttp3_conn_get_stream_priority is only available on the server
535+ // side, where it reflects the peer's requested priority (e.g., from
536+ // PRIORITY_UPDATE frames). Client-side priority is tracked by the
537+ // Stream itself and returned directly from GetPriority in streams.cc.
518538 if (!session ().is_server ()) {
519- return {StreamPriority::DEFAULT, StreamPriorityFlags::NON_INCREMENTAL};
539+ auto & stored = stream.stored_priority ();
540+ return {stored.priority , stored.flags };
520541 }
521542 nghttp3_pri pri;
522543 if (nghttp3_conn_get_stream_priority (*this , &pri, stream.id ()) == 0 ) {
0 commit comments