python: Utilize return value of nghttp2_submit_push_promise

This commit is contained in:
Tatsuhiro Tsujikawa 2014-05-10 23:45:05 +09:00
parent f2bb7947ee
commit 6e7d0286e3
1 changed files with 11 additions and 8 deletions

View File

@ -425,7 +425,6 @@ cdef int server_on_frame_send(cnghttp2.nghttp2_session *session,
if not handler: if not handler:
return 0 return 0
handler.stream_id = frame.push_promise.promised_stream_id
http2.send_response(handler) http2.send_response(handler)
elif frame.hd.type == cnghttp2.NGHTTP2_SETTINGS: elif frame.hd.type == cnghttp2.NGHTTP2_SETTINGS:
if (frame.hd.flags & cnghttp2.NGHTTP2_FLAG_ACK) == 0: if (frame.hd.flags & cnghttp2.NGHTTP2_FLAG_ACK) == 0:
@ -613,20 +612,24 @@ cdef class _HTTP2SessionCore:
def push(self, handler, promised_handler): def push(self, handler, promised_handler):
cdef cnghttp2.nghttp2_nv *nva cdef cnghttp2.nghttp2_nv *nva
cdef size_t nvlen cdef size_t nvlen
cdef int32_t promised_stream_id
self.handlers.add(promised_handler) self.handlers.add(promised_handler)
nva = NULL nva = NULL
nvlen = _make_nva(&nva, promised_handler.headers) nvlen = _make_nva(&nva, promised_handler.headers)
rv = cnghttp2.nghttp2_submit_push_promise(self.session, promised_stream_id = cnghttp2.nghttp2_submit_push_promise\
cnghttp2.NGHTTP2_FLAG_NONE, (self.session,
handler.stream_id, cnghttp2.NGHTTP2_FLAG_NONE,
nva, nvlen, handler.stream_id,
<void*>promised_handler) nva, nvlen,
if rv != 0: <void*>promised_handler)
if promised_stream_id < 0:
raise Exception('nghttp2_submit_push_promise failed: {}'.format\ raise Exception('nghttp2_submit_push_promise failed: {}'.format\
(_strerror(rv))) (_strerror(promised_stream_id)))
promised_handler.stream_id = promised_stream_id
def _rst_stream(self, stream_id, def _rst_stream(self, stream_id,
error_code=cnghttp2.NGHTTP2_INTERNAL_ERROR): error_code=cnghttp2.NGHTTP2_INTERNAL_ERROR):