{ // 获取包含Hugging Face文本的span元素 const spans = link.querySelectorAll('span.whitespace-nowrap, span.hidden.whitespace-nowrap'); spans.forEach(span => { if (span.textContent && span.textContent.trim().match(/Hugging\s*Face/i)) { span.textContent = 'AI快站'; } }); }); // 替换logo图片的alt属性 document.querySelectorAll('img[alt*="Hugging"], img[alt*="Face"]').forEach(img => { if (img.alt.match(/Hugging\s*Face/i)) { img.alt = 'AI快站 logo'; } }); } // 替换导航栏中的链接 function replaceNavigationLinks() { // 已替换标记,防止重复运行 if (window._navLinksReplaced) { return; } // 已经替换过的链接集合,防止重复替换 const replacedLinks = new Set(); // 只在导航栏区域查找和替换链接 const headerArea = document.querySelector('header') || document.querySelector('nav'); if (!headerArea) { return; } // 在导航区域内查找链接 const navLinks = headerArea.querySelectorAll('a'); navLinks.forEach(link => { // 如果已经替换过,跳过 if (replacedLinks.has(link)) return; const linkText = link.textContent.trim(); const linkHref = link.getAttribute('href') || ''; // 替换Spaces链接 - 仅替换一次 if ( (linkHref.includes('/spaces') || linkHref === '/spaces' || linkText === 'Spaces' || linkText.match(/^s*Spacess*$/i)) && linkText !== 'PDF TO Markdown' && linkText !== 'PDF TO Markdown' ) { link.textContent = 'PDF TO Markdown'; link.href = 'https://fast360.xyz'; link.setAttribute('target', '_blank'); link.setAttribute('rel', 'noopener noreferrer'); replacedLinks.add(link); } // 删除Posts链接 else if ( (linkHref.includes('/posts') || linkHref === '/posts' || linkText === 'Posts' || linkText.match(/^s*Postss*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } // 替换Docs链接 - 仅替换一次 else if ( (linkHref.includes('/docs') || linkHref === '/docs' || linkText === 'Docs' || linkText.match(/^s*Docss*$/i)) && linkText !== 'Voice Cloning' ) { link.textContent = 'Voice Cloning'; link.href = 'https://vibevoice.info/'; replacedLinks.add(link); } // 删除Enterprise链接 else if ( (linkHref.includes('/enterprise') || linkHref === '/enterprise' || linkText === 'Enterprise' || linkText.match(/^s*Enterprises*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } }); // 查找可能嵌套的Spaces和Posts文本 const textNodes = []; function findTextNodes(element) { if (element.nodeType === Node.TEXT_NODE) { const text = element.textContent.trim(); if (text === 'Spaces' || text === 'Posts' || text === 'Enterprise') { textNodes.push(element); } } else { for (const child of element.childNodes) { findTextNodes(child); } } } // 只在导航区域内查找文本节点 findTextNodes(headerArea); // 替换找到的文本节点 textNodes.forEach(node => { const text = node.textContent.trim(); if (text === 'Spaces') { node.textContent = node.textContent.replace(/Spaces/g, 'PDF TO Markdown'); } else if (text === 'Posts') { // 删除Posts文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } else if (text === 'Enterprise') { // 删除Enterprise文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } }); // 标记已替换完成 window._navLinksReplaced = true; } // 替换代码区域中的域名 function replaceCodeDomains() { // 特别处理span.hljs-string和span.njs-string元素 document.querySelectorAll('span.hljs-string, span.njs-string, span[class*="hljs-string"], span[class*="njs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换hljs-string类的span中的域名(移除多余的转义符号) document.querySelectorAll('span.hljs-string, span[class*="hljs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换pre和code标签中包含git clone命令的域名 document.querySelectorAll('pre, code').forEach(element => { if (element.textContent && element.textContent.includes('git clone')) { const text = element.innerHTML; if (text.includes('huggingface.co')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 处理特定的命令行示例 document.querySelectorAll('pre, code').forEach(element => { const text = element.innerHTML; if (text.includes('huggingface.co')) { // 针对git clone命令的专门处理 if (text.includes('git clone') || text.includes('GIT_LFS_SKIP_SMUDGE=1')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 特别处理模型下载页面上的代码片段 document.querySelectorAll('.flex.border-t, .svelte_hydrator, .inline-block').forEach(container => { const content = container.innerHTML; if (content && content.includes('huggingface.co')) { container.innerHTML = content.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 特别处理模型仓库克隆对话框中的代码片段 try { // 查找包含"Clone this model repository"标题的对话框 const cloneDialog = document.querySelector('.svelte_hydration_boundary, [data-target="MainHeader"]'); if (cloneDialog) { // 查找对话框中所有的代码片段和命令示例 const codeElements = cloneDialog.querySelectorAll('pre, code, span'); codeElements.forEach(element => { if (element.textContent && element.textContent.includes('huggingface.co')) { if (element.innerHTML.includes('huggingface.co')) { element.innerHTML = element.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { element.textContent = element.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); } // 更精确地定位克隆命令中的域名 document.querySelectorAll('[data-target]').forEach(container => { const codeBlocks = container.querySelectorAll('pre, code, span.hljs-string'); codeBlocks.forEach(block => { if (block.textContent && block.textContent.includes('huggingface.co')) { if (block.innerHTML.includes('huggingface.co')) { block.innerHTML = block.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { block.textContent = block.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); }); } catch (e) { // 错误处理但不打印日志 } } // 当DOM加载完成后执行替换 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); }); } else { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); } // 增加一个MutationObserver来处理可能的动态元素加载 const observer = new MutationObserver(mutations => { // 检查是否导航区域有变化 const hasNavChanges = mutations.some(mutation => { // 检查是否存在header或nav元素变化 return Array.from(mutation.addedNodes).some(node => { if (node.nodeType === Node.ELEMENT_NODE) { // 检查是否是导航元素或其子元素 if (node.tagName === 'HEADER' || node.tagName === 'NAV' || node.querySelector('header, nav')) { return true; } // 检查是否在导航元素内部 let parent = node.parentElement; while (parent) { if (parent.tagName === 'HEADER' || parent.tagName === 'NAV') { return true; } parent = parent.parentElement; } } return false; }); }); // 只在导航区域有变化时执行替换 if (hasNavChanges) { // 重置替换状态,允许再次替换 window._navLinksReplaced = false; replaceHeaderBranding(); replaceNavigationLinks(); } }); // 开始观察document.body的变化,包括子节点 if (document.body) { observer.observe(document.body, { childList: true, subtree: true }); } else { document.addEventListener('DOMContentLoaded', () => { observer.observe(document.body, { childList: true, subtree: true }); }); } })(); \",\n end_stream=True,\n )\n \n # receive response\n events = h3_transfer(quic_server, h3_client)\n self.assertEqual(len(events), 2)\n \n self.assertTrue(isinstance(events[0], ResponseReceived))\n self.assertEqual(\n events[0].headers,\n [\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n (b\"x-foo\", b\"server\"),\n ],\n )\n self.assertEqual(events[0].stream_id, stream_id)\n self.assertEqual(events[0].stream_ended, False)\n \n self.assertTrue(isinstance(events[1], DataReceived))\n self.assertEqual(events[1].data, b\"hello\")\n self.assertEqual(events[1].stream_id, stream_id)\n self.assertEqual(events[1].stream_ended, True)\n \n \n===========unchanged ref 0===========\n at: aioquic.h3.connection.H3Connection\n send_data(stream_id: int, data: bytes, end_stream: bool) -> None\n \n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._quic = quic\n \n at: aioquic.h3.events\n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n RequestReceived(headers: Headers, stream_id: int, stream_ended: bool)\n \n at: aioquic.quic.connection.QuicConnection\n get_next_available_stream_id(is_unidirectional=False) -> int\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: aioquic.quic.events.StreamDataReceived\n data: bytes\n \n end_stream: bool\n \n stream_id: int\n \n at: tests.test_h3\n h3_transfer(quic_sender, h3_receiver)\n \n at: tests.test_h3.FakeQuicConnection.__init__\n self.stream_queue = []\n \n self._events = []\n \n at: tests.test_h3.FakeQuicConnection.get_next_available_stream_id\n stream_id = self._next_stream_bidi\n \n at: unittest.case\n TestCase(methodName: str=...)\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n assertTrue(expr: Any, msg: Any=...) -> None\n \n failureException = AssertionError\n \n longMessage = True\n \n maxDiff = 80*8\n \n _diffThreshold = 2**16\n \n failUnlessEqual = assertEquals = _deprecate(assertEqual)\n \n failUnlessEqual = assertEquals = _deprecate(assertEqual)\n \n \n===========unchanged ref 1===========\n failIfEqual = assertNotEquals = _deprecate(assertNotEqual)\n \n failIfEqual = assertNotEquals = _deprecate(assertNotEqual)\n \n failUnlessAlmostEqual = assertAlmostEquals = _deprecate(assertAlmostEqual)\n \n failUnlessAlmostEqual = assertAlmostEquals = _deprecate(assertAlmostEqual)\n \n failIfAlmostEqual = assertNotAlmostEquals = _deprecate(assertNotAlmostEqual)\n \n failIfAlmostEqual = assertNotAlmostEquals = _deprecate(assertNotAlmostEqual)\n \n failUnless = assert_ = _deprecate(assertTrue)\n \n failUnless = assert_ = _deprecate(assertTrue)\n \n failUnlessRaises = _deprecate(assertRaises)\n \n failIf = _deprecate(assertFalse)\n \n assertRaisesRegexp = _deprecate(assertRaisesRegex)\n \n assertRegexpMatches = _deprecate(assertRegex)\n \n assertNotRegexpMatches = _deprecate(assertNotRegex)\n \n \n===========changed ref 0===========\n # module: tests.test_h3\n def h3_transfer(quic_sender, h3_receiver):\n quic_receiver = h3_receiver._quic\n + if hasattr(quic_sender, \"stream_queue\"):\n + quic_receiver._events.extend(quic_sender.stream_queue)\n + quic_sender.stream_queue.clear()\n + else:\n + transfer(quic_sender, quic_receiver)\n - transfer(quic_sender, quic_receiver)\n \n # process QUIC events\n http_events = []\n event = quic_receiver.next_event()\n while event is not None:\n http_events.extend(h3_receiver.handle_event(event))\n event = quic_receiver.next_event()\n return http_events\n \n===========changed ref 1===========\n # module: tests.test_h3\n class FakeQuicConnection:\n def __init__(self, configuration):\n self.configuration = configuration\n self.stream_queue = []\n + self._events = []\n self._next_stream_bidi = 0 if configuration.is_client else 1\n self._next_stream_uni = 2 if configuration.is_client else 3\n \n===========changed ref 2===========\n # module: aioquic.h3.connection\n + def parse_max_push_id(data: bytes) -> int:\n + buf = Buffer(data=data)\n + max_push_id = buf.pull_uint_var()\n + assert buf.eof()\n + return max_push_id\n + \n===========changed ref 3===========\n # module: aioquic.h3.connection\n class H3Stream:\n def __init__(self) -> None:\n self.blocked = False\n self.buffer = b\"\"\n self.ended = False\n self.frame_size: Optional[int] = None\n self.frame_type: Optional[int] = None\n + self.push_id: Optional[int] = None\n self.stream_type: Optional[int] = None\n \n===========changed ref 4===========\n # module: aioquic.h3.events\n + @dataclass\n + class PushPromiseReceived(HttpEvent):\n + \"\"\"\n + The PushedStreamReceived event is fired whenever a pushed stream has been\n + received from the remote peer.\n + \"\"\"\n + \n + headers: Headers\n + \"The request headers.\"\n + \n + push_id: int\n + \"The Push ID of the push promise.\"\n + \n + stream_id: int\n + \"The Stream ID of the stream that the push is related to.\"\n + "}}},{"rowIdx":3409,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_request_headers_only"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"eb4fc3878387177cf3b52a94f4c63fb9c871cbcf"},"commit_message":{"kind":"string","value":"[http3] add initial support for server push"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_headers_only(self):\n <0> with client_and_server(\n <1> client_options={\"alpn_protocols\": [\"h3-22\"]},\n <2> server_options={\"alpn_protocols\": [\"h3-22\"]},\n <3> ) as (quic_client, quic_server):\n <4> h3_client = H3Connection(quic_client)\n <5> h3_server = H3Connection(quic_server)\n <6> \n <7> # send request\n <8> stream_id = quic_client.get_next_available_stream_id()\n <9> h3_client.send_headers(\n<10> stream_id=stream_id,\n<11> headers=[\n<12> (b\":method\", b\"HEAD\"),\n<13> (b\":scheme\", b\"https\"),\n<14> (b\":authority\", b\"localhost\"),\n<15> (b\":path\", b\"/\"),\n<16> (b\"x-foo\", b\"client\"),\n<17> ],\n<18> end_stream=True,\n<19> )\n<20> \n<21> # receive request\n<22> events = h3_transfer(quic_client, h3_server)\n<23> self.assertEqual(len(events), 1)\n<24> \n<25> self.assertTrue(isinstance(events[0], RequestReceived))\n<26> self.assertEqual(\n<27> events[0].headers,\n<28> [\n<29> (b\":method\", b\"HEAD\"),\n<30> (b\":scheme\", b\"https\"),\n<31> (b\":authority\", b\"localhost\"),\n<32> (b\":path\", b\"/\"),\n<33> (b\"x-foo\", b\"client\"),\n<34> ],\n<35> )\n<36> self.assertEqual(events[0].stream_id, stream_id)\n<37> self.assertEqual(events[0].stream_ended, True)\n<38> \n<39> # send response\n<40> h3_server.send_headers(\n<41> stream_id=stream_id,\n<42> headers=[\n<43> (b"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_headers_only(self):\n # offset: 1\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n (b\"x-foo\", b\"server\"),\n ],\n end_stream=True,\n )\n \n # receive response\n events = h3_transfer(quic_server, h3_client)\n self.assertEqual(len(events), 1)\n \n self.assertTrue(isinstance(events[0], ResponseReceived))\n self.assertEqual(\n events[0].headers,\n [\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n (b\"x-foo\", b\"server\"),\n ],\n )\n self.assertEqual(events[0].stream_id, stream_id)\n self.assertEqual(events[0].stream_ended, True)\n \n \n===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[HttpEvent]\n \n _handle_control_frame(frame_type: int, frame_data: bytes) -> None\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.configuration.QuicConfiguration\n alpn_protocols: Optional[List[str]] = None\n \n certificate: Any = None\n \n connection_id_length: int = 8\n \n idle_timeout: float = 60.0\n \n is_client: bool = True\n \n private_key: Any = None\n \n \n===========unchanged ref 1===========\n quic_logger: Optional[QuicLogger] = None\n \n secrets_log_file: TextIO = None\n \n server_name: Optional[str] = None\n \n session_ticket: Optional[SessionTicket] = None\n \n supported_versions: List[int] = field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n )\n \n at: aioquic.quic.connection\n QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_connection\n client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_options={}, server_patch=lambda x: None, transport_options={})\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: tests.test_h3.H3ConnectionTest\n _make_request(h3_client, h3_server)\n _make_request(self, h3_client, h3_server)\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E]\n assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None\n \n at: unittest.case._AssertRaisesContext.__exit__\n self.exception = exc_value.with_traceback(None)\n \n \n===========changed ref 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def _make_request(self, h3_client, h3_server):\n quic_client = h3_client._quic\n quic_server = h3_server._quic\n \n # send request\n stream_id = quic_client.get_next_available_stream_id()\n h3_client.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/\"),\n (b\"x-foo\", b\"client\"),\n ],\n )\n h3_client.send_data(stream_id=stream_id, data=b\"\", end_stream=True)\n \n # receive request\n events = h3_transfer(quic_client, h3_server)\n self.assertEqual(len(events), 2)\n \n self.assertTrue(isinstance(events[0], RequestReceived))\n self.assertEqual(\n events[0].headers,\n [\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/\"),\n (b\"x-foo\", b\"client\"),\n ],\n )\n self.assertEqual(events[0].stream_id, stream_id)\n self.assertEqual(events[0].stream_ended, False)\n \n self.assertTrue(isinstance(events[1], DataReceived))\n self.assertEqual(events[1].data, b\"\")\n self.assertEqual(events[1].stream_id, stream_id)\n self.assertEqual(events[1].stream_ended, True)\n \n # send response\n h3_server.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":status\", b\"200\"),\n ("}}},{"rowIdx":3410,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_request_fragmented_frame"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"eb4fc3878387177cf3b52a94f4c63fb9c871cbcf"},"commit_message":{"kind":"string","value":"[http3] add initial support for server push"},"ground_truth":{"kind":"string","value":"<10>: # send request\n # send headers\n<22>: h3_client.send_data(stream_id=stream_id, data=b\"hello\", end_stream=True)\n \n # receive request\n events = h3_transfer(quic_client, h3_server)\n http_events = []\n<23>: for event in quic_client.stream_queue:\n<24>: http_events.extend(h3_server.handle_event(event))\n<25>: quic_client.stream_queue.clear()\n<27>: events,\n http_events,\n<37>: stream_id=stream_id,\n stream_id=0,\n<39>: ),\n )\n<40>: ],\n<41>: )\n<42>: \n<43>: # send body\n<44>: h3_client.send_data(stream_id=stream_id, data=b\"hello\", end_stream=True)\n<45>: http_events = []\n<46>: for event in quic\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_fragmented_frame(self):\n <0> quic_client = FakeQuicConnection(\n <1> configuration=QuicConfiguration(is_client=True)\n <2> )\n <3> quic_server = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=False)\n <5> )\n <6> \n <7> h3_client = H3Connection(quic_client)\n <8> h3_server = H3Connection(quic_server)\n <9> \n<10> # send headers\n<11> stream_id = quic_client.get_next_available_stream_id()\n<12> h3_client.send_headers(\n<13> stream_id=stream_id,\n<14> headers=[\n<15> (b\":method\", b\"GET\"),\n<16> (b\":scheme\", b\"https\"),\n<17> (b\":authority\", b\"localhost\"),\n<18> (b\":path\", b\"/\"),\n<19> (b\"x-foo\", b\"client\"),\n<20> ],\n<21> )\n<22> http_events = []\n<23> for event in quic_client.stream_queue:\n<24> http_events.extend(h3_server.handle_event(event))\n<25> quic_client.stream_queue.clear()\n<26> self.assertEqual(\n<27> http_events,\n<28> [\n<29> RequestReceived(\n<30> headers=[\n<31> (b\":method\", b\"GET\"),\n<32> (b\":scheme\", b\"https\"),\n<33> (b\":authority\", b\"localhost\"),\n<34> (b\":path\", b\"/\"),\n<35> (b\"x-foo\", b\"client\"),\n<36> ],\n<37> stream_id=0,\n<38> stream_ended=False,\n<39> )\n<40> ],\n<41> )\n<42> \n<43> # send body\n<44> h3_client.send_data(stream_id=stream_id, data=b\"hello\", end_stream=True)\n<45> http_events = []\n<46> for event in quic"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_fragmented_frame(self):\n # offset: 1\n http_events.extend(h3_server.handle_event(event))\n quic_client.stream_queue.clear()\n self.assertEqual(\n http_events,\n [\n DataReceived(data=b\"h\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"e\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"l\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"l\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"o\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"\", stream_id=0, stream_ended=True),\n ],\n )\n \n \n===========unchanged ref 0===========\n at: aioquic.h3.connection\n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.events\n RequestReceived(headers: Headers, stream_id: int, stream_ended: bool)\n \n ResponseReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: tests.test_h3\n h3_transfer(quic_sender, h3_receiver)\n \n at: tests.test_h3.H3ConnectionTest.test_request_headers_only\n h3_client = H3Connection(quic_client)\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n assertTrue(expr: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: tests.test_h3\n def h3_transfer(quic_sender, h3_receiver):\n quic_receiver = h3_receiver._quic\n + if hasattr(quic_sender, \"stream_queue\"):\n + quic_receiver._events.extend(quic_sender.stream_queue)\n + quic_sender.stream_queue.clear()\n + else:\n + transfer(quic_sender, quic_receiver)\n - transfer(quic_sender, quic_receiver)\n \n # process QUIC events\n http_events = []\n event = quic_receiver.next_event()\n while event is not None:\n http_events.extend(h3_receiver.handle_event(event))\n event = quic_receiver.next_event()\n return http_events\n \n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n + def test_handle_control_frame_max_push_id_from_server(self):\n + \"\"\"\n + A client should not receive MAX_PUSH_ID on the control stream.\n + \"\"\"\n + quic_client = FakeQuicConnection(\n + configuration=QuicConfiguration(is_client=True)\n + )\n + h3_client = H3Connection(quic_client)\n + \n + with self.assertRaises(QuicConnectionError) as cm:\n + h3_client._handle_control_frame(FrameType.MAX_PUSH_ID, encode_uint_var(0))\n + self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)\n + \n===========changed ref 2===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n + def test_handle_control_frame_headers(self):\n + \"\"\"\n + We should not receive HEADERS on the control stream.\n + \"\"\"\n + quic_server = FakeQuicConnection(\n + configuration=QuicConfiguration(is_client=False)\n + )\n + h3_server = H3Connection(quic_server)\n + \n + with self.assertRaises(QuicConnectionError) as cm:\n + h3_server._handle_control_frame(FrameType.HEADERS, b\"\")\n + self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n + \n===========changed ref 3===========\n # module: tests.test_h3\n class FakeQuicConnection:\n + def next_event(self):\n + try:\n + return self._events.pop(0)\n + except IndexError:\n + return None\n + \n===========changed ref 4===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n + def test_handle_push_frame_wrong_frame_type(self):\n + quic_client = FakeQuicConnection(\n + configuration=QuicConfiguration(is_client=True)\n + )\n + h3_client = H3Connection(quic_client)\n + \n + with self.assertRaises(QuicConnectionError) as cm:\n + h3_client.handle_event(\n + StreamDataReceived(\n + stream_id=15,\n + data=encode_uint_var(StreamType.PUSH)\n + + encode_uint_var(0) # push ID\n + + encode_frame(FrameType.SETTINGS, b\"\"),\n + end_stream=False,\n + )\n + )\n + self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n + \n===========changed ref 5===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n - def test_handle_control_frame_wrong_frame_type(self):\n - quic_server = FakeQuicConnection(\n - configuration=QuicConfiguration(is_client=False)\n - )\n - h3_server = H3Connection(quic_server)\n - \n - with self.assertRaises(QuicConnectionError) as cm:\n - h3_server._handle_control_frame(FrameType.HEADERS, b\"\")\n - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n - \n===========changed ref 6===========\n # module: tests.test_h3\n class FakeQuicConnection:\n def __init__(self, configuration):\n self.configuration = configuration\n self.stream_queue = []\n + self._events = []\n self._next_stream_bidi = 0 if configuration.is_client else 1\n self._next_stream_uni = 2 if configuration.is_client else 3\n "}}},{"rowIdx":3411,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_stream_data_uni"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"e48f62850cdb0033065dea3657a5dfe7d68e1bf1"},"commit_message":{"kind":"string","value":"[http3] explicity key off stream type for uni streams"},"ground_truth":{"kind":"string","value":"<20>: # check unicity\n<30>: if stream.stream_type == StreamType.CONTROL:\n if stream_id == self._peer_control_stream_id:\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[HttpEvent]:\n <0> http_events: List[HttpEvent] = []\n <1> \n <2> stream = self._stream[stream_id]\n <3> stream.buffer += data\n <4> if stream_ended:\n <5> stream.ended = True\n <6> \n <7> buf = Buffer(data=stream.buffer)\n <8> consumed = 0\n <9> unblocked_streams: Set[int] = set()\n<10> \n<11> while not buf.eof():\n<12> # fetch stream type for unidirectional streams\n<13> if stream.stream_type is None:\n<14> try:\n<15> stream.stream_type = buf.pull_uint_var()\n<16> except BufferReadError:\n<17> break\n<18> consumed = buf.tell()\n<19> \n<20> if stream.stream_type == StreamType.CONTROL:\n<21> assert self._peer_control_stream_id is None\n<22> self._peer_control_stream_id = stream_id\n<23> elif stream.stream_type == StreamType.QPACK_DECODER:\n<24> assert self._peer_decoder_stream_id is None\n<25> self._peer_decoder_stream_id = stream_id\n<26> elif stream.stream_type == StreamType.QPACK_ENCODER:\n<27> assert self._peer_encoder_stream_id is None\n<28> self._peer_encoder_stream_id = stream_id\n<29> \n<30> if stream_id == self._peer_control_stream_id:\n<31> # fetch next frame\n<32> try:\n<33> frame_type = buf.pull_uint_var()\n<34> frame_length = buf.pull_uint_var()\n<35> frame_data = buf.pull_bytes(frame_length)\n<36> except BufferReadError:\n<37> break\n<38> consumed = buf.tell()\n<39> \n<40> self._handle_control_frame(frame_type, frame_data)\n<41> elif stream.stream_type == StreamType."},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[HttpEvent]:\n # offset: 1\n # fetch push id\n if stream.push_id is None:\n try:\n stream.push_id = buf.pull_uint_var()\n except BufferReadError:\n break\n consumed = buf.tell()\n \n # fetch next frame\n try:\n frame_type = buf.pull_uint_var()\n frame_length = buf.pull_uint_var()\n frame_data = buf.pull_bytes(frame_length)\n except BufferReadError:\n break\n consumed = buf.tell()\n \n http_events.extend(\n self._handle_push_frame(\n frame_type=frame_type,\n frame_data=frame_data,\n push_id=stream.push_id,\n stream_id=stream_id,\n stream_ended=stream.ended and buf.eof(),\n )\n )\n else:\n # fetch unframed data\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n \n if stream_id == self._peer_decoder_stream_id:\n self._encoder.feed_decoder(data)\n \n elif stream_id == self._peer_encoder_stream_id:\n unblocked_streams.update(self._decoder.feed_encoder(data))\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n # process unblocked streams\n for stream_id in unblocked_streams:\n stream = self._stream[stream_id]\n decoder, headers = self._decoder.resume_header(stream_id)\n stream.blocked = False\n cls = ResponseReceived if self._is_client else RequestReceived\n http_events.append(\n cls(\n headers=headers,\n stream_id=stream_id,\n stream_ended=stream.\n===========below chunk 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[HttpEvent]:\n # offset: 2\n append(\n cls(\n headers=headers,\n stream_id=stream_id,\n stream_ended=stream.ended and not stream.buffer,\n )\n )\n http_events.extend(\n self._receive_stream_data_bidi(stream_id, b\"\", stream.ended)\n )\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n at: aioquic.h3.connection.H3Connection\n _handle_control_frame(frame_type: int, frame_data: bytes) -> None\n \n _handle_push_frame(frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[HttpEvent]\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._encoder = Encoder()\n \n self._stream: Dict[int, H3Stream] = {}\n \n self._peer_control_stream_id: Optional[int] = None\n \n self._peer_decoder_stream_id: Optional[int] = None\n \n self._peer_encoder_stream_id: Optional[int] = None\n \n at: aioquic.h3.connection.H3Stream.__init__\n self.buffer = b\"\"\n \n self.ended = False\n \n self.push_id: Optional[int] = None\n \n self.stream_type: Optional[int] = None\n \n at: aioquic.h3.events\n HttpEvent()\n \n RequestReceived(headers: Headers, stream_id: int, stream_ended: bool)\n \n ResponseReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n \n===========unchanged ref 1===========\n Set = _alias(set, 1, inst=False, name='Set')\n \n "}}},{"rowIdx":3412,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_stream_data_bidi"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"8d579b2864f8d3fae34438390ba2efd220e45b4c"},"commit_message":{"kind":"string","value":"[http3] raise an exception if server receives a PUSH_PROMISE"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[HttpEvent]:\n <0> \"\"\"\n <1> Client-initiated bidirectional streams carry requests and responses.\n <2> \"\"\"\n <3> http_events: List[HttpEvent] = []\n <4> \n <5> stream = self._stream[stream_id]\n <6> stream.buffer += data\n <7> if stream_ended:\n <8> stream.ended = True\n <9> if stream.blocked:\n<10> return http_events\n<11> \n<12> # shortcut DATA frame bits\n<13> if (\n<14> stream.frame_type == FrameType.DATA\n<15> and stream.frame_size is not None\n<16> and len(stream.buffer) < stream.frame_size\n<17> ):\n<18> http_events.append(\n<19> DataReceived(\n<20> data=stream.buffer, stream_id=stream_id, stream_ended=False\n<21> )\n<22> )\n<23> stream.frame_size -= len(stream.buffer)\n<24> stream.buffer = b\"\"\n<25> return http_events\n<26> \n<27> # some peers (e.g. f5) end the stream with no data\n<28> if stream_ended and not stream.buffer:\n<29> http_events.append(\n<30> DataReceived(data=b\"\", stream_id=stream_id, stream_ended=True)\n<31> )\n<32> return http_events\n<33> \n<34> buf = Buffer(data=stream.buffer)\n<35> consumed = 0\n<36> \n<37> while not buf.eof():\n<38> # fetch next frame header\n<39> if stream.frame_size is None:\n<40> try:\n<41> stream.frame_type = buf.pull_uint_var()\n<42> stream.frame_size = buf.pull_uint_var()\n<43> except BufferReadError:\n<44> break\n<45> consumed = buf.tell()\n<46> \n<47> # check how much data is available\n<48> chunk_size = min(stream.frame_size, buf.capacity - consumed"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[HttpEvent]:\n # offset: 1\n if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size:\n break\n \n # read available data\n frame_data = buf.pull_bytes(chunk_size)\n consumed = buf.tell()\n \n # detect end of frame\n stream.frame_size -= chunk_size\n if not stream.frame_size:\n stream.frame_size = None\n \n if stream.frame_type == FrameType.DATA and (stream_ended or frame_data):\n http_events.append(\n DataReceived(\n data=frame_data,\n stream_id=stream_id,\n stream_ended=stream_ended and buf.eof(),\n )\n )\n elif stream.frame_type == FrameType.HEADERS:\n try:\n headers = self._decode_headers(stream_id, frame_data)\n except StreamBlocked:\n stream.blocked = True\n break\n cls = ResponseReceived if self._is_client else RequestReceived\n http_events.append(\n cls(\n headers=headers,\n stream_id=stream_id,\n stream_ended=stream_ended and buf.eof(),\n )\n )\n elif stream.frame_type == FrameType.PUSH_PROMISE:\n frame_buf = Buffer(data=frame_data)\n push_id = frame_buf.pull_uint_var()\n headers = self._decode_headers(\n stream_id, frame_data[frame_buf.tell() :]\n )\n http_events.append(\n PushPromiseReceived(\n headers=headers, push_id=push_id, stream_id=stream_id\n )\n )\n elif stream.frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.GOAW\n===========below chunk 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[HttpEvent]:\n # offset: 2\n \n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on request stream\",\n )\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n at: aioquic.h3.connection.H3Connection\n _decode_headers(stream_id: int, frame_data: bytes) -> Headers\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._is_client = quic.configuration.is_client\n \n self._stream: Dict[int, H3Stream] = {}\n \n at: aioquic.h3.connection.H3Stream.__init__\n self.blocked = False\n \n self.buffer = b\"\"\n \n self.ended = False\n \n self.frame_size: Optional[int] = None\n \n self.frame_type: Optional[int] = None\n \n at: aioquic.h3.events\n HttpEvent()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n PushPromiseReceived(headers: Headers, push_id: int, stream_id: int)\n \n RequestReceived(headers: Headers, stream_id: int, stream_ended: bool)\n \n ResponseReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.h3.events.DataReceived\n data: bytes\n \n stream_id: int\n \n \n===========unchanged ref 1===========\n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.RequestReceived\n headers: Headers\n \n stream_id: int\n \n stream_ended: bool\n \n at: aioquic.h3.events.ResponseReceived\n headers: Headers\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.quic.connection\n QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n "}}},{"rowIdx":3413,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest._make_request"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"cbaebd25666112b8771f6511547385a2696f65bb"},"commit_message":{"kind":"string","value":"[tests] refactor http3 tests"},"ground_truth":{"kind":"string","value":"<19>: self.assertEqual(len(events), 2)\n<20>: \n<21>: self.assertTrue(isinstance(events[0], RequestReceived))\n<23>: events,\n events[0].headers,\n<25>: RequestReceived(\n headers=[\n (b\":method\", b\"GET\"),\n (b\":method\", b\"GET\"),\n<26>: (b\":scheme\", b\"https\"),\n (b\":scheme\", b\"https\"),\n<27>: (b\":authority\", b\"localhost\"),\n (b\":authority\", b\"localhost\"),\n<28>: (b\":path\", b\"/\"),\n (b\":path\", b\"/\"),\n<29>: (b\"x-foo\", b\"client\"),\n (b\"x-foo\", b\"client\"),\n<30>: ],\n stream_id=stream_id,\n stream_ended=False,\n ),\n DataReceived(data=b\"\", stream_id=stream_id, stream_ended=True),\n<32>: self.assertEqual(events[0].stream_id, stream_id)\n<33>: self.assertEqual(events[0].stream_ended, False)\n<34>: \n<35>: self.assertTrue(isinstance(events[1], DataReceived))\n<36>: self.assertEqual(events[1].data, b\"\")\n<37>: self.assertEqual(events[1].stream_id, stream_id)\n<38>: self.assertEqual(events[1].stream_ended, True)\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def _make_request(self, h3_client, h3_server):\n <0> quic_client = h3_client._quic\n <1> quic_server = h3_server._quic\n <2> \n <3> # send request\n <4> stream_id = quic_client.get_next_available_stream_id()\n <5> h3_client.send_headers(\n <6> stream_id=stream_id,\n <7> headers=[\n <8> (b\":method\", b\"GET\"),\n <9> (b\":scheme\", b\"https\"),\n<10> (b\":authority\", b\"localhost\"),\n<11> (b\":path\", b\"/\"),\n<12> (b\"x-foo\", b\"client\"),\n<13> ],\n<14> )\n<15> h3_client.send_data(stream_id=stream_id, data=b\"\", end_stream=True)\n<16> \n<17> # receive request\n<18> events = h3_transfer(quic_client, h3_server)\n<19> self.assertEqual(len(events), 2)\n<20> \n<21> self.assertTrue(isinstance(events[0], RequestReceived))\n<22> self.assertEqual(\n<23> events[0].headers,\n<24> [\n<25> (b\":method\", b\"GET\"),\n<26> (b\":scheme\", b\"https\"),\n<27> (b\":authority\", b\"localhost\"),\n<28> (b\":path\", b\"/\"),\n<29> (b\"x-foo\", b\"client\"),\n<30> ],\n<31> )\n<32> self.assertEqual(events[0].stream_id, stream_id)\n<33> self.assertEqual(events[0].stream_ended, False)\n<34> \n<35> self.assertTrue(isinstance(events[1], DataReceived))\n<36> self.assertEqual(events[1].data, b\"\")\n<37> self.assertEqual(events[1].stream_id, stream_id)\n<38> self.assertEqual(events[1].stream_ended, True)\n<39> \n<40> # send"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def _make_request(self, h3_client, h3_server):\n # offset: 1\n h3_server.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n (b\"x-foo\", b\"server\"),\n ],\n )\n h3_server.send_data(\n stream_id=stream_id,\n data=b\"hello\",\n end_stream=True,\n )\n \n # receive response\n events = h3_transfer(quic_server, h3_client)\n self.assertEqual(len(events), 2)\n \n self.assertTrue(isinstance(events[0], ResponseReceived))\n self.assertEqual(\n events[0].headers,\n [\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n (b\"x-foo\", b\"server\"),\n ],\n )\n self.assertEqual(events[0].push_id, None)\n self.assertEqual(events[0].stream_id, stream_id)\n self.assertEqual(events[0].stream_ended, False)\n \n self.assertTrue(isinstance(events[1], DataReceived))\n self.assertEqual(events[1].data, b\"hello\")\n self.assertEqual(events[1].push_id, None)\n self.assertEqual(events[1].stream_id, stream_id)\n self.assertEqual(events[1].stream_ended, True)\n \n \n===========unchanged ref 0===========\n at: aioquic.h3.connection.H3Connection\n send_data(stream_id: int, data: bytes, end_stream: bool) -> None\n \n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._quic = quic\n \n at: aioquic.h3.events\n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n RequestReceived(headers: Headers, stream_id: int, stream_ended: bool)\n \n ResponseReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.h3.events.DataReceived\n data: bytes\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.RequestReceived\n headers: Headers\n \n stream_id: int\n \n stream_ended: bool\n \n at: aioquic.h3.events.ResponseReceived\n headers: Headers\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.quic.connection.QuicConnection\n get_next_available_stream_id(is_unidirectional=False) -> int\n \n at: tests.test_h3\n h3_transfer(quic_sender, h3_receiver)\n \n at: tests.test_h3.H3ConnectionTest\n maxDiff = None\n \n at: unittest.case.TestCase\n failureException: Type[BaseException]\n \n longMessage: bool\n \n maxDiff: Optional[int]\n \n _testMethodName: str\n \n _testMethodDoc: str\n \n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n "}}},{"rowIdx":3414,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_request_headers_only"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"cbaebd25666112b8771f6511547385a2696f65bb"},"commit_message":{"kind":"string","value":"[tests] refactor http3 tests"},"ground_truth":{"kind":"string","value":"<23>: self.assertEqual(len(events), 1)\n<24>: \n<25>: self.assertTrue(isinstance(events[0], RequestReceived))\n<27>: events,\n events[0].headers,\n<29>: RequestReceived(\n headers=[\n (b\":method\", b\"HEAD\"),\n (b\":method\", b\"HEAD\"),\n<30>: (b\":scheme\", b\"https\"),\n (b\":scheme\", b\"https\"),\n<31>: (b\":authority\", b\"localhost\"),\n (b\":authority\", b\"localhost\"),\n<32>: (b\":path\", b\"/\"),\n (b\":path\", b\"/\"),\n<33>: (b\"x-foo\", b\"client\"),\n (b\"x-foo\", b\"client\"),\n<34>: ],\n stream_id=stream_id,\n stream_ended=True,\n )\n<36>: self.assertEqual(events[0].stream_id, stream_id)\n<37>: self.assertEqual(events[0].stream_ended, True)\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_headers_only(self):\n <0> with client_and_server(\n <1> client_options={\"alpn_protocols\": [\"h3-22\"]},\n <2> server_options={\"alpn_protocols\": [\"h3-22\"]},\n <3> ) as (quic_client, quic_server):\n <4> h3_client = H3Connection(quic_client)\n <5> h3_server = H3Connection(quic_server)\n <6> \n <7> # send request\n <8> stream_id = quic_client.get_next_available_stream_id()\n <9> h3_client.send_headers(\n<10> stream_id=stream_id,\n<11> headers=[\n<12> (b\":method\", b\"HEAD\"),\n<13> (b\":scheme\", b\"https\"),\n<14> (b\":authority\", b\"localhost\"),\n<15> (b\":path\", b\"/\"),\n<16> (b\"x-foo\", b\"client\"),\n<17> ],\n<18> end_stream=True,\n<19> )\n<20> \n<21> # receive request\n<22> events = h3_transfer(quic_client, h3_server)\n<23> self.assertEqual(len(events), 1)\n<24> \n<25> self.assertTrue(isinstance(events[0], RequestReceived))\n<26> self.assertEqual(\n<27> events[0].headers,\n<28> [\n<29> (b\":method\", b\"HEAD\"),\n<30> (b\":scheme\", b\"https\"),\n<31> (b\":authority\", b\"localhost\"),\n<32> (b\":path\", b\"/\"),\n<33> (b\"x-foo\", b\"client\"),\n<34> ],\n<35> )\n<36> self.assertEqual(events[0].stream_id, stream_id)\n<37> self.assertEqual(events[0].stream_ended, True)\n<38> \n<39> # send response\n<40> h3_server.send_headers(\n<41> stream_id=stream_id,\n<42> headers=[\n<43> (b"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_headers_only(self):\n # offset: 1\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n (b\"x-foo\", b\"server\"),\n ],\n end_stream=True,\n )\n \n # receive response\n events = h3_transfer(quic_server, h3_client)\n self.assertEqual(len(events), 1)\n \n self.assertTrue(isinstance(events[0], ResponseReceived))\n self.assertEqual(\n events[0].headers,\n [\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n (b\"x-foo\", b\"server\"),\n ],\n )\n self.assertEqual(events[0].push_id, None)\n self.assertEqual(events[0].stream_id, stream_id)\n self.assertEqual(events[0].stream_ended, True)\n \n \n===========unchanged ref 0===========\n at: aioquic.h3.connection\n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.events\n RequestReceived(headers: Headers, stream_id: int, stream_ended: bool)\n \n ResponseReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: tests.test_h3\n h3_transfer(quic_sender, h3_receiver)\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n assertTrue(expr: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def _make_request(self, h3_client, h3_server):\n quic_client = h3_client._quic\n quic_server = h3_server._quic\n \n # send request\n stream_id = quic_client.get_next_available_stream_id()\n h3_client.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/\"),\n (b\"x-foo\", b\"client\"),\n ],\n )\n h3_client.send_data(stream_id=stream_id, data=b\"\", end_stream=True)\n \n # receive request\n events = h3_transfer(quic_client, h3_server)\n - self.assertEqual(len(events), 2)\n - \n - self.assertTrue(isinstance(events[0], RequestReceived))\n self.assertEqual(\n + events,\n - events[0].headers,\n [\n + RequestReceived(\n + headers=[\n + (b\":method\", b\"GET\"),\n - (b\":method\", b\"GET\"),\n + (b\":scheme\", b\"https\"),\n - (b\":scheme\", b\"https\"),\n + (b\":authority\", b\"localhost\"),\n - (b\":authority\", b\"localhost\"),\n + (b\":path\", b\"/\"),\n - (b\":path\", b\"/\"),\n + (b\"x-foo\", b\"client\"),\n - (b\"x-foo\", b\"client\"),\n + ],\n + stream_id=stream_id,\n + stream_ended=False,\n + ),\n + DataReceived(data=b\"\", stream_id=stream_id, stream_ended=True),\n ],\n )\n - self.assert\n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def _make_request(self, h3_client, h3_server):\n # offset: 1\n b\"\", stream_id=stream_id, stream_ended=True),\n ],\n )\n - self.assertEqual(events[0].stream_id, stream_id)\n - self.assertEqual(events[0].stream_ended, False)\n - \n - self.assertTrue(isinstance(events[1], DataReceived))\n - self.assertEqual(events[1].data, b\"\")\n - self.assertEqual(events[1].stream_id, stream_id)\n - self.assertEqual(events[1].stream_ended, True)\n \n # send response\n h3_server.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n (b\"x-foo\", b\"server\"),\n ],\n )\n h3_server.send_data(\n stream_id=stream_id,\n data=b\"hello\",\n end_stream=True,\n )\n \n # receive response\n events = h3_transfer(quic_server, h3_client)\n - self.assertEqual(len(events), 2)\n - \n - self.assertTrue(isinstance(events[0], ResponseReceived))\n self.assertEqual(\n + events,\n - events[0].headers,\n [\n + ResponseReceived(\n + headers=[\n + (b\":status\", b\"200\"),\n - (b\":status\", b\"200\"),\n + (b\"content-type\", b\"text/html; charset=utf-8\"),\n - (b\"content-type\", b\"text/html; charset\n===========changed ref 2===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def _make_request(self, h3_client, h3_server):\n # offset: 2\n -8\"),\n + (b\"x-foo\", b\"server\"),\n - (b\"x-foo\", b\"server\"),\n + ],\n + stream_id=stream_id,\n + stream_ended=False,\n + ),\n + DataReceived(\n + data=b\"hello\",\n + stream_id=stream_id,\n + stream_ended=True,\n + ),\n ],\n )\n - self.assertEqual(events[0].push_id, None)\n - self.assertEqual(events[0].stream_id, stream_id)\n - self.assertEqual(events[0].stream_ended, False)\n \n - self.assertTrue(isinstance(events[1], DataReceived))\n - self.assertEqual(events[1].data, b\"hello\")\n - self.assertEqual(events[1].push_id, None)\n - self.assertEqual(events[1].stream_id, stream_id)\n - self.assertEqual(events[1].stream_ended, True)\n - "}}},{"rowIdx":3415,"cells":{"path":{"kind":"string","value":"aioquic.h0.connection/H0Connection.handle_event"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":" <7>: HeadersReceived(\n ResponseReceived(\n<14>: HeadersReceived(\n RequestReceived(\n"},"main_code":{"kind":"string","value":" # module: aioquic.h0.connection\n class H0Connection:\n def handle_event(self, event: QuicEvent) -> List[HttpEvent]:\n <0> http_events: List[HttpEvent] = []\n <1> \n <2> if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0:\n <3> data = event.data\n <4> if not self._headers_received.get(event.stream_id, False):\n <5> if self._is_client:\n <6> http_events.append(\n <7> ResponseReceived(\n <8> headers=[], stream_ended=False, stream_id=event.stream_id\n <9> )\n<10> )\n<11> else:\n<12> method, path = data.rstrip().split(b\" \", 1)\n<13> http_events.append(\n<14> RequestReceived(\n<15> headers=[(b\":method\", method), (b\":path\", path)],\n<16> stream_ended=False,\n<17> stream_id=event.stream_id,\n<18> )\n<19> )\n<20> data = b\"\"\n<21> self._headers_received[event.stream_id] = True\n<22> \n<23> http_events.append(\n<24> DataReceived(\n<25> data=data, stream_ended=event.end_stream, stream_id=event.stream_id\n<26> )\n<27> )\n<28> \n<29> return http_events\n<30> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h0.connection.H0Connection.__init__\n self._headers_received: Dict[int, bool] = {}\n \n self._is_client = quic.configuration.is_client\n \n self._quic = quic\n \n at: aioquic.h0.connection.H0Connection.handle_event\n http_events: List[HttpEvent] = []\n \n at: aioquic.h3.events\n Headers = List[Tuple[bytes, bytes]]\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.h3.events.DataReceived\n data: bytes\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.HeadersReceived\n headers: Headers\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.quic.connection.QuicConnection\n send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 1===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 2===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n===========changed ref 3===========\n # module: aioquic.h3.events\n - @dataclass\n - class ResponseReceived(HttpEvent):\n - \"\"\"\n - The ResponseReceived event is fired whenever response headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The response headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n - push_id: Optional[int] = None\n - \"The Push ID or `None` if this is not a push.\"\n - "}}},{"rowIdx":3416,"cells":{"path":{"kind":"string","value":"tests.test_h0/H0ConnectionTest.test_connect"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":"<24>: self.assertTrue(isinstance(events[0], HeadersReceived))\n self.assertTrue(isinstance(events[0], RequestReceived))\n"},"main_code":{"kind":"string","value":" # module: tests.test_h0\n class H0ConnectionTest(TestCase):\n def test_connect(self):\n <0> with client_and_server(\n <1> client_options={\"alpn_protocols\": [\"hq-22\"]},\n <2> server_options={\"alpn_protocols\": [\"hq-22\"]},\n <3> ) as (quic_client, quic_server):\n <4> h0_client = H0Connection(quic_client)\n <5> h0_server = H0Connection(quic_server)\n <6> \n <7> # send request\n <8> stream_id = quic_client.get_next_available_stream_id()\n <9> h0_client.send_headers(\n<10> stream_id=stream_id,\n<11> headers=[\n<12> (b\":method\", b\"GET\"),\n<13> (b\":scheme\", b\"https\"),\n<14> (b\":authority\", b\"localhost\"),\n<15> (b\":path\", b\"/\"),\n<16> ],\n<17> )\n<18> h0_client.send_data(stream_id=stream_id, data=b\"\", end_stream=True)\n<19> \n<20> # receive request\n<21> events = h0_transfer(quic_client, h0_server)\n<22> self.assertEqual(len(events), 2)\n<23> \n<24> self.assertTrue(isinstance(events[0], RequestReceived))\n<25> self.assertEqual(\n<26> events[0].headers, [(b\":method\", b\"GET\"), (b\":path\", b\"/\")]\n<27> )\n<28> self.assertEqual(events[0].stream_id, stream_id)\n<29> self.assertEqual(events[0].stream_ended, False)\n<30> \n<31> self.assertTrue(isinstance(events[1], DataReceived))\n<32> self.assertEqual(events[1].data, b\"\")\n<33> self.assertEqual(events[1].stream_id, stream_id)\n<34> self.assertEqual(events[1].stream_ended, True)\n<35> \n<36> # send response\n<37> h0_server.send_"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: tests.test_h0\n class H0ConnectionTest(TestCase):\n def test_connect(self):\n # offset: 1\n stream_id=stream_id,\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n ],\n )\n h0_server.send_data(\n stream_id=stream_id,\n data=b\"hello\",\n end_stream=True,\n )\n \n # receive response\n events = h0_transfer(quic_server, h0_client)\n self.assertEqual(len(events), 2)\n \n self.assertTrue(isinstance(events[0], ResponseReceived))\n self.assertEqual(events[0].headers, [])\n self.assertEqual(events[0].stream_id, stream_id)\n self.assertEqual(events[0].stream_ended, False)\n \n self.assertTrue(isinstance(events[1], DataReceived))\n self.assertEqual(events[1].data, b\"hello\")\n self.assertEqual(events[1].stream_id, stream_id)\n self.assertEqual(events[1].stream_ended, True)\n \n \n===========unchanged ref 0===========\n at: aioquic.h0.connection\n H0Connection(quic: QuicConnection)\n \n at: aioquic.h0.connection.H0Connection\n send_data(stream_id: int, data: bytes, end_stream: bool) -> None\n \n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.events\n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: tests.test_connection\n client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_options={}, server_patch=lambda x: None, transport_options={})\n \n at: tests.test_h0\n h0_transfer(quic_sender, h0_receiver)\n \n at: unittest.case.TestCase\n failureException: Type[BaseException]\n \n longMessage: bool\n \n maxDiff: Optional[int]\n \n _testMethodName: str\n \n _testMethodDoc: str\n \n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n assertTrue(expr: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 1===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 2===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n===========changed ref 3===========\n # module: aioquic.h3.events\n - @dataclass\n - class ResponseReceived(HttpEvent):\n - \"\"\"\n - The ResponseReceived event is fired whenever response headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The response headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n - push_id: Optional[int] = None\n - \"The Push ID or `None` if this is not a push.\"\n - \n===========changed ref 4===========\n # module: aioquic.h0.connection\n class H0Connection:\n def handle_event(self, event: QuicEvent) -> List[HttpEvent]:\n http_events: List[HttpEvent] = []\n \n if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0:\n data = event.data\n if not self._headers_received.get(event.stream_id, False):\n if self._is_client:\n http_events.append(\n + HeadersReceived(\n - ResponseReceived(\n headers=[], stream_ended=False, stream_id=event.stream_id\n )\n )\n else:\n method, path = data.rstrip().split(b\" \", 1)\n http_events.append(\n + HeadersReceived(\n - RequestReceived(\n headers=[(b\":method\", method), (b\":path\", path)],\n stream_ended=False,\n stream_id=event.stream_id,\n )\n )\n data = b\"\"\n self._headers_received[event.stream_id] = True\n \n http_events.append(\n DataReceived(\n data=data, stream_ended=event.end_stream, stream_id=event.stream_id\n )\n )\n \n return http_events\n "}}},{"rowIdx":3417,"cells":{"path":{"kind":"string","value":"tests.test_h0/H0ConnectionTest.test_headers_only"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":"<24>: self.assertTrue(isinstance(events[0], HeadersReceived))\n self.assertTrue(isinstance(events[0], RequestReceived))\n"},"main_code":{"kind":"string","value":" # module: tests.test_h0\n class H0ConnectionTest(TestCase):\n def test_headers_only(self):\n <0> with client_and_server(\n <1> client_options={\"alpn_protocols\": [\"hq-22\"]},\n <2> server_options={\"alpn_protocols\": [\"hq-22\"]},\n <3> ) as (quic_client, quic_server):\n <4> h0_client = H0Connection(quic_client)\n <5> h0_server = H0Connection(quic_server)\n <6> \n <7> # send request\n <8> stream_id = quic_client.get_next_available_stream_id()\n <9> h0_client.send_headers(\n<10> stream_id=stream_id,\n<11> headers=[\n<12> (b\":method\", b\"HEAD\"),\n<13> (b\":scheme\", b\"https\"),\n<14> (b\":authority\", b\"localhost\"),\n<15> (b\":path\", b\"/\"),\n<16> ],\n<17> end_stream=True,\n<18> )\n<19> \n<20> # receive request\n<21> events = h0_transfer(quic_client, h0_server)\n<22> self.assertEqual(len(events), 2)\n<23> \n<24> self.assertTrue(isinstance(events[0], RequestReceived))\n<25> self.assertEqual(\n<26> events[0].headers, [(b\":method\", b\"HEAD\"), (b\":path\", b\"/\")]\n<27> )\n<28> self.assertEqual(events[0].stream_id, stream_id)\n<29> self.assertEqual(events[0].stream_ended, False)\n<30> \n<31> self.assertTrue(isinstance(events[1], DataReceived))\n<32> self.assertEqual(events[1].data, b\"\")\n<33> self.assertEqual(events[1].stream_id, stream_id)\n<34> self.assertEqual(events[1].stream_ended, True)\n<35> \n<36> # send response\n<37> h0_server.send_headers(\n<38> stream_id=stream_id,\n<39> headers=[\n<40> "},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: tests.test_h0\n class H0ConnectionTest(TestCase):\n def test_headers_only(self):\n # offset: 1\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n ],\n end_stream=True,\n )\n \n # receive response\n events = h0_transfer(quic_server, h0_client)\n self.assertEqual(len(events), 2)\n \n self.assertTrue(isinstance(events[0], ResponseReceived))\n self.assertEqual(events[0].headers, [])\n self.assertEqual(events[0].stream_id, stream_id)\n self.assertEqual(events[0].stream_ended, False)\n \n self.assertTrue(isinstance(events[1], DataReceived))\n self.assertEqual(events[1].data, b\"\")\n self.assertEqual(events[1].stream_id, stream_id)\n self.assertEqual(events[1].stream_ended, True)\n \n \n===========unchanged ref 0===========\n at: aioquic.h0.connection\n H0Connection(quic: QuicConnection)\n \n at: aioquic.h0.connection.H0Connection\n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.events\n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: tests.test_connection\n client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_options={}, server_patch=lambda x: None, transport_options={})\n \n at: tests.test_h0\n h0_transfer(quic_sender, h0_receiver)\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n assertTrue(expr: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 1===========\n # module: tests.test_h0\n class H0ConnectionTest(TestCase):\n def test_connect(self):\n with client_and_server(\n client_options={\"alpn_protocols\": [\"hq-22\"]},\n server_options={\"alpn_protocols\": [\"hq-22\"]},\n ) as (quic_client, quic_server):\n h0_client = H0Connection(quic_client)\n h0_server = H0Connection(quic_server)\n \n # send request\n stream_id = quic_client.get_next_available_stream_id()\n h0_client.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/\"),\n ],\n )\n h0_client.send_data(stream_id=stream_id, data=b\"\", end_stream=True)\n \n # receive request\n events = h0_transfer(quic_client, h0_server)\n self.assertEqual(len(events), 2)\n \n + self.assertTrue(isinstance(events[0], HeadersReceived))\n - self.assertTrue(isinstance(events[0], RequestReceived))\n self.assertEqual(\n events[0].headers, [(b\":method\", b\"GET\"), (b\":path\", b\"/\")]\n )\n self.assertEqual(events[0].stream_id, stream_id)\n self.assertEqual(events[0].stream_ended, False)\n \n self.assertTrue(isinstance(events[1], DataReceived))\n self.assertEqual(events[1].data, b\"\")\n self.assertEqual(events[1].stream_id, stream_id)\n self.assertEqual(events[1].stream_ended, True)\n \n # send response\n h0_server.send_headers(\n stream_id=stream_id,\n headers=[\n (\n===========changed ref 2===========\n # module: tests.test_h0\n class H0ConnectionTest(TestCase):\n def test_connect(self):\n # offset: 1\n send response\n h0_server.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n ],\n )\n h0_server.send_data(\n stream_id=stream_id,\n data=b\"hello\",\n end_stream=True,\n )\n \n # receive response\n events = h0_transfer(quic_server, h0_client)\n self.assertEqual(len(events), 2)\n \n + self.assertTrue(isinstance(events[0], HeadersReceived))\n - self.assertTrue(isinstance(events[0], ResponseReceived))\n self.assertEqual(events[0].headers, [])\n self.assertEqual(events[0].stream_id, stream_id)\n self.assertEqual(events[0].stream_ended, False)\n \n self.assertTrue(isinstance(events[1], DataReceived))\n self.assertEqual(events[1].data, b\"hello\")\n self.assertEqual(events[1].stream_id, stream_id)\n self.assertEqual(events[1].stream_ended, True)\n \n===========changed ref 3===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 4===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n===========changed ref 5===========\n # module: aioquic.h3.events\n - @dataclass\n - class ResponseReceived(HttpEvent):\n - \"\"\"\n - The ResponseReceived event is fired whenever response headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The response headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n - push_id: Optional[int] = None\n - \"The Push ID or `None` if this is not a push.\"\n - "}}},{"rowIdx":3418,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._handle_push_frame"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":"<17>: HeadersReceived(\n ResponseReceived(\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _handle_push_frame(\n self,\n frame_type: int,\n frame_data: bytes,\n push_id: int,\n stream_id: int,\n stream_ended: bool,\n ) -> List[HttpEvent]:\n <0> \"\"\"\n <1> Handle a frame received on a push stream.\n <2> \"\"\"\n <3> http_events: List[HttpEvent] = []\n <4> \n <5> if frame_type == FrameType.DATA:\n <6> http_events.append(\n <7> DataReceived(\n <8> data=frame_data,\n <9> push_id=push_id,\n<10> stream_ended=stream_ended,\n<11> stream_id=stream_id,\n<12> )\n<13> )\n<14> elif frame_type == FrameType.HEADERS:\n<15> headers = self._decode_headers(stream_id, frame_data)\n<16> http_events.append(\n<17> ResponseReceived(\n<18> headers=headers,\n<19> push_id=push_id,\n<20> stream_id=stream_id,\n<21> stream_ended=stream_ended,\n<22> )\n<23> )\n<24> elif frame_type in (\n<25> FrameType.PRIORITY,\n<26> FrameType.CANCEL_PUSH,\n<27> FrameType.SETTINGS,\n<28> FrameType.PUSH_PROMISE,\n<29> FrameType.GOAWAY,\n<30> FrameType.MAX_PUSH_ID,\n<31> FrameType.DUPLICATE_PUSH,\n<32> ):\n<33> raise QuicConnectionError(\n<34> error_code=ErrorCode.HTTP_WRONG_STREAM,\n<35> frame_type=None,\n<36> reason_phrase=\"Invalid frame type on push stream\",\n<37> )\n<38> \n<39> return http_events\n<40> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n at: aioquic.h3.connection.H3Connection\n _decode_headers(stream_id: int, frame_data: bytes) -> Headers\n \n at: aioquic.h3.events\n HttpEvent()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.h3.events.DataReceived\n data: bytes\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.HeadersReceived\n headers: Headers\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.quic.connection\n QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 1===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 2===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n===========changed ref 3===========\n # module: aioquic.h3.events\n - @dataclass\n - class ResponseReceived(HttpEvent):\n - \"\"\"\n - The ResponseReceived event is fired whenever response headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The response headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n - push_id: Optional[int] = None\n - \"The Push ID or `None` if this is not a push.\"\n - \n===========changed ref 4===========\n # module: aioquic.h0.connection\n class H0Connection:\n def handle_event(self, event: QuicEvent) -> List[HttpEvent]:\n http_events: List[HttpEvent] = []\n \n if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0:\n data = event.data\n if not self._headers_received.get(event.stream_id, False):\n if self._is_client:\n http_events.append(\n + HeadersReceived(\n - ResponseReceived(\n headers=[], stream_ended=False, stream_id=event.stream_id\n )\n )\n else:\n method, path = data.rstrip().split(b\" \", 1)\n http_events.append(\n + HeadersReceived(\n - RequestReceived(\n headers=[(b\":method\", method), (b\":path\", path)],\n stream_ended=False,\n stream_id=event.stream_id,\n )\n )\n data = b\"\"\n self._headers_received[event.stream_id] = True\n \n http_events.append(\n DataReceived(\n data=data, stream_ended=event.end_stream, stream_id=event.stream_id\n )\n )\n \n return http_events\n \n===========changed ref 5===========\n # module: tests.test_h0\n class H0ConnectionTest(TestCase):\n def test_headers_only(self):\n with client_and_server(\n client_options={\"alpn_protocols\": [\"hq-22\"]},\n server_options={\"alpn_protocols\": [\"hq-22\"]},\n ) as (quic_client, quic_server):\n h0_client = H0Connection(quic_client)\n h0_server = H0Connection(quic_server)\n \n # send request\n stream_id = quic_client.get_next_available_stream_id()\n h0_client.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":method\", b\"HEAD\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/\"),\n ],\n end_stream=True,\n )\n \n # receive request\n events = h0_transfer(quic_client, h0_server)\n self.assertEqual(len(events), 2)\n \n + self.assertTrue(isinstance(events[0], HeadersReceived))\n - self.assertTrue(isinstance(events[0], RequestReceived))\n self.assertEqual(\n events[0].headers, [(b\":method\", b\"HEAD\"), (b\":path\", b\"/\")]\n )\n self.assertEqual(events[0].stream_id, stream_id)\n self.assertEqual(events[0].stream_ended, False)\n \n self.assertTrue(isinstance(events[1], DataReceived))\n self.assertEqual(events[1].data, b\"\")\n self.assertEqual(events[1].stream_id, stream_id)\n self.assertEqual(events[1].stream_ended, True)\n \n # send response\n h0_server.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"\n===========changed ref 6===========\n # module: tests.test_h0\n class H0ConnectionTest(TestCase):\n def test_headers_only(self):\n # offset: 1\n _id,\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n ],\n end_stream=True,\n )\n \n # receive response\n events = h0_transfer(quic_server, h0_client)\n self.assertEqual(len(events), 2)\n \n + self.assertTrue(isinstance(events[0], HeadersReceived))\n - self.assertTrue(isinstance(events[0], ResponseReceived))\n self.assertEqual(events[0].headers, [])\n self.assertEqual(events[0].stream_id, stream_id)\n self.assertEqual(events[0].stream_ended, False)\n \n self.assertTrue(isinstance(events[1], DataReceived))\n self.assertEqual(events[1].data, b\"\")\n self.assertEqual(events[1].stream_id, stream_id)\n self.assertEqual(events[1].stream_ended, True)\n "}}},{"rowIdx":3419,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_stream_data_bidi"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[HttpEvent]:\n <0> \"\"\"\n <1> Client-initiated bidirectional streams carry requests and responses.\n <2> \"\"\"\n <3> http_events: List[HttpEvent] = []\n <4> \n <5> stream = self._stream[stream_id]\n <6> stream.buffer += data\n <7> if stream_ended:\n <8> stream.ended = True\n <9> if stream.blocked:\n<10> return http_events\n<11> \n<12> # shortcut DATA frame bits\n<13> if (\n<14> stream.frame_type == FrameType.DATA\n<15> and stream.frame_size is not None\n<16> and len(stream.buffer) < stream.frame_size\n<17> ):\n<18> http_events.append(\n<19> DataReceived(\n<20> data=stream.buffer, stream_id=stream_id, stream_ended=False\n<21> )\n<22> )\n<23> stream.frame_size -= len(stream.buffer)\n<24> stream.buffer = b\"\"\n<25> return http_events\n<26> \n<27> # some peers (e.g. f5) end the stream with no data\n<28> if stream_ended and not stream.buffer:\n<29> http_events.append(\n<30> DataReceived(data=b\"\", stream_id=stream_id, stream_ended=True)\n<31> )\n<32> return http_events\n<33> \n<34> buf = Buffer(data=stream.buffer)\n<35> consumed = 0\n<36> \n<37> while not buf.eof():\n<38> # fetch next frame header\n<39> if stream.frame_size is None:\n<40> try:\n<41> stream.frame_type = buf.pull_uint_var()\n<42> stream.frame_size = buf.pull_uint_var()\n<43> except BufferReadError:\n<44> break\n<45> consumed = buf.tell()\n<46> \n<47> # check how much data is available\n<48> chunk_size = min(stream.frame_size, buf.capacity - consumed"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[HttpEvent]:\n # offset: 1\n if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size:\n break\n \n # read available data\n frame_data = buf.pull_bytes(chunk_size)\n consumed = buf.tell()\n \n # detect end of frame\n stream.frame_size -= chunk_size\n if not stream.frame_size:\n stream.frame_size = None\n \n if stream.frame_type == FrameType.DATA and (stream_ended or frame_data):\n http_events.append(\n DataReceived(\n data=frame_data,\n stream_id=stream_id,\n stream_ended=stream_ended and buf.eof(),\n )\n )\n elif stream.frame_type == FrameType.HEADERS:\n try:\n headers = self._decode_headers(stream_id, frame_data)\n except StreamBlocked:\n stream.blocked = True\n break\n cls = ResponseReceived if self._is_client else RequestReceived\n http_events.append(\n cls(\n headers=headers,\n stream_id=stream_id,\n stream_ended=stream_ended and buf.eof(),\n )\n )\n elif stream.frame_type == FrameType.PUSH_PROMISE:\n if not self._is_client:\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n frame_type=None,\n reason_phrase=\"Clients must not send PUSH_PROMISE\",\n )\n frame_buf = Buffer(data=frame_data)\n push_id = frame_buf.pull_uint_var()\n headers = self._decode_headers(\n stream_id, frame_data[frame_buf.tell() :]\n )\n http_events.append(\n PushPromiseReceived(\n headers=headers, push_\n===========below chunk 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[HttpEvent]:\n # offset: 2\n tell() :]\n )\n http_events.append(\n PushPromiseReceived(\n headers=headers, push_id=push_id, stream_id=stream_id\n )\n )\n elif stream.frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on request stream\",\n )\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n at: aioquic.h3.connection.H3Connection\n _decode_headers(stream_id: int, frame_data: bytes) -> Headers\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._is_client = quic.configuration.is_client\n \n self._stream: Dict[int, H3Stream] = {}\n \n at: aioquic.h3.connection.H3Stream.__init__\n self.blocked = False\n \n self.buffer = b\"\"\n \n self.ended = False\n \n self.frame_size: Optional[int] = None\n \n self.frame_type: Optional[int] = None\n \n at: aioquic.h3.events\n HttpEvent()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n PushPromiseReceived(headers: Headers, push_id: int, stream_id: int)\n \n at: aioquic.quic.connection\n QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)\n \n \n===========unchanged ref 1===========\n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_push_frame(\n self,\n frame_type: int,\n frame_data: bytes,\n push_id: int,\n stream_id: int,\n stream_ended: bool,\n ) -> List[HttpEvent]:\n \"\"\"\n Handle a frame received on a push stream.\n \"\"\"\n http_events: List[HttpEvent] = []\n \n if frame_type == FrameType.DATA:\n http_events.append(\n DataReceived(\n data=frame_data,\n push_id=push_id,\n stream_ended=stream_ended,\n stream_id=stream_id,\n )\n )\n elif frame_type == FrameType.HEADERS:\n headers = self._decode_headers(stream_id, frame_data)\n http_events.append(\n + HeadersReceived(\n - ResponseReceived(\n headers=headers,\n push_id=push_id,\n stream_id=stream_id,\n stream_ended=stream_ended,\n )\n )\n elif frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.PUSH_PROMISE,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n FrameType.DUPLICATE_PUSH,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on push stream\",\n )\n \n return http_events\n \n===========changed ref 2===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 3===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - "}}},{"rowIdx":3420,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_stream_data_uni"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[HttpEvent]:\n <0> http_events: List[HttpEvent] = []\n <1> \n <2> stream = self._stream[stream_id]\n <3> stream.buffer += data\n <4> if stream_ended:\n <5> stream.ended = True\n <6> \n <7> buf = Buffer(data=stream.buffer)\n <8> consumed = 0\n <9> unblocked_streams: Set[int] = set()\n<10> \n<11> while not buf.eof():\n<12> # fetch stream type for unidirectional streams\n<13> if stream.stream_type is None:\n<14> try:\n<15> stream.stream_type = buf.pull_uint_var()\n<16> except BufferReadError:\n<17> break\n<18> consumed = buf.tell()\n<19> \n<20> # check unicity\n<21> if stream.stream_type == StreamType.CONTROL:\n<22> assert self._peer_control_stream_id is None\n<23> self._peer_control_stream_id = stream_id\n<24> elif stream.stream_type == StreamType.QPACK_DECODER:\n<25> assert self._peer_decoder_stream_id is None\n<26> self._peer_decoder_stream_id = stream_id\n<27> elif stream.stream_type == StreamType.QPACK_ENCODER:\n<28> assert self._peer_encoder_stream_id is None\n<29> self._peer_encoder_stream_id = stream_id\n<30> \n<31> if stream.stream_type == StreamType.CONTROL:\n<32> # fetch next frame\n<33> try:\n<34> frame_type = buf.pull_uint_var()\n<35> frame_length = buf.pull_uint_var()\n<36> frame_data = buf.pull_bytes(frame_length)\n<37> except BufferReadError:\n<38> break\n<39> consumed = buf.tell()\n<40> \n<41> self._handle_control_frame(frame_type, frame_data)\n<42> elif stream.stream_"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[HttpEvent]:\n # offset: 1\n # fetch push id\n if stream.push_id is None:\n try:\n stream.push_id = buf.pull_uint_var()\n except BufferReadError:\n break\n consumed = buf.tell()\n \n # fetch next frame\n try:\n frame_type = buf.pull_uint_var()\n frame_length = buf.pull_uint_var()\n frame_data = buf.pull_bytes(frame_length)\n except BufferReadError:\n break\n consumed = buf.tell()\n \n http_events.extend(\n self._handle_push_frame(\n frame_type=frame_type,\n frame_data=frame_data,\n push_id=stream.push_id,\n stream_id=stream_id,\n stream_ended=stream.ended and buf.eof(),\n )\n )\n elif stream.stream_type == StreamType.QPACK_DECODER:\n # feed unframed data to decoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n self._encoder.feed_decoder(data)\n elif stream.stream_type == StreamType.QPACK_ENCODER:\n # feed unframed data to encoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n unblocked_streams.update(self._decoder.feed_encoder(data))\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n # process unblocked streams\n for stream_id in unblocked_streams:\n stream = self._stream[stream_id]\n decoder, headers = self._decoder.resume_header(stream_id)\n stream.blocked = False\n cls = ResponseReceived if self._is_client\n===========below chunk 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[HttpEvent]:\n # offset: 2\n ._decoder.resume_header(stream_id)\n stream.blocked = False\n cls = ResponseReceived if self._is_client else RequestReceived\n http_events.append(\n cls(\n headers=headers,\n stream_id=stream_id,\n stream_ended=stream.ended and not stream.buffer,\n )\n )\n http_events.extend(\n self._receive_stream_data_bidi(stream_id, b\"\", stream.ended)\n )\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n at: aioquic.h3.connection.H3Connection\n _handle_control_frame(frame_type: int, frame_data: bytes) -> None\n \n _handle_push_frame(frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[HttpEvent]\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._encoder = Encoder()\n \n self._stream: Dict[int, H3Stream] = {}\n \n self._peer_control_stream_id: Optional[int] = None\n \n self._peer_decoder_stream_id: Optional[int] = None\n \n self._peer_encoder_stream_id: Optional[int] = None\n \n at: aioquic.h3.events\n HttpEvent()\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n Set = _alias(set, 1, inst=False, name='Set')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_push_frame(\n self,\n frame_type: int,\n frame_data: bytes,\n push_id: int,\n stream_id: int,\n stream_ended: bool,\n ) -> List[HttpEvent]:\n \"\"\"\n Handle a frame received on a push stream.\n \"\"\"\n http_events: List[HttpEvent] = []\n \n if frame_type == FrameType.DATA:\n http_events.append(\n DataReceived(\n data=frame_data,\n push_id=push_id,\n stream_ended=stream_ended,\n stream_id=stream_id,\n )\n )\n elif frame_type == FrameType.HEADERS:\n headers = self._decode_headers(stream_id, frame_data)\n http_events.append(\n + HeadersReceived(\n - ResponseReceived(\n headers=headers,\n push_id=push_id,\n stream_id=stream_id,\n stream_ended=stream_ended,\n )\n )\n elif frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.PUSH_PROMISE,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n FrameType.DUPLICATE_PUSH,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on push stream\",\n )\n \n return http_events\n \n===========changed ref 1===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + "}}},{"rowIdx":3421,"cells":{"path":{"kind":"string","value":"examples.interop/test_http_0"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":"<14>: if events and isinstance(events[0], HeadersReceived):\n if events and isinstance(events[0], ResponseReceived):\n"},"main_code":{"kind":"string","value":" # module: examples.interop\n def test_http_0(server: Server, configuration: QuicConfiguration):\n <0> if server.path is None:\n <1> return\n <2> \n <3> configuration.alpn_protocols = [\"hq-22\"]\n <4> async with connect(\n <5> server.host,\n <6> server.port,\n <7> configuration=configuration,\n <8> create_protocol=HttpClient,\n <9> ) as protocol:\n<10> protocol = cast(HttpClient, protocol)\n<11> \n<12> # perform HTTP request\n<13> events = await protocol.get(server.host, server.path)\n<14> if events and isinstance(events[0], ResponseReceived):\n<15> server.result |= Result.D\n<16> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.asyncio.client\n connect(host: str, port: int, *, configuration: Optional[QuicConfiguration]=None, create_protocol: Optional[Callable]=QuicConnectionProtocol, session_ticket_handler: Optional[SessionTicketHandler]=None, stream_handler: Optional[QuicStreamHandler]=None) -> AsyncGenerator[QuicConnectionProtocol, None]\n connect(*args, **kwds)\n \n at: aioquic.h3.events\n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.configuration.QuicConfiguration\n alpn_protocols: Optional[List[str]] = None\n \n certificate: Any = None\n \n connection_id_length: int = 8\n \n idle_timeout: float = 60.0\n \n is_client: bool = True\n \n private_key: Any = None\n \n quic_logger: Optional[QuicLogger] = None\n \n secrets_log_file: TextIO = None\n \n server_name: Optional[str] = None\n \n session_ticket: Optional[SessionTicket] = None\n \n supported_versions: List[int] = field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n )\n \n at: examples.interop\n Result()\n \n \n===========unchanged ref 1===========\n Server(name: str, host: str, port: int=4433, http3: bool=True, retry_port: Optional[int]=4434, path: str=\"/\", result: Result=field(default_factory=lambda: Result(0)))\n \n at: examples.interop.Server\n name: str\n \n host: str\n \n port: int = 4433\n \n http3: bool = True\n \n retry_port: Optional[int] = 4434\n \n path: str = \"/\"\n \n result: Result = field(default_factory=lambda: Result(0))\n \n at: http3_client\n HttpClient(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None, /, *, quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None)\n \n at: http3_client.HttpClient\n get(authority: str, path: str) -> Deque[HttpEvent]\n \n at: typing\n cast(typ: Type[_T], val: Any) -> _T\n cast(typ: str, val: Any) -> Any\n cast(typ: object, val: Any) -> Any\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 1===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 2===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n===========changed ref 3===========\n # module: aioquic.h3.events\n - @dataclass\n - class ResponseReceived(HttpEvent):\n - \"\"\"\n - The ResponseReceived event is fired whenever response headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The response headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n - push_id: Optional[int] = None\n - \"The Push ID or `None` if this is not a push.\"\n - \n===========changed ref 4===========\n # module: aioquic.h0.connection\n class H0Connection:\n def handle_event(self, event: QuicEvent) -> List[HttpEvent]:\n http_events: List[HttpEvent] = []\n \n if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0:\n data = event.data\n if not self._headers_received.get(event.stream_id, False):\n if self._is_client:\n http_events.append(\n + HeadersReceived(\n - ResponseReceived(\n headers=[], stream_ended=False, stream_id=event.stream_id\n )\n )\n else:\n method, path = data.rstrip().split(b\" \", 1)\n http_events.append(\n + HeadersReceived(\n - RequestReceived(\n headers=[(b\":method\", method), (b\":path\", path)],\n stream_ended=False,\n stream_id=event.stream_id,\n )\n )\n data = b\"\"\n self._headers_received[event.stream_id] = True\n \n http_events.append(\n DataReceived(\n data=data, stream_ended=event.end_stream, stream_id=event.stream_id\n )\n )\n \n return http_events\n \n===========changed ref 5===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_push_frame(\n self,\n frame_type: int,\n frame_data: bytes,\n push_id: int,\n stream_id: int,\n stream_ended: bool,\n ) -> List[HttpEvent]:\n \"\"\"\n Handle a frame received on a push stream.\n \"\"\"\n http_events: List[HttpEvent] = []\n \n if frame_type == FrameType.DATA:\n http_events.append(\n DataReceived(\n data=frame_data,\n push_id=push_id,\n stream_ended=stream_ended,\n stream_id=stream_id,\n )\n )\n elif frame_type == FrameType.HEADERS:\n headers = self._decode_headers(stream_id, frame_data)\n http_events.append(\n + HeadersReceived(\n - ResponseReceived(\n headers=headers,\n push_id=push_id,\n stream_id=stream_id,\n stream_ended=stream_ended,\n )\n )\n elif frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.PUSH_PROMISE,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n FrameType.DUPLICATE_PUSH,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on push stream\",\n )\n \n return http_events\n "}}},{"rowIdx":3422,"cells":{"path":{"kind":"string","value":"examples.interop/test_http_3"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":"<14>: if events and isinstance(events[0], HeadersReceived):\n if events and isinstance(events[0], ResponseReceived):\n"},"main_code":{"kind":"string","value":" # module: examples.interop\n def test_http_3(server: Server, configuration: QuicConfiguration):\n <0> if server.path is None:\n <1> return\n <2> \n <3> configuration.alpn_protocols = [\"h3-22\"]\n <4> async with connect(\n <5> server.host,\n <6> server.port,\n <7> configuration=configuration,\n <8> create_protocol=HttpClient,\n <9> ) as protocol:\n<10> protocol = cast(HttpClient, protocol)\n<11> \n<12> # perform HTTP request\n<13> events = await protocol.get(server.host, server.path)\n<14> if events and isinstance(events[0], ResponseReceived):\n<15> server.result |= Result.D\n<16> server.result |= Result.three\n<17> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.asyncio.client\n connect(host: str, port: int, *, configuration: Optional[QuicConfiguration]=None, create_protocol: Optional[Callable]=QuicConnectionProtocol, session_ticket_handler: Optional[SessionTicketHandler]=None, stream_handler: Optional[QuicStreamHandler]=None) -> AsyncGenerator[QuicConnectionProtocol, None]\n connect(*args, **kwds)\n \n at: aioquic.h3.events\n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.configuration.QuicConfiguration\n alpn_protocols: Optional[List[str]] = None\n \n at: examples.interop\n Result()\n \n Server(name: str, host: str, port: int=4433, http3: bool=True, retry_port: Optional[int]=4434, path: str=\"/\", result: Result=field(default_factory=lambda: Result(0)))\n \n at: examples.interop.Server\n host: str\n \n port: int = 4433\n \n path: str = \"/\"\n \n result: Result = field(default_factory=lambda: Result(0))\n \n at: http3_client\n HttpClient(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None, /, *, quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None)\n \n \n===========unchanged ref 1===========\n at: http3_client.HttpClient\n get(authority: str, path: str) -> Deque[HttpEvent]\n \n at: typing\n cast(typ: Type[_T], val: Any) -> _T\n cast(typ: str, val: Any) -> Any\n cast(typ: object, val: Any) -> Any\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 1===========\n # module: examples.interop\n def test_http_0(server: Server, configuration: QuicConfiguration):\n if server.path is None:\n return\n \n configuration.alpn_protocols = [\"hq-22\"]\n async with connect(\n server.host,\n server.port,\n configuration=configuration,\n create_protocol=HttpClient,\n ) as protocol:\n protocol = cast(HttpClient, protocol)\n \n # perform HTTP request\n events = await protocol.get(server.host, server.path)\n + if events and isinstance(events[0], HeadersReceived):\n - if events and isinstance(events[0], ResponseReceived):\n server.result |= Result.D\n \n===========changed ref 2===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 3===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n===========changed ref 4===========\n # module: aioquic.h3.events\n - @dataclass\n - class ResponseReceived(HttpEvent):\n - \"\"\"\n - The ResponseReceived event is fired whenever response headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The response headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n - push_id: Optional[int] = None\n - \"The Push ID or `None` if this is not a push.\"\n - \n===========changed ref 5===========\n # module: aioquic.h0.connection\n class H0Connection:\n def handle_event(self, event: QuicEvent) -> List[HttpEvent]:\n http_events: List[HttpEvent] = []\n \n if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0:\n data = event.data\n if not self._headers_received.get(event.stream_id, False):\n if self._is_client:\n http_events.append(\n + HeadersReceived(\n - ResponseReceived(\n headers=[], stream_ended=False, stream_id=event.stream_id\n )\n )\n else:\n method, path = data.rstrip().split(b\" \", 1)\n http_events.append(\n + HeadersReceived(\n - RequestReceived(\n headers=[(b\":method\", method), (b\":path\", path)],\n stream_ended=False,\n stream_id=event.stream_id,\n )\n )\n data = b\"\"\n self._headers_received[event.stream_id] = True\n \n http_events.append(\n DataReceived(\n data=data, stream_ended=event.end_stream, stream_id=event.stream_id\n )\n )\n \n return http_events\n \n===========changed ref 6===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_push_frame(\n self,\n frame_type: int,\n frame_data: bytes,\n push_id: int,\n stream_id: int,\n stream_ended: bool,\n ) -> List[HttpEvent]:\n \"\"\"\n Handle a frame received on a push stream.\n \"\"\"\n http_events: List[HttpEvent] = []\n \n if frame_type == FrameType.DATA:\n http_events.append(\n DataReceived(\n data=frame_data,\n push_id=push_id,\n stream_ended=stream_ended,\n stream_id=stream_id,\n )\n )\n elif frame_type == FrameType.HEADERS:\n headers = self._decode_headers(stream_id, frame_data)\n http_events.append(\n + HeadersReceived(\n - ResponseReceived(\n headers=headers,\n push_id=push_id,\n stream_id=stream_id,\n stream_ended=stream_ended,\n )\n )\n elif frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.PUSH_PROMISE,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n FrameType.DUPLICATE_PUSH,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on push stream\",\n )\n \n return http_events\n "}}},{"rowIdx":3423,"cells":{"path":{"kind":"string","value":"examples.http3_client/WebSocket.http_event_received"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":" <0>: if isinstance(event, HeadersReceived):\n if isinstance(event, ResponseReceived):\n"},"main_code":{"kind":"string","value":" # module: examples.http3_client\n class WebSocket:\n def http_event_received(self, event: HttpEvent):\n <0> if isinstance(event, ResponseReceived):\n <1> for header, value in event.headers:\n <2> if header == b\"sec-websocket-protocol\":\n <3> self.subprotocol = value.decode(\"utf8\")\n <4> elif isinstance(event, DataReceived):\n <5> self.websocket.receive_data(event.data)\n <6> \n <7> for ws_event in self.websocket.events():\n <8> self.websocket_event_received(ws_event)\n <9> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h3.events\n HttpEvent()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: examples.http3_client.WebSocket\n websocket_event_received(event: wsproto.events.Event) -> None\n \n at: examples.http3_client.WebSocket.__init__\n self.subprotocol: Optional[str] = None\n \n self.websocket = wsproto.Connection(wsproto.ConnectionType.CLIENT)\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 1===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 2===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n===========changed ref 3===========\n # module: aioquic.h3.events\n - @dataclass\n - class ResponseReceived(HttpEvent):\n - \"\"\"\n - The ResponseReceived event is fired whenever response headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The response headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n - push_id: Optional[int] = None\n - \"The Push ID or `None` if this is not a push.\"\n - \n===========changed ref 4===========\n # module: examples.interop\n def test_http_0(server: Server, configuration: QuicConfiguration):\n if server.path is None:\n return\n \n configuration.alpn_protocols = [\"hq-22\"]\n async with connect(\n server.host,\n server.port,\n configuration=configuration,\n create_protocol=HttpClient,\n ) as protocol:\n protocol = cast(HttpClient, protocol)\n \n # perform HTTP request\n events = await protocol.get(server.host, server.path)\n + if events and isinstance(events[0], HeadersReceived):\n - if events and isinstance(events[0], ResponseReceived):\n server.result |= Result.D\n \n===========changed ref 5===========\n # module: examples.interop\n def test_http_3(server: Server, configuration: QuicConfiguration):\n if server.path is None:\n return\n \n configuration.alpn_protocols = [\"h3-22\"]\n async with connect(\n server.host,\n server.port,\n configuration=configuration,\n create_protocol=HttpClient,\n ) as protocol:\n protocol = cast(HttpClient, protocol)\n \n # perform HTTP request\n events = await protocol.get(server.host, server.path)\n + if events and isinstance(events[0], HeadersReceived):\n - if events and isinstance(events[0], ResponseReceived):\n server.result |= Result.D\n server.result |= Result.three\n \n===========changed ref 6===========\n # module: aioquic.h0.connection\n class H0Connection:\n def handle_event(self, event: QuicEvent) -> List[HttpEvent]:\n http_events: List[HttpEvent] = []\n \n if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0:\n data = event.data\n if not self._headers_received.get(event.stream_id, False):\n if self._is_client:\n http_events.append(\n + HeadersReceived(\n - ResponseReceived(\n headers=[], stream_ended=False, stream_id=event.stream_id\n )\n )\n else:\n method, path = data.rstrip().split(b\" \", 1)\n http_events.append(\n + HeadersReceived(\n - RequestReceived(\n headers=[(b\":method\", method), (b\":path\", path)],\n stream_ended=False,\n stream_id=event.stream_id,\n )\n )\n data = b\"\"\n self._headers_received[event.stream_id] = True\n \n http_events.append(\n DataReceived(\n data=data, stream_ended=event.end_stream, stream_id=event.stream_id\n )\n )\n \n return http_events\n \n===========changed ref 7===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_push_frame(\n self,\n frame_type: int,\n frame_data: bytes,\n push_id: int,\n stream_id: int,\n stream_ended: bool,\n ) -> List[HttpEvent]:\n \"\"\"\n Handle a frame received on a push stream.\n \"\"\"\n http_events: List[HttpEvent] = []\n \n if frame_type == FrameType.DATA:\n http_events.append(\n DataReceived(\n data=frame_data,\n push_id=push_id,\n stream_ended=stream_ended,\n stream_id=stream_id,\n )\n )\n elif frame_type == FrameType.HEADERS:\n headers = self._decode_headers(stream_id, frame_data)\n http_events.append(\n + HeadersReceived(\n - ResponseReceived(\n headers=headers,\n push_id=push_id,\n stream_id=stream_id,\n stream_ended=stream_ended,\n )\n )\n elif frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.PUSH_PROMISE,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n FrameType.DUPLICATE_PUSH,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on push stream\",\n )\n \n return http_events\n "}}},{"rowIdx":3424,"cells":{"path":{"kind":"string","value":"examples.http3_client/HttpClient.http_event_received"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":" <0>: if isinstance(event, (HeadersReceived, DataReceived)):\n if isinstance(event, (ResponseReceived, DataReceived)):\n"},"main_code":{"kind":"string","value":" # module: examples.http3_client\n class HttpClient(QuicConnectionProtocol):\n def http_event_received(self, event: HttpEvent):\n <0> if isinstance(event, (ResponseReceived, DataReceived)):\n <1> stream_id = event.stream_id\n <2> if stream_id in self._request_events:\n <3> # http\n <4> self._request_events[event.stream_id].append(event)\n <5> if event.stream_ended:\n <6> request_waiter = self._request_waiter.pop(stream_id)\n <7> request_waiter.set_result(self._request_events.pop(stream_id))\n <8> \n <9> elif stream_id in self._websockets:\n<10> # websocket\n<11> websocket = self._websockets[stream_id]\n<12> websocket.http_event_received(event)\n<13> \n<14> else:\n<15> # push\n<16> print(event)\n<17> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: _asyncio.Future\n set_result(result, /)\n \n at: aioquic.h3.events\n HttpEvent()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: asyncio.futures.Future\n _state = _PENDING\n \n _result = None\n \n _exception = None\n \n _loop = None\n \n _source_traceback = None\n \n _cancel_message = None\n \n _cancelled_exc = None\n \n _asyncio_future_blocking = False\n \n __log_traceback = False\n \n __class_getitem__ = classmethod(GenericAlias)\n \n set_result(result: _T, /) -> None\n \n __iter__ = __await__ # make compatible with 'yield from'.\n \n at: collections.deque\n append(x: _T) -> None\n \n at: examples.http3_client.HttpClient.__init__\n self._request_events: Dict[int, Deque[HttpEvent]] = {}\n \n self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {}\n \n self._websockets: Dict[int, WebSocket] = {}\n \n at: examples.http3_client.WebSocket\n http_event_received(event: HttpEvent)\n http_event_received(self, event: HttpEvent)\n \n at: typing.MutableMapping\n pop(key: _KT) -> _VT\n pop(key: _KT, default: Union[_VT, _T]=...) -> Union[_VT, _T]\n \n \n===========changed ref 0===========\n # module: examples.http3_client\n class WebSocket:\n def http_event_received(self, event: HttpEvent):\n + if isinstance(event, HeadersReceived):\n - if isinstance(event, ResponseReceived):\n for header, value in event.headers:\n if header == b\"sec-websocket-protocol\":\n self.subprotocol = value.decode(\"utf8\")\n elif isinstance(event, DataReceived):\n self.websocket.receive_data(event.data)\n \n for ws_event in self.websocket.events():\n self.websocket_event_received(ws_event)\n \n===========changed ref 1===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 2===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 3===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n===========changed ref 4===========\n # module: aioquic.h3.events\n - @dataclass\n - class ResponseReceived(HttpEvent):\n - \"\"\"\n - The ResponseReceived event is fired whenever response headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The response headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n - push_id: Optional[int] = None\n - \"The Push ID or `None` if this is not a push.\"\n - \n===========changed ref 5===========\n # module: examples.interop\n def test_http_0(server: Server, configuration: QuicConfiguration):\n if server.path is None:\n return\n \n configuration.alpn_protocols = [\"hq-22\"]\n async with connect(\n server.host,\n server.port,\n configuration=configuration,\n create_protocol=HttpClient,\n ) as protocol:\n protocol = cast(HttpClient, protocol)\n \n # perform HTTP request\n events = await protocol.get(server.host, server.path)\n + if events and isinstance(events[0], HeadersReceived):\n - if events and isinstance(events[0], ResponseReceived):\n server.result |= Result.D\n \n===========changed ref 6===========\n # module: examples.interop\n def test_http_3(server: Server, configuration: QuicConfiguration):\n if server.path is None:\n return\n \n configuration.alpn_protocols = [\"h3-22\"]\n async with connect(\n server.host,\n server.port,\n configuration=configuration,\n create_protocol=HttpClient,\n ) as protocol:\n protocol = cast(HttpClient, protocol)\n \n # perform HTTP request\n events = await protocol.get(server.host, server.path)\n + if events and isinstance(events[0], HeadersReceived):\n - if events and isinstance(events[0], ResponseReceived):\n server.result |= Result.D\n server.result |= Result.three\n \n===========changed ref 7===========\n # module: aioquic.h0.connection\n class H0Connection:\n def handle_event(self, event: QuicEvent) -> List[HttpEvent]:\n http_events: List[HttpEvent] = []\n \n if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0:\n data = event.data\n if not self._headers_received.get(event.stream_id, False):\n if self._is_client:\n http_events.append(\n + HeadersReceived(\n - ResponseReceived(\n headers=[], stream_ended=False, stream_id=event.stream_id\n )\n )\n else:\n method, path = data.rstrip().split(b\" \", 1)\n http_events.append(\n + HeadersReceived(\n - RequestReceived(\n headers=[(b\":method\", method), (b\":path\", path)],\n stream_ended=False,\n stream_id=event.stream_id,\n )\n )\n data = b\"\"\n self._headers_received[event.stream_id] = True\n \n http_events.append(\n DataReceived(\n data=data, stream_ended=event.end_stream, stream_id=event.stream_id\n )\n )\n \n return http_events\n "}}},{"rowIdx":3425,"cells":{"path":{"kind":"string","value":"examples.http3_client/run"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: examples.http3_client\n def run(configuration: QuicConfiguration, url: str) -> None:\n <0> # parse URL\n <1> parsed = urlparse(url)\n <2> assert parsed.scheme in (\n <3> \"https\",\n <4> \"wss\",\n <5> ), \"Only https:// or wss:// URLs are supported.\"\n <6> if \":\" in parsed.netloc:\n <7> host, port_str = parsed.netloc.split(\":\")\n <8> port = int(port_str)\n <9> else:\n<10> host = parsed.netloc\n<11> port = 443\n<12> \n<13> path = parsed.path\n<14> if parsed.query:\n<15> path += \"?\" + parsed.query\n<16> \n<17> async with connect(\n<18> host,\n<19> port,\n<20> configuration=configuration,\n<21> create_protocol=HttpClient,\n<22> session_ticket_handler=save_session_ticket,\n<23> ) as client:\n<24> client = cast(HttpClient, client)\n<25> \n<26> if parsed.scheme == \"wss\":\n<27> ws = await client.websocket(\n<28> parsed.netloc, path, subprotocols=[\"chat\", \"superchat\"]\n<29> )\n<30> \n<31> # send some messages and receive reply\n<32> for i in range(2):\n<33> message = \"Hello {}, WebSocket!\".format(i)\n<34> print(\"> \" + message)\n<35> await ws.send(message)\n<36> \n<37> message = await ws.recv()\n<38> print(\"< \" + message)\n<39> \n<40> await ws.close()\n<41> else:\n<42> # perform request\n<43> start = time.time()\n<44> http_events = await client.get(parsed.netloc, path)\n<45> elapsed = time.time() - start\n<46> \n<47> # print speed\n<48> octets = 0\n<49> for http_event in http_events:\n<50> if isinstance(http_event, DataReceived):\n<51> octets += len(http_event.data)\n<52> logger.info(\n<53> \"Received %d bytes in %.1f s (%.3f Mbps)\"\n<54> % (octets,"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: examples.http3_client\n def run(configuration: QuicConfiguration, url: str) -> None:\n # offset: 1\n )\n \n # print response\n for http_event in http_events:\n if isinstance(http_event, ResponseReceived):\n headers = b\"\"\n for k, v in http_event.headers:\n headers += k + b\": \" + v + b\"\\r\\n\"\n if headers:\n sys.stderr.buffer.write(headers + b\"\\r\\n\")\n sys.stderr.buffer.flush()\n elif isinstance(http_event, DataReceived):\n sys.stdout.buffer.write(http_event.data)\n sys.stdout.buffer.flush()\n \n \n===========unchanged ref 0===========\n at: aioquic.asyncio.client\n connect(host: str, port: int, *, configuration: Optional[QuicConfiguration]=None, create_protocol: Optional[Callable]=QuicConnectionProtocol, session_ticket_handler: Optional[SessionTicketHandler]=None, stream_handler: Optional[QuicStreamHandler]=None) -> AsyncGenerator[QuicConnectionProtocol, None]\n connect(*args, **kwds)\n \n at: aioquic.h3.events\n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: examples.http3_client\n logger = logging.getLogger(\"client\")\n \n HttpClient(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None, /, *, quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None)\n \n save_session_ticket(ticket)\n \n at: examples.http3_client.HttpClient\n get(authority: str, path: str) -> Deque[HttpEvent]\n \n websocket(authority: str, path: str, subprotocols: List[str]=[]) -> WebSocket\n \n at: examples.http3_client.WebSocket\n close(code=1000, reason=\"\") -> None\n \n recv() -> str\n \n send(message: str)\n \n \n===========unchanged ref 1===========\n at: logging.Logger\n info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None\n \n at: sys\n stdout: TextIO\n \n stderr: TextIO\n \n at: time\n time() -> float\n \n at: typing\n cast(typ: Type[_T], val: Any) -> _T\n cast(typ: str, val: Any) -> Any\n cast(typ: object, val: Any) -> Any\n \n at: typing.BinaryIO\n __slots__ = ()\n \n write(s: AnyStr) -> int\n \n at: typing.IO\n __slots__ = ()\n \n flush() -> None\n \n at: typing.TextIO\n __slots__ = ()\n \n at: urllib.parse\n urlparse(url: str, scheme: Optional[str]=..., allow_fragments: bool=...) -> ParseResult\n urlparse(url: Optional[bytes], scheme: Optional[bytes]=..., allow_fragments: bool=...) -> ParseResultBytes\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 1===========\n # module: examples.http3_client\n class HttpClient(QuicConnectionProtocol):\n def http_event_received(self, event: HttpEvent):\n + if isinstance(event, (HeadersReceived, DataReceived)):\n - if isinstance(event, (ResponseReceived, DataReceived)):\n stream_id = event.stream_id\n if stream_id in self._request_events:\n # http\n self._request_events[event.stream_id].append(event)\n if event.stream_ended:\n request_waiter = self._request_waiter.pop(stream_id)\n request_waiter.set_result(self._request_events.pop(stream_id))\n \n elif stream_id in self._websockets:\n # websocket\n websocket = self._websockets[stream_id]\n websocket.http_event_received(event)\n \n else:\n # push\n print(event)\n \n===========changed ref 2===========\n # module: examples.http3_client\n class WebSocket:\n def http_event_received(self, event: HttpEvent):\n + if isinstance(event, HeadersReceived):\n - if isinstance(event, ResponseReceived):\n for header, value in event.headers:\n if header == b\"sec-websocket-protocol\":\n self.subprotocol = value.decode(\"utf8\")\n elif isinstance(event, DataReceived):\n self.websocket.receive_data(event.data)\n \n for ws_event in self.websocket.events():\n self.websocket_event_received(ws_event)\n \n===========changed ref 3===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 4===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n===========changed ref 5===========\n # module: aioquic.h3.events\n - @dataclass\n - class ResponseReceived(HttpEvent):\n - \"\"\"\n - The ResponseReceived event is fired whenever response headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The response headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n - push_id: Optional[int] = None\n - \"The Push ID or `None` if this is not a push.\"\n - \n===========changed ref 6===========\n # module: examples.interop\n def test_http_0(server: Server, configuration: QuicConfiguration):\n if server.path is None:\n return\n \n configuration.alpn_protocols = [\"hq-22\"]\n async with connect(\n server.host,\n server.port,\n configuration=configuration,\n create_protocol=HttpClient,\n ) as protocol:\n protocol = cast(HttpClient, protocol)\n \n # perform HTTP request\n events = await protocol.get(server.host, server.path)\n + if events and isinstance(events[0], HeadersReceived):\n - if events and isinstance(events[0], ResponseReceived):\n server.result |= Result.D\n "}}},{"rowIdx":3426,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest._make_request"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":"<22>: HeadersReceived(\n RequestReceived(\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def _make_request(self, h3_client, h3_server):\n <0> quic_client = h3_client._quic\n <1> quic_server = h3_server._quic\n <2> \n <3> # send request\n <4> stream_id = quic_client.get_next_available_stream_id()\n <5> h3_client.send_headers(\n <6> stream_id=stream_id,\n <7> headers=[\n <8> (b\":method\", b\"GET\"),\n <9> (b\":scheme\", b\"https\"),\n<10> (b\":authority\", b\"localhost\"),\n<11> (b\":path\", b\"/\"),\n<12> (b\"x-foo\", b\"client\"),\n<13> ],\n<14> )\n<15> h3_client.send_data(stream_id=stream_id, data=b\"\", end_stream=True)\n<16> \n<17> # receive request\n<18> events = h3_transfer(quic_client, h3_server)\n<19> self.assertEqual(\n<20> events,\n<21> [\n<22> RequestReceived(\n<23> headers=[\n<24> (b\":method\", b\"GET\"),\n<25> (b\":scheme\", b\"https\"),\n<26> (b\":authority\", b\"localhost\"),\n<27> (b\":path\", b\"/\"),\n<28> (b\"x-foo\", b\"client\"),\n<29> ],\n<30> stream_id=stream_id,\n<31> stream_ended=False,\n<32> ),\n<33> DataReceived(data=b\"\", stream_id=stream_id, stream_ended=True),\n<34> ],\n<35> )\n<36> \n<37> # send response\n<38> h3_server.send_headers(\n<39> stream_id=stream_id,\n<40> headers=[\n<41> (b\":status\", b\"200\"),\n<42> (b\"content-type\", b\"text/html; charset=utf-8\"),\n<43> (b\"x-foo\", b\"server\"),\n<44> ],"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def _make_request(self, h3_client, h3_server):\n # offset: 1\n h3_server.send_data(\n stream_id=stream_id,\n data=b\"hello\",\n end_stream=True,\n )\n \n # receive response\n events = h3_transfer(quic_server, h3_client)\n self.assertEqual(\n events,\n [\n ResponseReceived(\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n (b\"x-foo\", b\"server\"),\n ],\n stream_id=stream_id,\n stream_ended=False,\n ),\n DataReceived(\n data=b\"hello\",\n stream_id=stream_id,\n stream_ended=True,\n ),\n ],\n )\n \n \n===========unchanged ref 0===========\n at: aioquic.h3.connection.H3Connection\n send_data(stream_id: int, data: bytes, end_stream: bool) -> None\n \n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.events\n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.h3.events.DataReceived\n data: bytes\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.HeadersReceived\n headers: Headers\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.quic.connection.QuicConnection\n get_next_available_stream_id(is_unidirectional=False) -> int\n \n at: tests.test_h3\n h3_transfer(quic_sender, h3_receiver)\n \n at: tests.test_h3.H3ConnectionTest\n maxDiff = None\n \n at: tests.test_h3.H3ConnectionTest._make_request\n quic_client = h3_client._quic\n \n quic_server = h3_server._quic\n \n at: unittest.case.TestCase\n failureException: Type[BaseException]\n \n longMessage: bool\n \n maxDiff: Optional[int]\n \n _testMethodName: str\n \n _testMethodDoc: str\n \n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 1===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 2===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n===========changed ref 3===========\n # module: examples.http3_client\n class WebSocket:\n def http_event_received(self, event: HttpEvent):\n + if isinstance(event, HeadersReceived):\n - if isinstance(event, ResponseReceived):\n for header, value in event.headers:\n if header == b\"sec-websocket-protocol\":\n self.subprotocol = value.decode(\"utf8\")\n elif isinstance(event, DataReceived):\n self.websocket.receive_data(event.data)\n \n for ws_event in self.websocket.events():\n self.websocket_event_received(ws_event)\n \n===========changed ref 4===========\n # module: aioquic.h3.events\n - @dataclass\n - class ResponseReceived(HttpEvent):\n - \"\"\"\n - The ResponseReceived event is fired whenever response headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The response headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n - push_id: Optional[int] = None\n - \"The Push ID or `None` if this is not a push.\"\n - \n===========changed ref 5===========\n # module: examples.interop\n def test_http_0(server: Server, configuration: QuicConfiguration):\n if server.path is None:\n return\n \n configuration.alpn_protocols = [\"hq-22\"]\n async with connect(\n server.host,\n server.port,\n configuration=configuration,\n create_protocol=HttpClient,\n ) as protocol:\n protocol = cast(HttpClient, protocol)\n \n # perform HTTP request\n events = await protocol.get(server.host, server.path)\n + if events and isinstance(events[0], HeadersReceived):\n - if events and isinstance(events[0], ResponseReceived):\n server.result |= Result.D\n \n===========changed ref 6===========\n # module: examples.interop\n def test_http_3(server: Server, configuration: QuicConfiguration):\n if server.path is None:\n return\n \n configuration.alpn_protocols = [\"h3-22\"]\n async with connect(\n server.host,\n server.port,\n configuration=configuration,\n create_protocol=HttpClient,\n ) as protocol:\n protocol = cast(HttpClient, protocol)\n \n # perform HTTP request\n events = await protocol.get(server.host, server.path)\n + if events and isinstance(events[0], HeadersReceived):\n - if events and isinstance(events[0], ResponseReceived):\n server.result |= Result.D\n server.result |= Result.three\n \n===========changed ref 7===========\n # module: examples.http3_client\n class HttpClient(QuicConnectionProtocol):\n def http_event_received(self, event: HttpEvent):\n + if isinstance(event, (HeadersReceived, DataReceived)):\n - if isinstance(event, (ResponseReceived, DataReceived)):\n stream_id = event.stream_id\n if stream_id in self._request_events:\n # http\n self._request_events[event.stream_id].append(event)\n if event.stream_ended:\n request_waiter = self._request_waiter.pop(stream_id)\n request_waiter.set_result(self._request_events.pop(stream_id))\n \n elif stream_id in self._websockets:\n # websocket\n websocket = self._websockets[stream_id]\n websocket.http_event_received(event)\n \n else:\n # push\n print(event)\n "}}},{"rowIdx":3427,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_request_headers_only"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":"<26>: HeadersReceived(\n RequestReceived(\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_headers_only(self):\n <0> with client_and_server(\n <1> client_options={\"alpn_protocols\": [\"h3-22\"]},\n <2> server_options={\"alpn_protocols\": [\"h3-22\"]},\n <3> ) as (quic_client, quic_server):\n <4> h3_client = H3Connection(quic_client)\n <5> h3_server = H3Connection(quic_server)\n <6> \n <7> # send request\n <8> stream_id = quic_client.get_next_available_stream_id()\n <9> h3_client.send_headers(\n<10> stream_id=stream_id,\n<11> headers=[\n<12> (b\":method\", b\"HEAD\"),\n<13> (b\":scheme\", b\"https\"),\n<14> (b\":authority\", b\"localhost\"),\n<15> (b\":path\", b\"/\"),\n<16> (b\"x-foo\", b\"client\"),\n<17> ],\n<18> end_stream=True,\n<19> )\n<20> \n<21> # receive request\n<22> events = h3_transfer(quic_client, h3_server)\n<23> self.assertEqual(\n<24> events,\n<25> [\n<26> RequestReceived(\n<27> headers=[\n<28> (b\":method\", b\"HEAD\"),\n<29> (b\":scheme\", b\"https\"),\n<30> (b\":authority\", b\"localhost\"),\n<31> (b\":path\", b\"/\"),\n<32> (b\"x-foo\", b\"client\"),\n<33> ],\n<34> stream_id=stream_id,\n<35> stream_ended=True,\n<36> )\n<37> ],\n<38> )\n<39> \n<40> # send response\n<41> h3_server.send_headers(\n<42> stream_id=stream_id,\n<43> headers=[\n<44> (b\":status\", b\"200\"),\n<45> (b\"content-type\", b\"text/html; charset=utf-8\"),\n<46> (b"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_headers_only(self):\n # offset: 1\n ],\n end_stream=True,\n )\n \n # receive response\n events = h3_transfer(quic_server, h3_client)\n self.assertEqual(len(events), 1)\n \n self.assertTrue(\n events,\n [\n ResponseReceived(\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n (b\"x-foo\", b\"server\"),\n ],\n stream_id=stream_id,\n stream_ended=True,\n )\n ],\n )\n \n \n===========unchanged ref 0===========\n at: aioquic.h3.connection\n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.events\n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.configuration.QuicConfiguration\n alpn_protocols: Optional[List[str]] = None\n \n certificate: Any = None\n \n connection_id_length: int = 8\n \n idle_timeout: float = 60.0\n \n is_client: bool = True\n \n private_key: Any = None\n \n quic_logger: Optional[QuicLogger] = None\n \n secrets_log_file: TextIO = None\n \n server_name: Optional[str] = None\n \n session_ticket: Optional[SessionTicket] = None\n \n supported_versions: List[int] = field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n )\n \n at: tests.test_h3\n h3_transfer(quic_sender, h3_receiver)\n \n FakeQuicConnection(configuration)\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========unchanged ref 1===========\n assertTrue(expr: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def _make_request(self, h3_client, h3_server):\n quic_client = h3_client._quic\n quic_server = h3_server._quic\n \n # send request\n stream_id = quic_client.get_next_available_stream_id()\n h3_client.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/\"),\n (b\"x-foo\", b\"client\"),\n ],\n )\n h3_client.send_data(stream_id=stream_id, data=b\"\", end_stream=True)\n \n # receive request\n events = h3_transfer(quic_client, h3_server)\n self.assertEqual(\n events,\n [\n + HeadersReceived(\n - RequestReceived(\n headers=[\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/\"),\n (b\"x-foo\", b\"client\"),\n ],\n stream_id=stream_id,\n stream_ended=False,\n ),\n DataReceived(data=b\"\", stream_id=stream_id, stream_ended=True),\n ],\n )\n \n # send response\n h3_server.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n (b\"x-foo\", b\"server\"),\n ],\n )\n h3_server.send_data(\n stream_id=stream_id,\n data=b\"hello\n===========changed ref 2===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def _make_request(self, h3_client, h3_server):\n # offset: 1\n server.send_data(\n stream_id=stream_id,\n data=b\"hello\",\n end_stream=True,\n )\n \n # receive response\n events = h3_transfer(quic_server, h3_client)\n self.assertEqual(\n events,\n [\n + HeadersReceived(\n - ResponseReceived(\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n (b\"x-foo\", b\"server\"),\n ],\n stream_id=stream_id,\n stream_ended=False,\n ),\n DataReceived(\n data=b\"hello\",\n stream_id=stream_id,\n stream_ended=True,\n ),\n ],\n )\n \n===========changed ref 3===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 4===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n===========changed ref 5===========\n # module: examples.http3_client\n class WebSocket:\n def http_event_received(self, event: HttpEvent):\n + if isinstance(event, HeadersReceived):\n - if isinstance(event, ResponseReceived):\n for header, value in event.headers:\n if header == b\"sec-websocket-protocol\":\n self.subprotocol = value.decode(\"utf8\")\n elif isinstance(event, DataReceived):\n self.websocket.receive_data(event.data)\n \n for ws_event in self.websocket.events():\n self.websocket_event_received(ws_event)\n "}}},{"rowIdx":3428,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_request_fragmented_frame"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":"<29>: HeadersReceived(\n RequestReceived(\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_fragmented_frame(self):\n <0> quic_client = FakeQuicConnection(\n <1> configuration=QuicConfiguration(is_client=True)\n <2> )\n <3> quic_server = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=False)\n <5> )\n <6> \n <7> h3_client = H3Connection(quic_client)\n <8> h3_server = H3Connection(quic_server)\n <9> \n<10> # send request\n<11> stream_id = quic_client.get_next_available_stream_id()\n<12> h3_client.send_headers(\n<13> stream_id=stream_id,\n<14> headers=[\n<15> (b\":method\", b\"GET\"),\n<16> (b\":scheme\", b\"https\"),\n<17> (b\":authority\", b\"localhost\"),\n<18> (b\":path\", b\"/\"),\n<19> (b\"x-foo\", b\"client\"),\n<20> ],\n<21> )\n<22> h3_client.send_data(stream_id=stream_id, data=b\"hello\", end_stream=True)\n<23> \n<24> # receive request\n<25> events = h3_transfer(quic_client, h3_server)\n<26> self.assertEqual(\n<27> events,\n<28> [\n<29> RequestReceived(\n<30> headers=[\n<31> (b\":method\", b\"GET\"),\n<32> (b\":scheme\", b\"https\"),\n<33> (b\":authority\", b\"localhost\"),\n<34> (b\":path\", b\"/\"),\n<35> (b\"x-foo\", b\"client\"),\n<36> ],\n<37> stream_id=stream_id,\n<38> stream_ended=False,\n<39> ),\n<40> DataReceived(data=b\"h\", stream_id=0, stream_ended=False),\n<41> DataReceived(data=b\"e\", stream_id=0, stream_ended=False),\n<42> DataReceived(data=b\"l\", stream"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_fragmented_frame(self):\n # offset: 1\n DataReceived(data=b\"l\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"o\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"\", stream_id=0, stream_ended=True),\n ],\n )\n \n # send push promise\n push_stream_id = h3_server.push_promise(\n stream_id=stream_id,\n headers=[\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/app.txt\"),\n ],\n )\n self.assertEqual(push_stream_id, 15)\n \n # send response\n h3_server.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n ],\n end_stream=False,\n )\n h3_server.send_data(stream_id=stream_id, data=b\"html\", end_stream=True)\n \n #  fulfill push promise\n h3_server.send_headers(\n stream_id=push_stream_id,\n headers=[(b\":status\", b\"200\"), (b\"content-type\", b\"text/plain\")],\n end_stream=False,\n )\n h3_server.send_data(stream_id=push_stream_id, data=b\"text\", end_stream=True)\n \n # receive push promise / reponse\n events = h3_transfer(quic_server, h3_client)\n self.assertEqual(\n events,\n [\n PushPromiseReceived(\n headers=[\n (b\":method\", b\"GET\"),\n (b\":\n===========below chunk 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_fragmented_frame(self):\n # offset: 2\n \n [\n PushPromiseReceived(\n headers=[\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/app.txt\"),\n ],\n push_id=0,\n stream_id=stream_id,\n ),\n ResponseReceived(\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n ],\n stream_id=0,\n stream_ended=False,\n ),\n DataReceived(data=b\"h\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"t\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"m\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"l\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"\", stream_id=0, stream_ended=True),\n ResponseReceived(\n headers=[(b\":status\", b\"200\"), (b\"content-type\", b\"text/plain\")],\n stream_id=15,\n stream_ended=False,\n push_id=0,\n ),\n DataReceived(data=b\"text\", stream_id=15, stream_ended=False, push_id=0),\n ],\n )\n \n \n===========unchanged ref 0===========\n at: aioquic.h3.connection\n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n push_promise(stream_id: int, headers: Headers) -> int\n \n send_data(stream_id: int, data: bytes, end_stream: bool) -> None\n \n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.events\n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n PushPromiseReceived(headers: Headers, push_id: int, stream_id: int)\n \n at: aioquic.h3.events.PushPromiseReceived\n headers: Headers\n \n push_id: int\n \n stream_id: int\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: tests.test_connection\n client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_options={}, server_patch=lambda x: None, transport_options={})\n \n at: tests.test_h3\n h3_transfer(quic_sender, h3_receiver)\n \n \n===========unchanged ref 1===========\n at: tests.test_h3.FakeQuicConnection\n get_next_available_stream_id(is_unidirectional=False)\n \n at: tests.test_h3.H3ConnectionTest.test_request_fragmented_frame\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n \n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + "}}},{"rowIdx":3429,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_blocked_stream"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_blocked_stream(self):\n <0> quic_client = FakeQuicConnection(\n <1> configuration=QuicConfiguration(is_client=True)\n <2> )\n <3> h3_client = H3Connection(quic_client)\n <4> \n <5> h3_client.handle_event(\n <6> StreamDataReceived(\n <7> stream_id=3,\n <8> data=binascii.unhexlify(\n <9> \"0004170150000680020000074064091040bcc0000000faceb00c\"\n<10> ),\n<11> end_stream=False,\n<12> )\n<13> )\n<14> h3_client.handle_event(\n<15> StreamDataReceived(stream_id=7, data=b\"\\x02\", end_stream=False)\n<16> )\n<17> h3_client.handle_event(\n<18> StreamDataReceived(stream_id=11, data=b\"\\x03\", end_stream=False)\n<19> )\n<20> h3_client.handle_event(\n<21> StreamDataReceived(\n<22> stream_id=0, data=binascii.unhexlify(\"01040280d910\"), end_stream=False\n<23> )\n<24> )\n<25> h3_client.handle_event(\n<26> StreamDataReceived(\n<27> stream_id=0,\n<28> data=binascii.unhexlify(\n<29> \"00408d796f752072656163686564206d766673742e6e65742c20726561636820\"\n<30> \"746865202f6563686f20656e64706f696e7420666f7220616e206563686f2072\"\n<31> \"6573706f6e7365207175657279202f3c6e756d6265723e20656e64706f696e74\"\n<32> \"7320666f722061207661726961626c6520736"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_blocked_stream(self):\n # offset: 1\n \"6974682072616e646f6d206279746573\"\n ),\n end_stream=True,\n )\n )\n self.assertEqual(\n h3_client.handle_event(\n StreamDataReceived(\n stream_id=7,\n data=binascii.unhexlify(\n \"3fe101c696d07abe941094cb6d0a08017d403971966e32ca98b46f\"\n ),\n end_stream=False,\n )\n ),\n [\n ResponseReceived(\n headers=[\n (b\":status\", b\"200\"),\n (b\"date\", b\"Mon, 22 Jul 2019 06:33:33 GMT\"),\n ],\n stream_id=0,\n stream_ended=False,\n ),\n DataReceived(\n data=(\n b\"you reached mvfst.net, reach the /echo endpoint for an \"\n b\"echo response query / endpoints for a variable \"\n b\"size response with random bytes\"\n ),\n stream_id=0,\n stream_ended=True,\n ),\n ],\n )\n \n \n===========unchanged ref 0===========\n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[HttpEvent]\n \n at: aioquic.h3.events\n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: aioquic.quic.events.StreamDataReceived\n data: bytes\n \n end_stream: bool\n \n stream_id: int\n \n at: binascii\n unhexlify(hexstr: _Ascii, /) -> bytes\n \n at: tests.test_connection\n client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_options={}, server_patch=lambda x: None, transport_options={})\n \n at: tests.test_h3.H3ConnectionTest.test_blocked_stream\n h3_client = H3Connection(quic_client)\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_headers_only(self):\n with client_and_server(\n client_options={\"alpn_protocols\": [\"h3-22\"]},\n server_options={\"alpn_protocols\": [\"h3-22\"]},\n ) as (quic_client, quic_server):\n h3_client = H3Connection(quic_client)\n h3_server = H3Connection(quic_server)\n \n # send request\n stream_id = quic_client.get_next_available_stream_id()\n h3_client.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":method\", b\"HEAD\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/\"),\n (b\"x-foo\", b\"client\"),\n ],\n end_stream=True,\n )\n \n # receive request\n events = h3_transfer(quic_client, h3_server)\n self.assertEqual(\n events,\n [\n + HeadersReceived(\n - RequestReceived(\n headers=[\n (b\":method\", b\"HEAD\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/\"),\n (b\"x-foo\", b\"client\"),\n ],\n stream_id=stream_id,\n stream_ended=True,\n )\n ],\n )\n \n # send response\n h3_server.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n (b\"x-foo\", b\"server\"),\n ],\n end_stream=True,\n )\n \n # receive response\n events = h3_transfer(\n===========changed ref 2===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_headers_only(self):\n # offset: 1\n \n ],\n end_stream=True,\n )\n \n # receive response\n events = h3_transfer(quic_server, h3_client)\n self.assertEqual(len(events), 1)\n \n self.assertTrue(\n events,\n [\n + HeadersReceived(\n - ResponseReceived(\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n (b\"x-foo\", b\"server\"),\n ],\n stream_id=stream_id,\n stream_ended=True,\n )\n ],\n )\n \n===========changed ref 3===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 4===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n===========changed ref 5===========\n # module: examples.http3_client\n class WebSocket:\n def http_event_received(self, event: HttpEvent):\n + if isinstance(event, HeadersReceived):\n - if isinstance(event, ResponseReceived):\n for header, value in event.headers:\n if header == b\"sec-websocket-protocol\":\n self.subprotocol = value.decode(\"utf8\")\n elif isinstance(event, DataReceived):\n self.websocket.receive_data(event.data)\n \n for ws_event in self.websocket.events():\n self.websocket_event_received(ws_event)\n \n===========changed ref 6===========\n # module: aioquic.h3.events\n - @dataclass\n - class ResponseReceived(HttpEvent):\n - \"\"\"\n - The ResponseReceived event is fired whenever response headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The response headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n - push_id: Optional[int] = None\n - \"The Push ID or `None` if this is not a push.\"\n - "}}},{"rowIdx":3430,"cells":{"path":{"kind":"string","value":"examples.http3_server/HttpServerProtocol.http_event_received"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":" <0>: if isinstance(event, HeadersReceived) and event.stream_id not in self._handlers:\n if isinstance(event, RequestReceived) and event.stream_id not in self._handlers:\n"},"main_code":{"kind":"string","value":" # module: examples.http3_server\n class HttpServerProtocol(QuicConnectionProtocol):\n def http_event_received(self, event: HttpEvent) -> None:\n <0> if isinstance(event, RequestReceived) and event.stream_id not in self._handlers:\n <1> headers = []\n <2> http_version = \"0.9\" if isinstance(self._http, H0Connection) else \"3\"\n <3> raw_path = b\"\"\n <4> method = \"\"\n <5> protocol = None\n <6> for header, value in event.headers:\n <7> if header == b\":authority\":\n <8> headers.append((b\"host\", value))\n <9> elif header == b\":method\":\n<10> method = value.decode(\"utf8\")\n<11> elif header == b\":path\":\n<12> raw_path = value\n<13> elif header == b\":protocol\":\n<14> protocol = value.decode(\"utf8\")\n<15> elif header and not header.startswith(b\":\"):\n<16> headers.append((header, value))\n<17> \n<18> if b\"?\" in raw_path:\n<19> path_bytes, query_string = raw_path.split(b\"?\", maxsplit=1)\n<20> else:\n<21> path_bytes, query_string = raw_path, b\"\"\n<22> path = path_bytes.decode(\"utf8\")\n<23> \n<24> handler: Handler\n<25> if method == \"CONNECT\" and protocol == \"websocket\":\n<26> subprotocols: List[str] = []\n<27> for header, value in event.headers:\n<28> if header == b\"sec-websocket-protocol\":\n<29> subprotocols = [\n<30> x.strip() for x in value.decode(\"utf8\").split(\",\")\n<31> ]\n<32> scope = {\n<33> \"headers\": headers,\n<34> \"http_version\": http_version,\n<35> \"method\": method,\n<36> \"path\": path,\n<37> \"query_string\": query_string,\n<38> \"raw_path\": raw_path,\n<39> \"root_path\": \"\",\n<40> \"scheme\": \"wss\",\n<41> \"subprotocols\": subprotocols,\n<42> \"type\": \"websocket\","},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: examples.http3_server\n class HttpServerProtocol(QuicConnectionProtocol):\n def http_event_received(self, event: HttpEvent) -> None:\n # offset: 1\n handler = WebSocketHandler(\n connection=self._http,\n scope=scope,\n stream_id=event.stream_id,\n transmit=self.transmit,\n )\n else:\n scope = {\n \"headers\": headers,\n \"http_version\": http_version,\n \"method\": method,\n \"path\": path,\n \"query_string\": query_string,\n \"raw_path\": raw_path,\n \"root_path\": \"\",\n \"scheme\": \"https\",\n \"type\": \"http\",\n }\n handler = HttpRequestHandler(\n connection=self._http,\n scope=scope,\n stream_ended=event.stream_ended,\n stream_id=event.stream_id,\n transmit=self.transmit,\n )\n self._handlers[event.stream_id] = handler\n asyncio.ensure_future(handler.run_asgi(application))\n elif isinstance(event, DataReceived) and event.stream_id in self._handlers:\n handler = self._handlers[event.stream_id]\n handler.http_event_received(event)\n \n \n===========unchanged ref 0===========\n at: aioquic.asyncio.protocol.QuicConnectionProtocol\n transmit() -> None\n \n at: aioquic.h0.connection\n H0Connection(quic: QuicConnection)\n \n at: aioquic.h3.events\n HttpEvent()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: asyncio.tasks\n ensure_future(coro_or_future: _FutureT[_T], *, loop: Optional[AbstractEventLoop]=...) -> Future[_T]\n \n at: examples.http3_server\n HttpRequestHandler(*, connection: HttpConnection, scope: Dict, stream_ended: bool, stream_id: int, transmit: Callable[[], None])\n \n WebSocketHandler(*, connection: HttpConnection, scope: Dict, stream_id: int, transmit: Callable[[], None])\n \n Handler = Union[HttpRequestHandler, WebSocketHandler]\n \n application = getattr(module, attr_str)\n \n at: examples.http3_server.HttpServerProtocol.__init__\n self._handlers: Dict[int, Handler] = {}\n \n self._http: Optional[HttpConnection] = None\n \n at: examples.http3_server.HttpServerProtocol.quic_event_received\n self._http = H3Connection(self._quic)\n self._http = H0Connection(self._quic)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 1===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 2===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n===========changed ref 3===========\n # module: examples.http3_client\n class WebSocket:\n def http_event_received(self, event: HttpEvent):\n + if isinstance(event, HeadersReceived):\n - if isinstance(event, ResponseReceived):\n for header, value in event.headers:\n if header == b\"sec-websocket-protocol\":\n self.subprotocol = value.decode(\"utf8\")\n elif isinstance(event, DataReceived):\n self.websocket.receive_data(event.data)\n \n for ws_event in self.websocket.events():\n self.websocket_event_received(ws_event)\n \n===========changed ref 4===========\n # module: aioquic.h3.events\n - @dataclass\n - class ResponseReceived(HttpEvent):\n - \"\"\"\n - The ResponseReceived event is fired whenever response headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The response headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n - push_id: Optional[int] = None\n - \"The Push ID or `None` if this is not a push.\"\n - \n===========changed ref 5===========\n # module: examples.interop\n def test_http_0(server: Server, configuration: QuicConfiguration):\n if server.path is None:\n return\n \n configuration.alpn_protocols = [\"hq-22\"]\n async with connect(\n server.host,\n server.port,\n configuration=configuration,\n create_protocol=HttpClient,\n ) as protocol:\n protocol = cast(HttpClient, protocol)\n \n # perform HTTP request\n events = await protocol.get(server.host, server.path)\n + if events and isinstance(events[0], HeadersReceived):\n - if events and isinstance(events[0], ResponseReceived):\n server.result |= Result.D\n \n===========changed ref 6===========\n # module: examples.interop\n def test_http_3(server: Server, configuration: QuicConfiguration):\n if server.path is None:\n return\n \n configuration.alpn_protocols = [\"h3-22\"]\n async with connect(\n server.host,\n server.port,\n configuration=configuration,\n create_protocol=HttpClient,\n ) as protocol:\n protocol = cast(HttpClient, protocol)\n \n # perform HTTP request\n events = await protocol.get(server.host, server.path)\n + if events and isinstance(events[0], HeadersReceived):\n - if events and isinstance(events[0], ResponseReceived):\n server.result |= Result.D\n server.result |= Result.three\n \n===========changed ref 7===========\n # module: examples.http3_client\n class HttpClient(QuicConnectionProtocol):\n def http_event_received(self, event: HttpEvent):\n + if isinstance(event, (HeadersReceived, DataReceived)):\n - if isinstance(event, (ResponseReceived, DataReceived)):\n stream_id = event.stream_id\n if stream_id in self._request_events:\n # http\n self._request_events[event.stream_id].append(event)\n if event.stream_ended:\n request_waiter = self._request_waiter.pop(stream_id)\n request_waiter.set_result(self._request_events.pop(stream_id))\n \n elif stream_id in self._websockets:\n # websocket\n websocket = self._websockets[stream_id]\n websocket.http_event_received(event)\n \n else:\n # push\n print(event)\n "}}},{"rowIdx":3431,"cells":{"path":{"kind":"string","value":"examples.httpx_client/H3Dispatcher.send"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":"<31>: if isinstance(event, HeadersReceived):\n if isinstance(event, ResponseReceived):\n"},"main_code":{"kind":"string","value":" # module: examples.httpx_client\n class H3Dispatcher(QuicConnectionProtocol, AsyncDispatcher):\n def send(\n self,\n request: AsyncRequest,\n verify: VerifyTypes = None,\n cert: CertTypes = None,\n timeout: TimeoutTypes = None,\n ) -> AsyncResponse:\n <0> stream_id = self._quic.get_next_available_stream_id()\n <1> \n <2> # prepare request\n <3> self._http.send_headers(\n <4> stream_id=stream_id,\n <5> headers=[\n <6> (b\":method\", request.method.encode(\"utf8\")),\n <7> (b\":scheme\", request.url.scheme.encode(\"utf8\")),\n <8> (b\":authority\", str(request.url.authority).encode(\"utf8\")),\n <9> (b\":path\", request.url.full_path.encode(\"utf8\")),\n<10> ]\n<11> + [\n<12> (k.encode(\"utf8\"), v.encode(\"utf8\"))\n<13> for (k, v) in request.headers.items()\n<14> if k not in (\"connection\", \"host\")\n<15> ],\n<16> )\n<17> self._http.send_data(stream_id=stream_id, data=request.content, end_stream=True)\n<18> \n<19> # transmit request\n<20> waiter = self._loop.create_future()\n<21> self._request_events[stream_id] = deque()\n<22> self._request_waiter[stream_id] = waiter\n<23> self.transmit()\n<24> \n<25> # process response\n<26> events = await asyncio.shield(waiter)\n<27> content = b\"\"\n<28> headers = []\n<29> status_code = None\n<30> for event in events:\n<31> if isinstance(event, ResponseReceived):\n<32> for header, value in event.headers:\n<33> if header == b\":status\":\n<34> status_code = int(value.decode(\"ascii\"))\n<35> elif header[0:1] != b\":\":\n<36> headers.append((header.decode(\"utf8\"), value.decode(\"utf8\")))\n<37> elif"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: examples.httpx_client\n class H3Dispatcher(QuicConnectionProtocol, AsyncDispatcher):\n def send(\n self,\n request: AsyncRequest,\n verify: VerifyTypes = None,\n cert: CertTypes = None,\n timeout: TimeoutTypes = None,\n ) -> AsyncResponse:\n # offset: 1\n content += event.data\n \n return AsyncResponse(\n status_code=status_code,\n protocol=\"HTTP/3\",\n headers=headers,\n content=content,\n # on_close=on_close,\n request=request,\n )\n \n \n===========unchanged ref 0===========\n at: aioquic.asyncio.protocol.QuicConnectionProtocol\n transmit() -> None\n \n at: aioquic.asyncio.protocol.QuicConnectionProtocol.__init__\n self._loop = loop\n \n self._quic = quic\n \n at: aioquic.h3.connection.H3Connection\n send_data(stream_id: int, data: bytes, end_stream: bool) -> None\n \n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.events\n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.quic.connection.QuicConnection\n get_next_available_stream_id(is_unidirectional=False) -> int\n \n at: asyncio.events.AbstractEventLoop\n create_future() -> Future[Any]\n \n at: asyncio.tasks\n shield(arg: _FutureT[_T], *, loop: Optional[AbstractEventLoop]=...) -> Future[_T]\n \n at: collections\n deque(iterable: Iterable[_T]=..., maxlen: Optional[int]=...)\n \n at: examples.httpx_client.H3Dispatcher.__init__\n self._http = H3Connection(self._quic)\n \n self._request_events: Dict[int, Deque[HttpEvent]] = {}\n \n self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {}\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 1===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 2===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n===========changed ref 3===========\n # module: examples.http3_client\n class WebSocket:\n def http_event_received(self, event: HttpEvent):\n + if isinstance(event, HeadersReceived):\n - if isinstance(event, ResponseReceived):\n for header, value in event.headers:\n if header == b\"sec-websocket-protocol\":\n self.subprotocol = value.decode(\"utf8\")\n elif isinstance(event, DataReceived):\n self.websocket.receive_data(event.data)\n \n for ws_event in self.websocket.events():\n self.websocket_event_received(ws_event)\n \n===========changed ref 4===========\n # module: aioquic.h3.events\n - @dataclass\n - class ResponseReceived(HttpEvent):\n - \"\"\"\n - The ResponseReceived event is fired whenever response headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The response headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n - push_id: Optional[int] = None\n - \"The Push ID or `None` if this is not a push.\"\n - \n===========changed ref 5===========\n # module: examples.interop\n def test_http_0(server: Server, configuration: QuicConfiguration):\n if server.path is None:\n return\n \n configuration.alpn_protocols = [\"hq-22\"]\n async with connect(\n server.host,\n server.port,\n configuration=configuration,\n create_protocol=HttpClient,\n ) as protocol:\n protocol = cast(HttpClient, protocol)\n \n # perform HTTP request\n events = await protocol.get(server.host, server.path)\n + if events and isinstance(events[0], HeadersReceived):\n - if events and isinstance(events[0], ResponseReceived):\n server.result |= Result.D\n \n===========changed ref 6===========\n # module: examples.interop\n def test_http_3(server: Server, configuration: QuicConfiguration):\n if server.path is None:\n return\n \n configuration.alpn_protocols = [\"h3-22\"]\n async with connect(\n server.host,\n server.port,\n configuration=configuration,\n create_protocol=HttpClient,\n ) as protocol:\n protocol = cast(HttpClient, protocol)\n \n # perform HTTP request\n events = await protocol.get(server.host, server.path)\n + if events and isinstance(events[0], HeadersReceived):\n - if events and isinstance(events[0], ResponseReceived):\n server.result |= Result.D\n server.result |= Result.three\n \n===========changed ref 7===========\n # module: examples.http3_client\n class HttpClient(QuicConnectionProtocol):\n def http_event_received(self, event: HttpEvent):\n + if isinstance(event, (HeadersReceived, DataReceived)):\n - if isinstance(event, (ResponseReceived, DataReceived)):\n stream_id = event.stream_id\n if stream_id in self._request_events:\n # http\n self._request_events[event.stream_id].append(event)\n if event.stream_ended:\n request_waiter = self._request_waiter.pop(stream_id)\n request_waiter.set_result(self._request_events.pop(stream_id))\n \n elif stream_id in self._websockets:\n # websocket\n websocket = self._websockets[stream_id]\n websocket.http_event_received(event)\n \n else:\n # push\n print(event)\n "}}},{"rowIdx":3432,"cells":{"path":{"kind":"string","value":"examples.httpx_client/H3Dispatcher.http_event_received"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3"},"commit_message":{"kind":"string","value":"[http3] merge RequestReceived and ResponseReceived into HeadersReceived"},"ground_truth":{"kind":"string","value":" <0>: if isinstance(event, (HeadersReceived, DataReceived)):\n if isinstance(event, (ResponseReceived, DataReceived)):\n"},"main_code":{"kind":"string","value":" # module: examples.httpx_client\n class H3Dispatcher(QuicConnectionProtocol, AsyncDispatcher):\n def http_event_received(self, event: HttpEvent):\n <0> if isinstance(event, (ResponseReceived, DataReceived)):\n <1> stream_id = event.stream_id\n <2> if stream_id in self._request_events:\n <3> self._request_events[event.stream_id].append(event)\n <4> if event.stream_ended:\n <5> request_waiter = self._request_waiter.pop(stream_id)\n <6> request_waiter.set_result(self._request_events.pop(stream_id))\n <7> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: _asyncio.Future\n set_result(result, /)\n \n at: aioquic.h3.events\n HttpEvent()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: asyncio.futures.Future\n _state = _PENDING\n \n _result = None\n \n _exception = None\n \n _loop = None\n \n _source_traceback = None\n \n _cancel_message = None\n \n _cancelled_exc = None\n \n _asyncio_future_blocking = False\n \n __log_traceback = False\n \n __class_getitem__ = classmethod(GenericAlias)\n \n set_result(result: _T, /) -> None\n \n __iter__ = __await__ # make compatible with 'yield from'.\n \n at: collections.deque\n append(x: _T) -> None\n \n at: examples.httpx_client.H3Dispatcher.__init__\n self._request_events: Dict[int, Deque[HttpEvent]] = {}\n \n self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {}\n \n at: typing.MutableMapping\n pop(key: _KT) -> _VT\n pop(key: _KT, default: Union[_VT, _T]=...) -> Union[_VT, _T]\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + @dataclass\n + class HeadersReceived(HttpEvent):\n + \"\"\"\n + The HeadersReceived event is fired whenever headers are received.\n + \"\"\"\n + \n + headers: Headers\n + \"The headers.\"\n + \n + stream_id: int\n + \"The ID of the stream the headers were received for.\"\n + \n + stream_ended: bool\n + \"Whether the STREAM frame had the FIN bit set.\"\n + \n + push_id: Optional[int] = None\n + \"The Push ID or `None` if this is not a push.\"\n + \n===========changed ref 1===========\n # module: examples.httpx_client\n class H3Dispatcher(QuicConnectionProtocol, AsyncDispatcher):\n def send(\n self,\n request: AsyncRequest,\n verify: VerifyTypes = None,\n cert: CertTypes = None,\n timeout: TimeoutTypes = None,\n ) -> AsyncResponse:\n stream_id = self._quic.get_next_available_stream_id()\n \n # prepare request\n self._http.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":method\", request.method.encode(\"utf8\")),\n (b\":scheme\", request.url.scheme.encode(\"utf8\")),\n (b\":authority\", str(request.url.authority).encode(\"utf8\")),\n (b\":path\", request.url.full_path.encode(\"utf8\")),\n ]\n + [\n (k.encode(\"utf8\"), v.encode(\"utf8\"))\n for (k, v) in request.headers.items()\n if k not in (\"connection\", \"host\")\n ],\n )\n self._http.send_data(stream_id=stream_id, data=request.content, end_stream=True)\n \n # transmit request\n waiter = self._loop.create_future()\n self._request_events[stream_id] = deque()\n self._request_waiter[stream_id] = waiter\n self.transmit()\n \n # process response\n events = await asyncio.shield(waiter)\n content = b\"\"\n headers = []\n status_code = None\n for event in events:\n + if isinstance(event, HeadersReceived):\n - if isinstance(event, ResponseReceived):\n for header, value in event.headers:\n if header == b\":status\":\n status_code = int(value.decode(\"ascii\"))\n elif header[0:1] != b\":\":\n headers.append((header.decode(\"utf8\"), value.decode(\"utf8\")))\n elif isinstance(event, DataReceived):\n content += event.data\n \n return AsyncResponse(\n status_code\n===========changed ref 2===========\n # module: examples.httpx_client\n class H3Dispatcher(QuicConnectionProtocol, AsyncDispatcher):\n def send(\n self,\n request: AsyncRequest,\n verify: VerifyTypes = None,\n cert: CertTypes = None,\n timeout: TimeoutTypes = None,\n ) -> AsyncResponse:\n # offset: 1\n )))\n elif isinstance(event, DataReceived):\n content += event.data\n \n return AsyncResponse(\n status_code=status_code,\n protocol=\"HTTP/3\",\n headers=headers,\n content=content,\n # on_close=on_close,\n request=request,\n )\n \n===========changed ref 3===========\n # module: aioquic.h3.events\n + # backwards compatibility\n \n + RequestReceived = ResponseReceived = HeadersReceived\n \n===========changed ref 4===========\n # module: aioquic.h3.events\n - @dataclass\n - class RequestReceived(HttpEvent):\n - \"\"\"\n - The RequestReceived event is fired whenever request headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The request headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n===========changed ref 5===========\n # module: examples.http3_client\n class WebSocket:\n def http_event_received(self, event: HttpEvent):\n + if isinstance(event, HeadersReceived):\n - if isinstance(event, ResponseReceived):\n for header, value in event.headers:\n if header == b\"sec-websocket-protocol\":\n self.subprotocol = value.decode(\"utf8\")\n elif isinstance(event, DataReceived):\n self.websocket.receive_data(event.data)\n \n for ws_event in self.websocket.events():\n self.websocket_event_received(ws_event)\n \n===========changed ref 6===========\n # module: aioquic.h3.events\n - @dataclass\n - class ResponseReceived(HttpEvent):\n - \"\"\"\n - The ResponseReceived event is fired whenever response headers are received.\n - \"\"\"\n - \n - headers: Headers\n - \"The response headers.\"\n - \n - stream_id: int\n - \"The ID of the stream the headers were received for.\"\n - \n - stream_ended: bool\n - \"Whether the STREAM frame had the FIN bit set.\"\n - \n - push_id: Optional[int] = None\n - \"The Push ID or `None` if this is not a push.\"\n - \n===========changed ref 7===========\n # module: examples.interop\n def test_http_0(server: Server, configuration: QuicConfiguration):\n if server.path is None:\n return\n \n configuration.alpn_protocols = [\"hq-22\"]\n async with connect(\n server.host,\n server.port,\n configuration=configuration,\n create_protocol=HttpClient,\n ) as protocol:\n protocol = cast(HttpClient, protocol)\n \n # perform HTTP request\n events = await protocol.get(server.host, server.path)\n + if events and isinstance(events[0], HeadersReceived):\n - if events and isinstance(events[0], ResponseReceived):\n server.result |= Result.D\n \n===========changed ref 8===========\n # module: examples.interop\n def test_http_3(server: Server, configuration: QuicConfiguration):\n if server.path is None:\n return\n \n configuration.alpn_protocols = [\"h3-22\"]\n async with connect(\n server.host,\n server.port,\n configuration=configuration,\n create_protocol=HttpClient,\n ) as protocol:\n protocol = cast(HttpClient, protocol)\n \n # perform HTTP request\n events = await protocol.get(server.host, server.path)\n + if events and isinstance(events[0], HeadersReceived):\n - if events and isinstance(events[0], ResponseReceived):\n server.result |= Result.D\n server.result |= Result.three\n "}}},{"rowIdx":3433,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_request_fragmented_frame"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"993790505b6e9913903a1c5190eb2a43f917d408"},"commit_message":{"kind":"string","value":"[http3] rename `push_promise` to `send_push_promise`"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_fragmented_frame(self):\n <0> quic_client = FakeQuicConnection(\n <1> configuration=QuicConfiguration(is_client=True)\n <2> )\n <3> quic_server = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=False)\n <5> )\n <6> \n <7> h3_client = H3Connection(quic_client)\n <8> h3_server = H3Connection(quic_server)\n <9> \n<10> # send request\n<11> stream_id = quic_client.get_next_available_stream_id()\n<12> h3_client.send_headers(\n<13> stream_id=stream_id,\n<14> headers=[\n<15> (b\":method\", b\"GET\"),\n<16> (b\":scheme\", b\"https\"),\n<17> (b\":authority\", b\"localhost\"),\n<18> (b\":path\", b\"/\"),\n<19> (b\"x-foo\", b\"client\"),\n<20> ],\n<21> )\n<22> h3_client.send_data(stream_id=stream_id, data=b\"hello\", end_stream=True)\n<23> \n<24> # receive request\n<25> events = h3_transfer(quic_client, h3_server)\n<26> self.assertEqual(\n<27> events,\n<28> [\n<29> HeadersReceived(\n<30> headers=[\n<31> (b\":method\", b\"GET\"),\n<32> (b\":scheme\", b\"https\"),\n<33> (b\":authority\", b\"localhost\"),\n<34> (b\":path\", b\"/\"),\n<35> (b\"x-foo\", b\"client\"),\n<36> ],\n<37> stream_id=stream_id,\n<38> stream_ended=False,\n<39> ),\n<40> DataReceived(data=b\"h\", stream_id=0, stream_ended=False),\n<41> DataReceived(data=b\"e\", stream_id=0, stream_ended=False),\n<42> DataReceived(data=b\"l\", stream"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_fragmented_frame(self):\n # offset: 1\n DataReceived(data=b\"l\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"o\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"\", stream_id=0, stream_ended=True),\n ],\n )\n \n # send push promise\n push_stream_id = h3_server.push_promise(\n stream_id=stream_id,\n headers=[\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/app.txt\"),\n ],\n )\n self.assertEqual(push_stream_id, 15)\n \n # send response\n h3_server.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n ],\n end_stream=False,\n )\n h3_server.send_data(stream_id=stream_id, data=b\"html\", end_stream=True)\n \n #  fulfill push promise\n h3_server.send_headers(\n stream_id=push_stream_id,\n headers=[(b\":status\", b\"200\"), (b\"content-type\", b\"text/plain\")],\n end_stream=False,\n )\n h3_server.send_data(stream_id=push_stream_id, data=b\"text\", end_stream=True)\n \n # receive push promise / reponse\n events = h3_transfer(quic_server, h3_client)\n self.assertEqual(\n events,\n [\n PushPromiseReceived(\n headers=[\n (b\":method\", b\"GET\"),\n (b\":\n===========below chunk 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_fragmented_frame(self):\n # offset: 2\n \n [\n PushPromiseReceived(\n headers=[\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/app.txt\"),\n ],\n push_id=0,\n stream_id=stream_id,\n ),\n HeadersReceived(\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n ],\n stream_id=0,\n stream_ended=False,\n ),\n DataReceived(data=b\"h\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"t\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"m\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"l\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"\", stream_id=0, stream_ended=True),\n HeadersReceived(\n headers=[(b\":status\", b\"200\"), (b\"content-type\", b\"text/plain\")],\n stream_id=15,\n stream_ended=False,\n push_id=0,\n ),\n DataReceived(data=b\"text\", stream_id=15, stream_ended=False, push_id=0),\n ],\n )\n \n \n===========unchanged ref 0===========\n at: aioquic.h3.connection\n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n send_push_promise(stream_id: int, headers: Headers) -> int\n \n send_data(stream_id: int, data: bytes, end_stream: bool) -> None\n \n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.events\n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n PushPromiseReceived(headers: Headers, push_id: int, stream_id: int)\n \n at: aioquic.h3.events.DataReceived\n data: bytes\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.HeadersReceived\n headers: Headers\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.PushPromiseReceived\n headers: Headers\n \n push_id: int\n \n stream_id: int\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n \n===========unchanged ref 1===========\n at: aioquic.quic.configuration.QuicConfiguration\n alpn_protocols: Optional[List[str]] = None\n \n certificate: Any = None\n \n connection_id_length: int = 8\n \n idle_timeout: float = 60.0\n \n is_client: bool = True\n \n private_key: Any = None\n \n quic_logger: Optional[QuicLogger] = None\n \n secrets_log_file: TextIO = None\n \n server_name: Optional[str] = None\n \n session_ticket: Optional[SessionTicket] = None\n \n supported_versions: List[int] = field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n )\n \n at: tests.test_h3\n h3_transfer(quic_sender, h3_receiver)\n \n FakeQuicConnection(configuration)\n \n at: tests.test_h3.FakeQuicConnection\n get_next_available_stream_id(is_unidirectional=False)\n \n at: tests.test_h3.H3ConnectionTest\n maxDiff = None\n \n at: unittest.case.TestCase\n failureException: Type[BaseException]\n \n longMessage: bool\n \n maxDiff: Optional[int]\n \n _testMethodName: str\n \n _testMethodDoc: str\n \n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n "}}},{"rowIdx":3434,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_stream_data_uni"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"e6ec053e4c5be31b8f91b425fc60a562a8d3a912"},"commit_message":{"kind":"string","value":"[http3] avoid endless loop for unknown uni stream types"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[HttpEvent]:\n <0> http_events: List[HttpEvent] = []\n <1> \n <2> stream = self._stream[stream_id]\n <3> stream.buffer += data\n <4> if stream_ended:\n <5> stream.ended = True\n <6> \n <7> buf = Buffer(data=stream.buffer)\n <8> consumed = 0\n <9> unblocked_streams: Set[int] = set()\n<10> \n<11> while not buf.eof():\n<12> # fetch stream type for unidirectional streams\n<13> if stream.stream_type is None:\n<14> try:\n<15> stream.stream_type = buf.pull_uint_var()\n<16> except BufferReadError:\n<17> break\n<18> consumed = buf.tell()\n<19> \n<20> # check unicity\n<21> if stream.stream_type == StreamType.CONTROL:\n<22> assert self._peer_control_stream_id is None\n<23> self._peer_control_stream_id = stream_id\n<24> elif stream.stream_type == StreamType.QPACK_DECODER:\n<25> assert self._peer_decoder_stream_id is None\n<26> self._peer_decoder_stream_id = stream_id\n<27> elif stream.stream_type == StreamType.QPACK_ENCODER:\n<28> assert self._peer_encoder_stream_id is None\n<29> self._peer_encoder_stream_id = stream_id\n<30> \n<31> if stream.stream_type == StreamType.CONTROL:\n<32> # fetch next frame\n<33> try:\n<34> frame_type = buf.pull_uint_var()\n<35> frame_length = buf.pull_uint_var()\n<36> frame_data = buf.pull_bytes(frame_length)\n<37> except BufferReadError:\n<38> break\n<39> consumed = buf.tell()\n<40> \n<41> self._handle_control_frame(frame_type, frame_data)\n<42> elif stream.stream_"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[HttpEvent]:\n # offset: 1\n # fetch push id\n if stream.push_id is None:\n try:\n stream.push_id = buf.pull_uint_var()\n except BufferReadError:\n break\n consumed = buf.tell()\n \n # fetch next frame\n try:\n frame_type = buf.pull_uint_var()\n frame_length = buf.pull_uint_var()\n frame_data = buf.pull_bytes(frame_length)\n except BufferReadError:\n break\n consumed = buf.tell()\n \n http_events.extend(\n self._handle_push_frame(\n frame_type=frame_type,\n frame_data=frame_data,\n push_id=stream.push_id,\n stream_id=stream_id,\n stream_ended=stream.ended and buf.eof(),\n )\n )\n elif stream.stream_type == StreamType.QPACK_DECODER:\n # feed unframed data to decoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n self._encoder.feed_decoder(data)\n elif stream.stream_type == StreamType.QPACK_ENCODER:\n # feed unframed data to encoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n unblocked_streams.update(self._decoder.feed_encoder(data))\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n # process unblocked streams\n for stream_id in unblocked_streams:\n stream = self._stream[stream_id]\n decoder, headers = self._decoder.resume_header(stream_id)\n stream.blocked = False\n http_events.append(\n HeadersReceived\n===========below chunk 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[HttpEvent]:\n # offset: 2\n ._decoder.resume_header(stream_id)\n stream.blocked = False\n http_events.append(\n HeadersReceived(\n headers=headers,\n stream_id=stream_id,\n stream_ended=stream.ended and not stream.buffer,\n )\n )\n http_events.extend(\n self._receive_stream_data_bidi(stream_id, b\"\", stream.ended)\n )\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n at: aioquic.h3.connection.H3Connection\n _handle_control_frame(frame_type: int, frame_data: bytes) -> None\n \n _handle_push_frame(frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[HttpEvent]\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._encoder = Encoder()\n \n self._stream: Dict[int, H3Stream] = {}\n \n self._peer_control_stream_id: Optional[int] = None\n \n self._peer_decoder_stream_id: Optional[int] = None\n \n self._peer_encoder_stream_id: Optional[int] = None\n \n at: aioquic.h3.connection.H3Stream.__init__\n self.buffer = b\"\"\n \n self.ended = False\n \n self.push_id: Optional[int] = None\n \n self.stream_type: Optional[int] = None\n \n at: aioquic.h3.events\n HttpEvent()\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n Set = _alias(set, 1, inst=False, name='Set')\n \n "}}},{"rowIdx":3435,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection.send_push_promise"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"1a83d7684ff29a526b9c961402070d82a0f60009"},"commit_message":{"kind":"string","value":"[examples] add ASGI bindings for server push"},"ground_truth":{"kind":"string","value":" <9>: if self._max_push_id is None or self._next_push_id >= self._max_push_id:\n assert self._max_push_id is not None and self._next_push_id < self._max_push_id\n<10>: raise NoAvailablePushIDError\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def send_push_promise(self, stream_id: int, headers: Headers) -> int:\n <0> \"\"\"\n <1> Send a push promise related to the specified stream.\n <2> \n <3> Returns the stream ID on which headers and data can be sent.\n <4> \n <5> :param stream_id: The stream ID on which to send the data.\n <6> :param headers: The HTTP request headers for this push.\n <7> \"\"\"\n <8> assert not self._is_client, \"Only servers may send a push promise.\"\n <9> assert self._max_push_id is not None and self._next_push_id < self._max_push_id\n<10> \n<11> # send push promise\n<12> push_id = self._next_push_id\n<13> self._next_push_id += 1\n<14> self._quic.send_stream_data(\n<15> stream_id,\n<16> encode_frame(\n<17> FrameType.PUSH_PROMISE,\n<18> encode_uint_var(push_id) + self._encode_headers(stream_id, headers),\n<19> ),\n<20> )\n<21> \n<22> #  create push stream\n<23> push_stream_id = self._create_uni_stream(StreamType.PUSH)\n<24> self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id))\n<25> \n<26> return push_stream_id\n<27> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n at: aioquic.h3.connection.H3Connection\n _create_uni_stream(stream_type: int) -> int\n \n _encode_headers(stream_id, headers: Headers) -> bytes\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._is_client = quic.configuration.is_client\n \n self._quic = quic\n \n self._max_push_id: Optional[int] = 8 if self._is_client else None\n \n self._next_push_id: int = 0\n \n at: aioquic.h3.connection.H3Connection._handle_control_frame\n self._max_push_id = parse_max_push_id(frame_data)\n \n at: aioquic.h3.events\n Headers = List[Tuple[bytes, bytes]]\n \n at: aioquic.h3.exceptions\n NoAvailablePushIDError(*args: object)\n \n at: aioquic.quic.connection.QuicConnection\n send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None\n \n \n===========changed ref 0===========\n + # module: aioquic.h3.exceptions\n + class NoAvailablePushIDError(H3Error):\n + \"\"\"\n + There are no available push IDs left.\n + \"\"\"\n + \n===========changed ref 1===========\n + # module: aioquic.h3.exceptions\n + \n + \n===========changed ref 2===========\n + # module: aioquic.h3.exceptions\n + class H3Error(Exception):\n + \"\"\"\n + Base class for HTTP/3 exceptions.\n + \"\"\"\n + "}}},{"rowIdx":3436,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._init_connection"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"1a83d7684ff29a526b9c961402070d82a0f60009"},"commit_message":{"kind":"string","value":"[examples] add ASGI bindings for server push"},"ground_truth":{"kind":"string","value":"<14>: if self._is_client and self._max_push_id is not None:\n if self._is_client:\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _init_connection(self) -> None:\n <0> # send our settings\n <1> self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL)\n <2> self._quic.send_stream_data(\n <3> self._local_control_stream_id,\n <4> encode_frame(\n <5> FrameType.SETTINGS,\n <6> encode_settings(\n <7> {\n <8> Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity,\n <9> Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams,\n<10> }\n<11> ),\n<12> ),\n<13> )\n<14> if self._is_client:\n<15> self._quic.send_stream_data(\n<16> self._local_control_stream_id,\n<17> encode_frame(FrameType.MAX_PUSH_ID, encode_uint_var(self._max_push_id)),\n<18> )\n<19> \n<20> # create encoder and decoder streams\n<21> self._local_encoder_stream_id = self._create_uni_stream(\n<22> StreamType.QPACK_ENCODER\n<23> )\n<24> self._local_decoder_stream_id = self._create_uni_stream(\n<25> StreamType.QPACK_DECODER\n<26> )\n<27> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n Setting(x: Union[str, bytes, bytearray], base: int)\n Setting(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n encode_settings(settings: Dict[int, int]) -> bytes\n \n at: aioquic.h3.connection.H3Connection\n _create_uni_stream(stream_type: int) -> int\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._max_table_capacity = 0x100\n \n self._blocked_streams = 0x10\n \n self._is_client = quic.configuration.is_client\n \n self._quic = quic\n \n self._max_push_id: Optional[int] = 8 if self._is_client else None\n \n self._local_control_stream_id: Optional[int] = None\n \n self._local_decoder_stream_id: Optional[int] = None\n \n self._local_encoder_stream_id: Optional[int] = None\n \n at: aioquic.h3.connection.H3Connection._handle_control_frame\n self._max_push_id = parse_max_push_id(frame_data)\n \n at: aioquic.h3.connection.H3Connection._handle_push_frame\n http_events: List[HttpEvent] = []\n \n \n===========unchanged ref 1===========\n at: aioquic.quic.connection.QuicConnection\n send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def send_push_promise(self, stream_id: int, headers: Headers) -> int:\n \"\"\"\n Send a push promise related to the specified stream.\n \n Returns the stream ID on which headers and data can be sent.\n \n :param stream_id: The stream ID on which to send the data.\n :param headers: The HTTP request headers for this push.\n \"\"\"\n assert not self._is_client, \"Only servers may send a push promise.\"\n + if self._max_push_id is None or self._next_push_id >= self._max_push_id:\n - assert self._max_push_id is not None and self._next_push_id < self._max_push_id\n + raise NoAvailablePushIDError\n \n # send push promise\n push_id = self._next_push_id\n self._next_push_id += 1\n self._quic.send_stream_data(\n stream_id,\n encode_frame(\n FrameType.PUSH_PROMISE,\n encode_uint_var(push_id) + self._encode_headers(stream_id, headers),\n ),\n )\n \n #  create push stream\n push_stream_id = self._create_uni_stream(StreamType.PUSH)\n self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id))\n \n return push_stream_id\n \n===========changed ref 1===========\n + # module: aioquic.h3.exceptions\n + \n + \n===========changed ref 2===========\n + # module: aioquic.h3.exceptions\n + class NoAvailablePushIDError(H3Error):\n + \"\"\"\n + There are no available push IDs left.\n + \"\"\"\n + \n===========changed ref 3===========\n + # module: aioquic.h3.exceptions\n + class H3Error(Exception):\n + \"\"\"\n + Base class for HTTP/3 exceptions.\n + \"\"\"\n + "}}},{"rowIdx":3437,"cells":{"path":{"kind":"string","value":"examples.demo/homepage"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"1a83d7684ff29a526b9c961402070d82a0f60009"},"commit_message":{"kind":"string","value":"[examples] add ASGI bindings for server push"},"ground_truth":{"kind":"string","value":" <3>: await request.send_push_promise(\"/style.css\")\n"},"main_code":{"kind":"string","value":" # module: examples.demo\n @app.route(\"/\")\n async def homepage(request):\n <0> \"\"\"\n <1> Simple homepage.\n <2> \"\"\"\n <3> return templates.TemplateResponse(\"index.html\", {\"request\": request})\n <4> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: examples.demo\n app = Starlette()\n \n \n===========changed ref 0===========\n + # module: aioquic.h3.exceptions\n + \n + \n===========changed ref 1===========\n + # module: aioquic.h3.exceptions\n + class NoAvailablePushIDError(H3Error):\n + \"\"\"\n + There are no available push IDs left.\n + \"\"\"\n + \n===========changed ref 2===========\n + # module: aioquic.h3.exceptions\n + class H3Error(Exception):\n + \"\"\"\n + Base class for HTTP/3 exceptions.\n + \"\"\"\n + \n===========changed ref 3===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _init_connection(self) -> None:\n # send our settings\n self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL)\n self._quic.send_stream_data(\n self._local_control_stream_id,\n encode_frame(\n FrameType.SETTINGS,\n encode_settings(\n {\n Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity,\n Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams,\n }\n ),\n ),\n )\n + if self._is_client and self._max_push_id is not None:\n - if self._is_client:\n self._quic.send_stream_data(\n self._local_control_stream_id,\n encode_frame(FrameType.MAX_PUSH_ID, encode_uint_var(self._max_push_id)),\n )\n \n # create encoder and decoder streams\n self._local_encoder_stream_id = self._create_uni_stream(\n StreamType.QPACK_ENCODER\n )\n self._local_decoder_stream_id = self._create_uni_stream(\n StreamType.QPACK_DECODER\n )\n \n===========changed ref 4===========\n # module: aioquic.h3.connection\n class H3Connection:\n def send_push_promise(self, stream_id: int, headers: Headers) -> int:\n \"\"\"\n Send a push promise related to the specified stream.\n \n Returns the stream ID on which headers and data can be sent.\n \n :param stream_id: The stream ID on which to send the data.\n :param headers: The HTTP request headers for this push.\n \"\"\"\n assert not self._is_client, \"Only servers may send a push promise.\"\n + if self._max_push_id is None or self._next_push_id >= self._max_push_id:\n - assert self._max_push_id is not None and self._next_push_id < self._max_push_id\n + raise NoAvailablePushIDError\n \n # send push promise\n push_id = self._next_push_id\n self._next_push_id += 1\n self._quic.send_stream_data(\n stream_id,\n encode_frame(\n FrameType.PUSH_PROMISE,\n encode_uint_var(push_id) + self._encode_headers(stream_id, headers),\n ),\n )\n \n #  create push stream\n push_stream_id = self._create_uni_stream(StreamType.PUSH)\n self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id))\n \n return push_stream_id\n "}}},{"rowIdx":3438,"cells":{"path":{"kind":"string","value":"examples.http3_server/HttpRequestHandler.__init__"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"1a83d7684ff29a526b9c961402070d82a0f60009"},"commit_message":{"kind":"string","value":"[examples] add ASGI bindings for server push"},"ground_truth":{"kind":"string","value":" <0>: self.authority = authority\n <1>: self.protocol = protocol\n"},"main_code":{"kind":"string","value":" # module: examples.http3_server\n class HttpRequestHandler:\n def __init__(\n self,\n *,\n + authority: bytes,\n connection: HttpConnection,\n + protocol: QuicConnectionProtocol,\n scope: Dict,\n stream_ended: bool,\n stream_id: int,\n transmit: Callable[[], None],\n ):\n <0> self.connection = connection\n <1> self.queue: asyncio.Queue[Dict] = asyncio.Queue()\n <2> self.scope = scope\n <3> self.stream_id = stream_id\n <4> self.transmit = transmit\n <5> \n <6> if stream_ended:\n <7> self.queue.put_nowait({\"type\": \"http.request\"})\n <8> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.asyncio.protocol\n QuicConnectionProtocol(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None)\n \n at: asyncio.queues\n Queue(maxsize: int=..., *, loop: Optional[AbstractEventLoop]=...)\n \n at: examples.http3_server\n HttpConnection = Union[H0Connection, H3Connection]\n \n at: typing\n Callable = _CallableType(collections.abc.Callable, 2)\n \n Dict = _alias(dict, 2, inst=False, name='Dict')\n \n \n===========changed ref 0===========\n + # module: aioquic.h3.exceptions\n + \n + \n===========changed ref 1===========\n + # module: aioquic.h3.exceptions\n + class NoAvailablePushIDError(H3Error):\n + \"\"\"\n + There are no available push IDs left.\n + \"\"\"\n + \n===========changed ref 2===========\n + # module: aioquic.h3.exceptions\n + class H3Error(Exception):\n + \"\"\"\n + Base class for HTTP/3 exceptions.\n + \"\"\"\n + \n===========changed ref 3===========\n # module: examples.demo\n @app.route(\"/\")\n async def homepage(request):\n \"\"\"\n Simple homepage.\n \"\"\"\n + await request.send_push_promise(\"/style.css\")\n return templates.TemplateResponse(\"index.html\", {\"request\": request})\n \n===========changed ref 4===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _init_connection(self) -> None:\n # send our settings\n self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL)\n self._quic.send_stream_data(\n self._local_control_stream_id,\n encode_frame(\n FrameType.SETTINGS,\n encode_settings(\n {\n Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity,\n Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams,\n }\n ),\n ),\n )\n + if self._is_client and self._max_push_id is not None:\n - if self._is_client:\n self._quic.send_stream_data(\n self._local_control_stream_id,\n encode_frame(FrameType.MAX_PUSH_ID, encode_uint_var(self._max_push_id)),\n )\n \n # create encoder and decoder streams\n self._local_encoder_stream_id = self._create_uni_stream(\n StreamType.QPACK_ENCODER\n )\n self._local_decoder_stream_id = self._create_uni_stream(\n StreamType.QPACK_DECODER\n )\n \n===========changed ref 5===========\n # module: aioquic.h3.connection\n class H3Connection:\n def send_push_promise(self, stream_id: int, headers: Headers) -> int:\n \"\"\"\n Send a push promise related to the specified stream.\n \n Returns the stream ID on which headers and data can be sent.\n \n :param stream_id: The stream ID on which to send the data.\n :param headers: The HTTP request headers for this push.\n \"\"\"\n assert not self._is_client, \"Only servers may send a push promise.\"\n + if self._max_push_id is None or self._next_push_id >= self._max_push_id:\n - assert self._max_push_id is not None and self._next_push_id < self._max_push_id\n + raise NoAvailablePushIDError\n \n # send push promise\n push_id = self._next_push_id\n self._next_push_id += 1\n self._quic.send_stream_data(\n stream_id,\n encode_frame(\n FrameType.PUSH_PROMISE,\n encode_uint_var(push_id) + self._encode_headers(stream_id, headers),\n ),\n )\n \n #  create push stream\n push_stream_id = self._create_uni_stream(StreamType.PUSH)\n self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id))\n \n return push_stream_id\n \n===========changed ref 6===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n + def test_request_with_server_push_max_push_id(self):\n + with client_and_server(\n + client_options={\"alpn_protocols\": [\"h3-22\"]},\n + server_options={\"alpn_protocols\": [\"h3-22\"]},\n + ) as (quic_client, quic_server):\n + h3_client = H3Connection(quic_client)\n + h3_server = H3Connection(quic_server)\n + \n + # send request\n + stream_id = quic_client.get_next_available_stream_id()\n + h3_client.send_headers(\n + stream_id=stream_id,\n + headers=[\n + (b\":method\", b\"GET\"),\n + (b\":scheme\", b\"https\"),\n + (b\":authority\", b\"localhost\"),\n + (b\":path\", b\"/\"),\n + ],\n + end_stream=True,\n + )\n + \n + # receive request\n + events = h3_transfer(quic_client, h3_server)\n + self.assertEqual(\n + events,\n + [\n + HeadersReceived(\n + headers=[\n + (b\":method\", b\"GET\"),\n + (b\":scheme\", b\"https\"),\n + (b\":authority\", b\"localhost\"),\n + (b\":path\", b\"/\"),\n + ],\n + stream_id=stream_id,\n + stream_ended=True,\n + )\n + ],\n + )\n + \n + # send push promises\n + for i in range(0, 8):\n + h3_server.send_push_promise(\n + stream_id=stream_id,\n + headers=[\n + (b\":method\", b\"GET\"),\n + (b\":scheme\", b\"https\"),\n + (b\":authority\", b\"localhost\"),\n + (b\":path\",\n===========changed ref 7===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n + def test_request_with_server_push_max_push_id(self):\n # offset: 1\n b\":scheme\", b\"https\"),\n + (b\":authority\", b\"localhost\"),\n + (b\":path\", \"/{}.css\".format(i).encode(\"ascii\")),\n + ],\n + )\n + \n + # send one too many\n + with self.assertRaises(NoAvailablePushIDError):\n + h3_server.send_push_promise(\n + stream_id=stream_id,\n + headers=[\n + (b\":method\", b\"GET\"),\n + (b\":scheme\", b\"https\"),\n + (b\":authority\", b\"localhost\"),\n + (b\":path\", b\"/8.css\"),\n + ],\n + )\n + "}}},{"rowIdx":3439,"cells":{"path":{"kind":"string","value":"examples.http3_server/HttpRequestHandler.send"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"1a83d7684ff29a526b9c961402070d82a0f60009"},"commit_message":{"kind":"string","value":"[examples] add ASGI bindings for server push"},"ground_truth":{"kind":"string","value":"<16>: elif message[\"type\"] == \"http.response.push\" and isinstance(\n self.connection, H3Connection\n ):\n request_headers = [\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", self.authority),\n (b\":path\", message[\"path\"].encode(\"utf8\")),\n ] + [(k, v) for k, v in message[\"headers\"]]\n \n # send push promise\n try:\n push_stream_id = self.connection.send_push_promise(\n stream_id=self.stream_id, headers=request_headers\n )\n except NoAvailablePushIDError:\n return\n \n # fake request\n self.protocol.http_event_received(\n HeadersReceived(\n headers=request_headers, stream_ended=True, stream_id=push_stream_id"},"main_code":{"kind":"string","value":" # module: examples.http3_server\n class HttpRequestHandler:\n def send(self, message: Dict):\n <0> if message[\"type\"] == \"http.response.start\":\n <1> self.connection.send_headers(\n <2> stream_id=self.stream_id,\n <3> headers=[\n <4> (b\":status\", str(message[\"status\"]).encode(\"ascii\")),\n <5> (b\"server\", b\"aioquic\"),\n <6> (b\"date\", formatdate(time.time(), usegmt=True).encode()),\n <7> ]\n <8> + [(k, v) for k, v in message[\"headers\"]],\n <9> )\n<10> elif message[\"type\"] == \"http.response.body\":\n<11> self.connection.send_data(\n<12> stream_id=self.stream_id,\n<13> data=message.get(\"body\", b\"\"),\n<14> end_stream=not message.get(\"more_body\", False),\n<15> )\n<16> self.transmit()\n<17> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h0.connection.H0Connection\n send_data(stream_id: int, data: bytes, end_stream: bool) -> None\n \n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.connection.H3Connection\n send_data(stream_id: int, data: bytes, end_stream: bool) -> None\n \n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: asyncio.queues.Queue\n __class_getitem__ = classmethod(GenericAlias)\n \n get() -> _T\n \n at: email.utils\n formatdate(timeval: Optional[float]=..., localtime: bool=..., usegmt: bool=...) -> str\n \n at: examples.http3_server\n application = getattr(module, attr_str)\n \n at: examples.http3_server.HttpRequestHandler.__init__\n self.connection = connection\n \n self.queue: asyncio.Queue[Dict] = asyncio.Queue()\n \n self.scope = scope\n \n self.stream_id = stream_id\n \n at: time\n time() -> float\n \n at: typing\n Dict = _alias(dict, 2, inst=False, name='Dict')\n \n \n===========changed ref 0===========\n # module: examples.http3_server\n class HttpRequestHandler:\n def __init__(\n self,\n *,\n + authority: bytes,\n connection: HttpConnection,\n + protocol: QuicConnectionProtocol,\n scope: Dict,\n stream_ended: bool,\n stream_id: int,\n transmit: Callable[[], None],\n ):\n + self.authority = authority\n self.connection = connection\n + self.protocol = protocol\n self.queue: asyncio.Queue[Dict] = asyncio.Queue()\n self.scope = scope\n self.stream_id = stream_id\n self.transmit = transmit\n \n if stream_ended:\n self.queue.put_nowait({\"type\": \"http.request\"})\n \n===========changed ref 1===========\n + # module: aioquic.h3.exceptions\n + \n + \n===========changed ref 2===========\n + # module: aioquic.h3.exceptions\n + class NoAvailablePushIDError(H3Error):\n + \"\"\"\n + There are no available push IDs left.\n + \"\"\"\n + \n===========changed ref 3===========\n + # module: aioquic.h3.exceptions\n + class H3Error(Exception):\n + \"\"\"\n + Base class for HTTP/3 exceptions.\n + \"\"\"\n + \n===========changed ref 4===========\n # module: examples.demo\n @app.route(\"/\")\n async def homepage(request):\n \"\"\"\n Simple homepage.\n \"\"\"\n + await request.send_push_promise(\"/style.css\")\n return templates.TemplateResponse(\"index.html\", {\"request\": request})\n \n===========changed ref 5===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _init_connection(self) -> None:\n # send our settings\n self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL)\n self._quic.send_stream_data(\n self._local_control_stream_id,\n encode_frame(\n FrameType.SETTINGS,\n encode_settings(\n {\n Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity,\n Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams,\n }\n ),\n ),\n )\n + if self._is_client and self._max_push_id is not None:\n - if self._is_client:\n self._quic.send_stream_data(\n self._local_control_stream_id,\n encode_frame(FrameType.MAX_PUSH_ID, encode_uint_var(self._max_push_id)),\n )\n \n # create encoder and decoder streams\n self._local_encoder_stream_id = self._create_uni_stream(\n StreamType.QPACK_ENCODER\n )\n self._local_decoder_stream_id = self._create_uni_stream(\n StreamType.QPACK_DECODER\n )\n \n===========changed ref 6===========\n # module: aioquic.h3.connection\n class H3Connection:\n def send_push_promise(self, stream_id: int, headers: Headers) -> int:\n \"\"\"\n Send a push promise related to the specified stream.\n \n Returns the stream ID on which headers and data can be sent.\n \n :param stream_id: The stream ID on which to send the data.\n :param headers: The HTTP request headers for this push.\n \"\"\"\n assert not self._is_client, \"Only servers may send a push promise.\"\n + if self._max_push_id is None or self._next_push_id >= self._max_push_id:\n - assert self._max_push_id is not None and self._next_push_id < self._max_push_id\n + raise NoAvailablePushIDError\n \n # send push promise\n push_id = self._next_push_id\n self._next_push_id += 1\n self._quic.send_stream_data(\n stream_id,\n encode_frame(\n FrameType.PUSH_PROMISE,\n encode_uint_var(push_id) + self._encode_headers(stream_id, headers),\n ),\n )\n \n #  create push stream\n push_stream_id = self._create_uni_stream(StreamType.PUSH)\n self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id))\n \n return push_stream_id\n \n===========changed ref 7===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n + def test_request_with_server_push_max_push_id(self):\n + with client_and_server(\n + client_options={\"alpn_protocols\": [\"h3-22\"]},\n + server_options={\"alpn_protocols\": [\"h3-22\"]},\n + ) as (quic_client, quic_server):\n + h3_client = H3Connection(quic_client)\n + h3_server = H3Connection(quic_server)\n + \n + # send request\n + stream_id = quic_client.get_next_available_stream_id()\n + h3_client.send_headers(\n + stream_id=stream_id,\n + headers=[\n + (b\":method\", b\"GET\"),\n + (b\":scheme\", b\"https\"),\n + (b\":authority\", b\"localhost\"),\n + (b\":path\", b\"/\"),\n + ],\n + end_stream=True,\n + )\n + \n + # receive request\n + events = h3_transfer(quic_client, h3_server)\n + self.assertEqual(\n + events,\n + [\n + HeadersReceived(\n + headers=[\n + (b\":method\", b\"GET\"),\n + (b\":scheme\", b\"https\"),\n + (b\":authority\", b\"localhost\"),\n + (b\":path\", b\"/\"),\n + ],\n + stream_id=stream_id,\n + stream_ended=True,\n + )\n + ],\n + )\n + \n + # send push promises\n + for i in range(0, 8):\n + h3_server.send_push_promise(\n + stream_id=stream_id,\n + headers=[\n + (b\":method\", b\"GET\"),\n + (b\":scheme\", b\"https\"),\n + (b\":authority\", b\"localhost\"),\n + (b\":path\","}}},{"rowIdx":3440,"cells":{"path":{"kind":"string","value":"examples.http3_server/HttpServerProtocol.http_event_received"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"1a83d7684ff29a526b9c961402070d82a0f60009"},"commit_message":{"kind":"string","value":"[examples] add ASGI bindings for server push"},"ground_truth":{"kind":"string","value":" <1>: authority = None\n <8>: authority = value\n"},"main_code":{"kind":"string","value":" # module: examples.http3_server\n class HttpServerProtocol(QuicConnectionProtocol):\n def http_event_received(self, event: HttpEvent) -> None:\n <0> if isinstance(event, HeadersReceived) and event.stream_id not in self._handlers:\n <1> headers = []\n <2> http_version = \"0.9\" if isinstance(self._http, H0Connection) else \"3\"\n <3> raw_path = b\"\"\n <4> method = \"\"\n <5> protocol = None\n <6> for header, value in event.headers:\n <7> if header == b\":authority\":\n <8> headers.append((b\"host\", value))\n <9> elif header == b\":method\":\n<10> method = value.decode(\"utf8\")\n<11> elif header == b\":path\":\n<12> raw_path = value\n<13> elif header == b\":protocol\":\n<14> protocol = value.decode(\"utf8\")\n<15> elif header and not header.startswith(b\":\"):\n<16> headers.append((header, value))\n<17> \n<18> if b\"?\" in raw_path:\n<19> path_bytes, query_string = raw_path.split(b\"?\", maxsplit=1)\n<20> else:\n<21> path_bytes, query_string = raw_path, b\"\"\n<22> path = path_bytes.decode(\"utf8\")\n<23> \n<24> handler: Handler\n<25> if method == \"CONNECT\" and protocol == \"websocket\":\n<26> subprotocols: List[str] = []\n<27> for header, value in event.headers:\n<28> if header == b\"sec-websocket-protocol\":\n<29> subprotocols = [\n<30> x.strip() for x in value.decode(\"utf8\").split(\",\")\n<31> ]\n<32> scope = {\n<33> \"headers\": headers,\n<34> \"http_version\": http_version,\n<35> \"method\": method,\n<36> \"path\": path,\n<37> \"query_string\": query_string,\n<38> \"raw_path\": raw_path,\n<39> \"root_path\": \"\",\n<40> \"scheme\": \"wss\",\n<41> \"subprotocols\": subprotocols,\n<42> \"type\": \"websocket\","},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: examples.http3_server\n class HttpServerProtocol(QuicConnectionProtocol):\n def http_event_received(self, event: HttpEvent) -> None:\n # offset: 1\n handler = WebSocketHandler(\n connection=self._http,\n scope=scope,\n stream_id=event.stream_id,\n transmit=self.transmit,\n )\n else:\n scope = {\n \"headers\": headers,\n \"http_version\": http_version,\n \"method\": method,\n \"path\": path,\n \"query_string\": query_string,\n \"raw_path\": raw_path,\n \"root_path\": \"\",\n \"scheme\": \"https\",\n \"type\": \"http\",\n }\n handler = HttpRequestHandler(\n connection=self._http,\n scope=scope,\n stream_ended=event.stream_ended,\n stream_id=event.stream_id,\n transmit=self.transmit,\n )\n self._handlers[event.stream_id] = handler\n asyncio.ensure_future(handler.run_asgi(application))\n elif isinstance(event, DataReceived) and event.stream_id in self._handlers:\n handler = self._handlers[event.stream_id]\n handler.http_event_received(event)\n \n \n===========unchanged ref 0===========\n at: aioquic.asyncio.protocol\n QuicConnectionProtocol(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None)\n \n at: aioquic.asyncio.protocol.QuicConnectionProtocol\n __init__(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None)\n __init__(self, quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None)\n \n at: aioquic.h0.connection\n H0Connection(quic: QuicConnection)\n \n at: aioquic.h0.connection.H0Connection\n send_data(stream_id: int, data: bytes, end_stream: bool) -> None\n \n at: aioquic.h3.connection.H3Connection\n send_data(stream_id: int, data: bytes, end_stream: bool) -> None\n \n at: aioquic.h3.events\n HttpEvent()\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: examples.http3_server\n HttpConnection = Union[H0Connection, H3Connection]\n \n HttpRequestHandler(*, authority: bytes, connection: HttpConnection, protocol: QuicConnectionProtocol, scope: Dict, stream_ended: bool, stream_id: int, transmit: Callable[[], None])\n \n WebSocketHandler(*, connection: HttpConnection, scope: Dict, stream_id: int, transmit: Callable[[], None])\n \n at: examples.http3_server.HttpServerProtocol.quic_event_received\n self._http = H3Connection(self._quic)\n self._http = H0Connection(self._quic)\n \n at: examples.http3_server.WebSocketHandler.__init__\n self.closed = False\n \n self.connection = connection\n \n self.stream_id = stream_id\n \n self.transmit = transmit\n \n self.websocket: Optional[wsproto.Connection] = None\n \n \n===========unchanged ref 1===========\n at: examples.http3_server.WebSocketHandler.send\n self.websocket = wsproto.Connection(wsproto.ConnectionType.SERVER)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n Dict = _alias(dict, 2, inst=False, name='Dict')\n \n at: typing.Mapping\n get(key: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T]\n get(key: _KT) -> Optional[_VT_co]\n \n \n===========changed ref 0===========\n # module: examples.http3_server\n class HttpRequestHandler:\n def __init__(\n self,\n *,\n + authority: bytes,\n connection: HttpConnection,\n + protocol: QuicConnectionProtocol,\n scope: Dict,\n stream_ended: bool,\n stream_id: int,\n transmit: Callable[[], None],\n ):\n + self.authority = authority\n self.connection = connection\n + self.protocol = protocol\n self.queue: asyncio.Queue[Dict] = asyncio.Queue()\n self.scope = scope\n self.stream_id = stream_id\n self.transmit = transmit\n \n if stream_ended:\n self.queue.put_nowait({\"type\": \"http.request\"})\n \n===========changed ref 1===========\n # module: examples.http3_server\n class HttpRequestHandler:\n def send(self, message: Dict):\n if message[\"type\"] == \"http.response.start\":\n self.connection.send_headers(\n stream_id=self.stream_id,\n headers=[\n (b\":status\", str(message[\"status\"]).encode(\"ascii\")),\n (b\"server\", b\"aioquic\"),\n (b\"date\", formatdate(time.time(), usegmt=True).encode()),\n ]\n + [(k, v) for k, v in message[\"headers\"]],\n )\n elif message[\"type\"] == \"http.response.body\":\n self.connection.send_data(\n stream_id=self.stream_id,\n data=message.get(\"body\", b\"\"),\n end_stream=not message.get(\"more_body\", False),\n )\n + elif message[\"type\"] == \"http.response.push\" and isinstance(\n + self.connection, H3Connection\n + ):\n + request_headers = [\n + (b\":method\", b\"GET\"),\n + (b\":scheme\", b\"https\"),\n + (b\":authority\", self.authority),\n + (b\":path\", message[\"path\"].encode(\"utf8\")),\n + ] + [(k, v) for k, v in message[\"headers\"]]\n + \n + # send push promise\n + try:\n + push_stream_id = self.connection.send_push_promise(\n + stream_id=self.stream_id, headers=request_headers\n + )\n + except NoAvailablePushIDError:\n + return\n + \n + # fake request\n + self.protocol.http_event_received(\n + HeadersReceived(\n + headers=request_headers, stream_ended=True, stream_id=push_stream_id\n + )\n + )\n self.transmit()\n \n===========changed ref 2===========\n + # module: aioquic.h3.exceptions\n + \n + \n===========changed ref 3===========\n + # module: aioquic.h3.exceptions\n + class NoAvailablePushIDError(H3Error):\n + \"\"\"\n + There are no available push IDs left.\n + \"\"\"\n + \n===========changed ref 4===========\n + # module: aioquic.h3.exceptions\n + class H3Error(Exception):\n + \"\"\"\n + Base class for HTTP/3 exceptions.\n + \"\"\"\n + \n===========changed ref 5===========\n # module: examples.demo\n @app.route(\"/\")\n async def homepage(request):\n \"\"\"\n Simple homepage.\n \"\"\"\n + await request.send_push_promise(\"/style.css\")\n return templates.TemplateResponse(\"index.html\", {\"request\": request})\n "}}},{"rowIdx":3441,"cells":{"path":{"kind":"string","value":"aioquic.h0.connection/H0Connection.handle_event"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"d290ebea69fdddd2d4afb594a8a312fa5f95d71f"},"commit_message":{"kind":"string","value":"[h3] rename HttpEvent to H3Event"},"ground_truth":{"kind":"string","value":" <0>: http_events: List[H3Event] = []\n http_events: List[HttpEvent] = []\n"},"main_code":{"kind":"string","value":" # module: aioquic.h0.connection\n class H0Connection:\n + def handle_event(self, event: QuicEvent) -> List[H3Event]:\n - def handle_event(self, event: QuicEvent) -> List[HttpEvent]:\n <0> http_events: List[HttpEvent] = []\n <1> \n <2> if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0:\n <3> data = event.data\n <4> if not self._headers_received.get(event.stream_id, False):\n <5> if self._is_client:\n <6> http_events.append(\n <7> HeadersReceived(\n <8> headers=[], stream_ended=False, stream_id=event.stream_id\n <9> )\n<10> )\n<11> else:\n<12> method, path = data.rstrip().split(b\" \", 1)\n<13> http_events.append(\n<14> HeadersReceived(\n<15> headers=[(b\":method\", method), (b\":path\", path)],\n<16> stream_ended=False,\n<17> stream_id=event.stream_id,\n<18> )\n<19> )\n<20> data = b\"\"\n<21> self._headers_received[event.stream_id] = True\n<22> \n<23> http_events.append(\n<24> DataReceived(\n<25> data=data, stream_ended=event.end_stream, stream_id=event.stream_id\n<26> )\n<27> )\n<28> \n<29> return http_events\n<30> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h0.connection.H0Connection.__init__\n self._headers_received: Dict[int, bool] = {}\n \n self._is_client = quic.configuration.is_client\n \n at: aioquic.h3.events\n H3Event()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.h3.events.DataReceived\n data: bytes\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.HeadersReceived\n headers: Headers\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.quic.events\n QuicEvent()\n \n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n at: typing.Mapping\n get(key: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T]\n get(key: _KT) -> Optional[_VT_co]\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + class H3Event:\n + \"\"\"\n + Base class for HTTP/3 events.\n + \"\"\"\n + \n===========changed ref 1===========\n # module: aioquic.h3.events\n - class HttpEvent:\n - \"\"\"\n - Base class for HTTP/3 events.\n - \"\"\"\n - \n - pass\n - "}}},{"rowIdx":3442,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._handle_push_frame"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"d290ebea69fdddd2d4afb594a8a312fa5f95d71f"},"commit_message":{"kind":"string","value":"[h3] rename HttpEvent to H3Event"},"ground_truth":{"kind":"string","value":" <3>: http_events: List[H3Event] = []\n http_events: List[HttpEvent] = []\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _handle_push_frame(\n self,\n frame_type: int,\n frame_data: bytes,\n push_id: int,\n stream_id: int,\n stream_ended: bool,\n + ) -> List[H3Event]:\n - ) -> List[HttpEvent]:\n <0> \"\"\"\n <1> Handle a frame received on a push stream.\n <2> \"\"\"\n <3> http_events: List[HttpEvent] = []\n <4> \n <5> if frame_type == FrameType.DATA:\n <6> http_events.append(\n <7> DataReceived(\n <8> data=frame_data,\n <9> push_id=push_id,\n<10> stream_ended=stream_ended,\n<11> stream_id=stream_id,\n<12> )\n<13> )\n<14> elif frame_type == FrameType.HEADERS:\n<15> headers = self._decode_headers(stream_id, frame_data)\n<16> http_events.append(\n<17> HeadersReceived(\n<18> headers=headers,\n<19> push_id=push_id,\n<20> stream_id=stream_id,\n<21> stream_ended=stream_ended,\n<22> )\n<23> )\n<24> elif frame_type in (\n<25> FrameType.PRIORITY,\n<26> FrameType.CANCEL_PUSH,\n<27> FrameType.SETTINGS,\n<28> FrameType.PUSH_PROMISE,\n<29> FrameType.GOAWAY,\n<30> FrameType.MAX_PUSH_ID,\n<31> FrameType.DUPLICATE_PUSH,\n<32> ):\n<33> raise QuicConnectionError(\n<34> error_code=ErrorCode.HTTP_WRONG_STREAM,\n<35> frame_type=None,\n<36> reason_phrase=\"Invalid frame type on push stream\",\n<37> )\n<38> \n<39> return http_events\n<40> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n at: aioquic.h3.connection.H3Connection\n _decode_headers(stream_id: int, frame_data: bytes) -> Headers\n \n at: aioquic.h3.events\n H3Event()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.h3.events.DataReceived\n data: bytes\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.HeadersReceived\n headers: Headers\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.quic.connection\n QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + class H3Event:\n + \"\"\"\n + Base class for HTTP/3 events.\n + \"\"\"\n + \n===========changed ref 1===========\n # module: aioquic.h3.events\n - class HttpEvent:\n - \"\"\"\n - Base class for HTTP/3 events.\n - \"\"\"\n - \n - pass\n - \n===========changed ref 2===========\n # module: aioquic.h0.connection\n class H0Connection:\n + def handle_event(self, event: QuicEvent) -> List[H3Event]:\n - def handle_event(self, event: QuicEvent) -> List[HttpEvent]:\n + http_events: List[H3Event] = []\n - http_events: List[HttpEvent] = []\n \n if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0:\n data = event.data\n if not self._headers_received.get(event.stream_id, False):\n if self._is_client:\n http_events.append(\n HeadersReceived(\n headers=[], stream_ended=False, stream_id=event.stream_id\n )\n )\n else:\n method, path = data.rstrip().split(b\" \", 1)\n http_events.append(\n HeadersReceived(\n headers=[(b\":method\", method), (b\":path\", path)],\n stream_ended=False,\n stream_id=event.stream_id,\n )\n )\n data = b\"\"\n self._headers_received[event.stream_id] = True\n \n http_events.append(\n DataReceived(\n data=data, stream_ended=event.end_stream, stream_id=event.stream_id\n )\n )\n \n return http_events\n "}}},{"rowIdx":3443,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_stream_data_bidi"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"d290ebea69fdddd2d4afb594a8a312fa5f95d71f"},"commit_message":{"kind":"string","value":"[h3] rename HttpEvent to H3Event"},"ground_truth":{"kind":"string","value":" <3>: http_events: List[H3Event] = []\n http_events: List[HttpEvent] = []\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n + ) -> List[H3Event]:\n - ) -> List[HttpEvent]:\n <0> \"\"\"\n <1> Client-initiated bidirectional streams carry requests and responses.\n <2> \"\"\"\n <3> http_events: List[HttpEvent] = []\n <4> \n <5> stream = self._stream[stream_id]\n <6> stream.buffer += data\n <7> if stream_ended:\n <8> stream.ended = True\n <9> if stream.blocked:\n<10> return http_events\n<11> \n<12> # shortcut DATA frame bits\n<13> if (\n<14> stream.frame_type == FrameType.DATA\n<15> and stream.frame_size is not None\n<16> and len(stream.buffer) < stream.frame_size\n<17> ):\n<18> http_events.append(\n<19> DataReceived(\n<20> data=stream.buffer, stream_id=stream_id, stream_ended=False\n<21> )\n<22> )\n<23> stream.frame_size -= len(stream.buffer)\n<24> stream.buffer = b\"\"\n<25> return http_events\n<26> \n<27> # some peers (e.g. f5) end the stream with no data\n<28> if stream_ended and not stream.buffer:\n<29> http_events.append(\n<30> DataReceived(data=b\"\", stream_id=stream_id, stream_ended=True)\n<31> )\n<32> return http_events\n<33> \n<34> buf = Buffer(data=stream.buffer)\n<35> consumed = 0\n<36> \n<37> while not buf.eof():\n<38> # fetch next frame header\n<39> if stream.frame_size is None:\n<40> try:\n<41> stream.frame_type = buf.pull_uint_var()\n<42> stream.frame_size = buf.pull_uint_var()\n<43> except BufferReadError:\n<44> break\n<45> consumed = buf.tell()\n<46> \n<47> # check how much data is available\n<48> chunk_size = min"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n + ) -> List[H3Event]:\n - ) -> List[HttpEvent]:\n # offset: 1\n if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size:\n break\n \n # read available data\n frame_data = buf.pull_bytes(chunk_size)\n consumed = buf.tell()\n \n # detect end of frame\n stream.frame_size -= chunk_size\n if not stream.frame_size:\n stream.frame_size = None\n \n if stream.frame_type == FrameType.DATA and (stream_ended or frame_data):\n http_events.append(\n DataReceived(\n data=frame_data,\n stream_id=stream_id,\n stream_ended=stream_ended and buf.eof(),\n )\n )\n elif stream.frame_type == FrameType.HEADERS:\n try:\n headers = self._decode_headers(stream_id, frame_data)\n except StreamBlocked:\n stream.blocked = True\n break\n http_events.append(\n HeadersReceived(\n headers=headers,\n stream_id=stream_id,\n stream_ended=stream_ended and buf.eof(),\n )\n )\n elif stream.frame_type == FrameType.PUSH_PROMISE:\n if not self._is_client:\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n frame_type=None,\n reason_phrase=\"Clients must not send PUSH_PROMISE\",\n )\n frame_buf = Buffer(data=frame_data)\n push_id = frame_buf.pull_uint_var()\n headers = self._decode_headers(\n stream_id, frame_data[frame_buf.tell() :]\n )\n http_events.append(\n PushPromiseReceived(\n headers=headers, push_id=\n===========below chunk 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n + ) -> List[H3Event]:\n - ) -> List[HttpEvent]:\n # offset: 2\n () :]\n )\n http_events.append(\n PushPromiseReceived(\n headers=headers, push_id=push_id, stream_id=stream_id\n )\n )\n elif stream.frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on request stream\",\n )\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n at: aioquic.h3.connection.H3Connection\n _decode_headers(stream_id: int, frame_data: bytes) -> Headers\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._is_client = quic.configuration.is_client\n \n self._stream: Dict[int, H3Stream] = {}\n \n at: aioquic.h3.connection.H3Stream.__init__\n self.blocked = False\n \n self.buffer = b\"\"\n \n self.ended = False\n \n self.frame_size: Optional[int] = None\n \n self.frame_type: Optional[int] = None\n \n at: aioquic.h3.events\n H3Event()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n PushPromiseReceived(headers: Headers, push_id: int, stream_id: int)\n \n at: aioquic.quic.connection\n QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)\n \n \n===========unchanged ref 1===========\n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + class H3Event:\n + \"\"\"\n + Base class for HTTP/3 events.\n + \"\"\"\n + \n===========changed ref 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_push_frame(\n self,\n frame_type: int,\n frame_data: bytes,\n push_id: int,\n stream_id: int,\n stream_ended: bool,\n + ) -> List[H3Event]:\n - ) -> List[HttpEvent]:\n \"\"\"\n Handle a frame received on a push stream.\n \"\"\"\n + http_events: List[H3Event] = []\n - http_events: List[HttpEvent] = []\n \n if frame_type == FrameType.DATA:\n http_events.append(\n DataReceived(\n data=frame_data,\n push_id=push_id,\n stream_ended=stream_ended,\n stream_id=stream_id,\n )\n )\n elif frame_type == FrameType.HEADERS:\n headers = self._decode_headers(stream_id, frame_data)\n http_events.append(\n HeadersReceived(\n headers=headers,\n push_id=push_id,\n stream_id=stream_id,\n stream_ended=stream_ended,\n )\n )\n elif frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.PUSH_PROMISE,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n FrameType.DUPLICATE_PUSH,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on push stream\",\n )\n \n return http_events\n \n===========changed ref 2===========\n # module: aioquic.h3.events\n - class HttpEvent:\n - \"\"\"\n - Base class for HTTP/3 events.\n - \"\"\"\n - \n - pass\n - "}}},{"rowIdx":3444,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_stream_data_uni"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"d290ebea69fdddd2d4afb594a8a312fa5f95d71f"},"commit_message":{"kind":"string","value":"[h3] rename HttpEvent to H3Event"},"ground_truth":{"kind":"string","value":" <0>: http_events: List[H3Event] = []\n http_events: List[HttpEvent] = []\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n + ) -> List[H3Event]:\n - ) -> List[HttpEvent]:\n <0> http_events: List[HttpEvent] = []\n <1> \n <2> stream = self._stream[stream_id]\n <3> stream.buffer += data\n <4> if stream_ended:\n <5> stream.ended = True\n <6> \n <7> buf = Buffer(data=stream.buffer)\n <8> consumed = 0\n <9> unblocked_streams: Set[int] = set()\n<10> \n<11> while not buf.eof():\n<12> # fetch stream type for unidirectional streams\n<13> if stream.stream_type is None:\n<14> try:\n<15> stream.stream_type = buf.pull_uint_var()\n<16> except BufferReadError:\n<17> break\n<18> consumed = buf.tell()\n<19> \n<20> # check unicity\n<21> if stream.stream_type == StreamType.CONTROL:\n<22> assert self._peer_control_stream_id is None\n<23> self._peer_control_stream_id = stream_id\n<24> elif stream.stream_type == StreamType.QPACK_DECODER:\n<25> assert self._peer_decoder_stream_id is None\n<26> self._peer_decoder_stream_id = stream_id\n<27> elif stream.stream_type == StreamType.QPACK_ENCODER:\n<28> assert self._peer_encoder_stream_id is None\n<29> self._peer_encoder_stream_id = stream_id\n<30> \n<31> if stream.stream_type == StreamType.CONTROL:\n<32> # fetch next frame\n<33> try:\n<34> frame_type = buf.pull_uint_var()\n<35> frame_length = buf.pull_uint_var()\n<36> frame_data = buf.pull_bytes(frame_length)\n<37> except BufferReadError:\n<38> break\n<39> consumed = buf.tell()\n<40> \n<41> self._handle_control_frame(frame_type,"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n + ) -> List[H3Event]:\n - ) -> List[HttpEvent]:\n # offset: 1\n elif stream.stream_type == StreamType.PUSH:\n # fetch push id\n if stream.push_id is None:\n try:\n stream.push_id = buf.pull_uint_var()\n except BufferReadError:\n break\n consumed = buf.tell()\n \n # fetch next frame\n try:\n frame_type = buf.pull_uint_var()\n frame_length = buf.pull_uint_var()\n frame_data = buf.pull_bytes(frame_length)\n except BufferReadError:\n break\n consumed = buf.tell()\n \n http_events.extend(\n self._handle_push_frame(\n frame_type=frame_type,\n frame_data=frame_data,\n push_id=stream.push_id,\n stream_id=stream_id,\n stream_ended=stream.ended and buf.eof(),\n )\n )\n elif stream.stream_type == StreamType.QPACK_DECODER:\n # feed unframed data to decoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n self._encoder.feed_decoder(data)\n elif stream.stream_type == StreamType.QPACK_ENCODER:\n # feed unframed data to encoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n unblocked_streams.update(self._decoder.feed_encoder(data))\n else:\n # unknown stream type, discard data\n buf.seek(buf.capacity)\n consumed = buf.tell()\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n # process unblocked streams\n for\n===========below chunk 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n + ) -> List[H3Event]:\n - ) -> List[HttpEvent]:\n # offset: 2\n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n # process unblocked streams\n for stream_id in unblocked_streams:\n stream = self._stream[stream_id]\n decoder, headers = self._decoder.resume_header(stream_id)\n stream.blocked = False\n http_events.append(\n HeadersReceived(\n headers=headers,\n stream_id=stream_id,\n stream_ended=stream.ended and not stream.buffer,\n )\n )\n http_events.extend(\n self._receive_stream_data_bidi(stream_id, b\"\", stream.ended)\n )\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n at: aioquic.h3.connection.H3Connection\n _handle_control_frame(frame_type: int, frame_data: bytes) -> None\n \n _handle_push_frame(self, frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[H3Event]\n _handle_push_frame(frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[H3Event]\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._encoder = Encoder()\n \n self._stream: Dict[int, H3Stream] = {}\n \n self._peer_control_stream_id: Optional[int] = None\n \n self._peer_decoder_stream_id: Optional[int] = None\n \n self._peer_encoder_stream_id: Optional[int] = None\n \n at: aioquic.h3.events\n H3Event()\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n Set = _alias(set, 1, inst=False, name='Set')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_push_frame(\n self,\n frame_type: int,\n frame_data: bytes,\n push_id: int,\n stream_id: int,\n stream_ended: bool,\n + ) -> List[H3Event]:\n - ) -> List[HttpEvent]:\n \"\"\"\n Handle a frame received on a push stream.\n \"\"\"\n + http_events: List[H3Event] = []\n - http_events: List[HttpEvent] = []\n \n if frame_type == FrameType.DATA:\n http_events.append(\n DataReceived(\n data=frame_data,\n push_id=push_id,\n stream_ended=stream_ended,\n stream_id=stream_id,\n )\n )\n elif frame_type == FrameType.HEADERS:\n headers = self._decode_headers(stream_id, frame_data)\n http_events.append(\n HeadersReceived(\n headers=headers,\n push_id=push_id,\n stream_id=stream_id,\n stream_ended=stream_ended,\n )\n )\n elif frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.PUSH_PROMISE,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n FrameType.DUPLICATE_PUSH,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on push stream\",\n )\n \n return http_events\n \n===========changed ref 1===========\n # module: aioquic.h3.events\n + class H3Event:\n + \"\"\"\n + Base class for HTTP/3 events.\n + \"\"\"\n + "}}},{"rowIdx":3445,"cells":{"path":{"kind":"string","value":"examples.http3_client/HttpClient.__init__"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"d290ebea69fdddd2d4afb594a8a312fa5f95d71f"},"commit_message":{"kind":"string","value":"[h3] rename HttpEvent to H3Event"},"ground_truth":{"kind":"string","value":" <3>: self._request_events: Dict[int, Deque[H3Event]] = {}\n self._request_events: Dict[int, Deque[HttpEvent]] = {}\n <4>: self._request_waiter: Dict[int, asyncio.Future[Deque[H3Event]]] = {}\n self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {}\n"},"main_code":{"kind":"string","value":" # module: examples.http3_client\n class HttpClient(QuicConnectionProtocol):\n def __init__(self, *args, **kwargs):\n <0> super().__init__(*args, **kwargs)\n <1> \n <2> self._http: Optional[HttpConnection] = None\n <3> self._request_events: Dict[int, Deque[HttpEvent]] = {}\n <4> self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {}\n <5> self._websockets: Dict[int, WebSocket] = {}\n <6> \n <7> if self._quic.configuration.alpn_protocols[0].startswith(\"hq-\"):\n <8> self._http = H0Connection(self._quic)\n <9> else:\n<10> self._http = H3Connection(self._quic)\n<11> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.asyncio.protocol.QuicConnectionProtocol\n __init__(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None)\n __init__(self, quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None)\n \n at: aioquic.asyncio.protocol.QuicConnectionProtocol.__init__\n self._quic = quic\n \n at: aioquic.h0.connection\n H0Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection\n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.events\n H3Event()\n \n at: aioquic.quic.configuration.QuicConfiguration\n alpn_protocols: Optional[List[str]] = None\n \n certificate: Any = None\n \n connection_id_length: int = 8\n \n idle_timeout: float = 60.0\n \n is_client: bool = True\n \n private_key: Any = None\n \n quic_logger: Optional[QuicLogger] = None\n \n secrets_log_file: TextIO = None\n \n server_name: Optional[str] = None\n \n session_ticket: Optional[SessionTicket] = None\n \n supported_versions: List[int] = field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n )\n \n at: asyncio.futures\n Future(*, loop: Optional[AbstractEventLoop]=...)\n Future = _CFuture = _asyncio.Future\n \n at: examples.http3_client\n HttpConnection = Union[H0Connection, H3Connection]\n \n WebSocket(http: HttpConnection, stream_id: int, transmit: Callable[[], None])\n \n at: typing\n Deque = _alias(collections.deque, 1, name='Deque')\n \n Dict = _alias(dict, 2, inst=False, name='Dict')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + class H3Event:\n + \"\"\"\n + Base class for HTTP/3 events.\n + \"\"\"\n + \n===========changed ref 1===========\n # module: aioquic.h3.events\n - class HttpEvent:\n - \"\"\"\n - Base class for HTTP/3 events.\n - \"\"\"\n - \n - pass\n - \n===========changed ref 2===========\n # module: aioquic.h0.connection\n class H0Connection:\n + def handle_event(self, event: QuicEvent) -> List[H3Event]:\n - def handle_event(self, event: QuicEvent) -> List[HttpEvent]:\n + http_events: List[H3Event] = []\n - http_events: List[HttpEvent] = []\n \n if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0:\n data = event.data\n if not self._headers_received.get(event.stream_id, False):\n if self._is_client:\n http_events.append(\n HeadersReceived(\n headers=[], stream_ended=False, stream_id=event.stream_id\n )\n )\n else:\n method, path = data.rstrip().split(b\" \", 1)\n http_events.append(\n HeadersReceived(\n headers=[(b\":method\", method), (b\":path\", path)],\n stream_ended=False,\n stream_id=event.stream_id,\n )\n )\n data = b\"\"\n self._headers_received[event.stream_id] = True\n \n http_events.append(\n DataReceived(\n data=data, stream_ended=event.end_stream, stream_id=event.stream_id\n )\n )\n \n return http_events\n \n===========changed ref 3===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_push_frame(\n self,\n frame_type: int,\n frame_data: bytes,\n push_id: int,\n stream_id: int,\n stream_ended: bool,\n + ) -> List[H3Event]:\n - ) -> List[HttpEvent]:\n \"\"\"\n Handle a frame received on a push stream.\n \"\"\"\n + http_events: List[H3Event] = []\n - http_events: List[HttpEvent] = []\n \n if frame_type == FrameType.DATA:\n http_events.append(\n DataReceived(\n data=frame_data,\n push_id=push_id,\n stream_ended=stream_ended,\n stream_id=stream_id,\n )\n )\n elif frame_type == FrameType.HEADERS:\n headers = self._decode_headers(stream_id, frame_data)\n http_events.append(\n HeadersReceived(\n headers=headers,\n push_id=push_id,\n stream_id=stream_id,\n stream_ended=stream_ended,\n )\n )\n elif frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.PUSH_PROMISE,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n FrameType.DUPLICATE_PUSH,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on push stream\",\n )\n \n return http_events\n \n===========changed ref 4===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n + ) -> List[H3Event]:\n - ) -> List[HttpEvent]:\n + http_events: List[H3Event] = []\n - http_events: List[HttpEvent] = []\n \n stream = self._stream[stream_id]\n stream.buffer += data\n if stream_ended:\n stream.ended = True\n \n buf = Buffer(data=stream.buffer)\n consumed = 0\n unblocked_streams: Set[int] = set()\n \n while not buf.eof():\n # fetch stream type for unidirectional streams\n if stream.stream_type is None:\n try:\n stream.stream_type = buf.pull_uint_var()\n except BufferReadError:\n break\n consumed = buf.tell()\n \n # check unicity\n if stream.stream_type == StreamType.CONTROL:\n assert self._peer_control_stream_id is None\n self._peer_control_stream_id = stream_id\n elif stream.stream_type == StreamType.QPACK_DECODER:\n assert self._peer_decoder_stream_id is None\n self._peer_decoder_stream_id = stream_id\n elif stream.stream_type == StreamType.QPACK_ENCODER:\n assert self._peer_encoder_stream_id is None\n self._peer_encoder_stream_id = stream_id\n \n if stream.stream_type == StreamType.CONTROL:\n # fetch next frame\n try:\n frame_type = buf.pull_uint_var()\n frame_length = buf.pull_uint_var()\n frame_data = buf.pull_bytes(frame_length)\n except BufferReadError:\n break\n consumed = buf.tell()\n \n self._handle_control_frame(frame_type, frame_data)\n elif stream.stream_type == StreamType.PUSH:\n # fetch push id\n "}}},{"rowIdx":3446,"cells":{"path":{"kind":"string","value":"examples.http3_client/HttpClient.get"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"d290ebea69fdddd2d4afb594a8a312fa5f95d71f"},"commit_message":{"kind":"string","value":"[h3] rename HttpEvent to H3Event"},"ground_truth":{"kind":"string","value":"<11>: (b\"user-agent\", b\"aioquic\"),\n"},"main_code":{"kind":"string","value":" # module: examples.http3_client\n class HttpClient(QuicConnectionProtocol):\n + def get(self, authority: str, path: str) -> Deque[H3Event]:\n - def get(self, authority: str, path: str) -> Deque[HttpEvent]:\n <0> \"\"\"\n <1> Perform a GET request.\n <2> \"\"\"\n <3> stream_id = self._quic.get_next_available_stream_id()\n <4> self._http.send_headers(\n <5> stream_id=stream_id,\n <6> headers=[\n <7> (b\":method\", b\"GET\"),\n <8> (b\":scheme\", b\"https\"),\n <9> (b\":authority\", authority.encode(\"utf8\")),\n<10> (b\":path\", path.encode(\"utf8\")),\n<11> ],\n<12> )\n<13> self._http.send_data(stream_id=stream_id, data=b\"\", end_stream=True)\n<14> \n<15> waiter = self._loop.create_future()\n<16> self._request_events[stream_id] = deque()\n<17> self._request_waiter[stream_id] = waiter\n<18> self.transmit()\n<19> \n<20> return await asyncio.shield(waiter)\n<21> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.asyncio.protocol.QuicConnectionProtocol\n transmit() -> None\n \n at: aioquic.asyncio.protocol.QuicConnectionProtocol.__init__\n self._loop = loop\n \n self._quic = quic\n \n at: aioquic.h0.connection.H0Connection\n send_data(stream_id: int, data: bytes, end_stream: bool) -> None\n \n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.connection.H3Connection\n send_data(stream_id: int, data: bytes, end_stream: bool) -> None\n \n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.events\n H3Event()\n \n at: aioquic.quic.connection.QuicConnection\n get_next_available_stream_id(is_unidirectional=False) -> int\n \n at: asyncio.events.AbstractEventLoop\n create_future() -> Future[Any]\n \n at: collections\n deque(iterable: Iterable[_T]=..., maxlen: Optional[int]=...)\n \n at: examples.http3_client.HttpClient.__init__\n self._http = H3Connection(self._quic)\n self._http: Optional[HttpConnection] = None\n self._http = H0Connection(self._quic)\n \n self._request_events: Dict[int, Deque[H3Event]] = {}\n \n self._request_waiter: Dict[int, asyncio.Future[Deque[H3Event]]] = {}\n \n at: typing\n Deque = _alias(collections.deque, 1, name='Deque')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + class H3Event:\n + \"\"\"\n + Base class for HTTP/3 events.\n + \"\"\"\n + \n===========changed ref 1===========\n # module: examples.http3_client\n class HttpClient(QuicConnectionProtocol):\n def __init__(self, *args, **kwargs):\n super().__init__(*args, **kwargs)\n \n self._http: Optional[HttpConnection] = None\n + self._request_events: Dict[int, Deque[H3Event]] = {}\n - self._request_events: Dict[int, Deque[HttpEvent]] = {}\n + self._request_waiter: Dict[int, asyncio.Future[Deque[H3Event]]] = {}\n - self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {}\n self._websockets: Dict[int, WebSocket] = {}\n \n if self._quic.configuration.alpn_protocols[0].startswith(\"hq-\"):\n self._http = H0Connection(self._quic)\n else:\n self._http = H3Connection(self._quic)\n \n===========changed ref 2===========\n # module: aioquic.h3.events\n - class HttpEvent:\n - \"\"\"\n - Base class for HTTP/3 events.\n - \"\"\"\n - \n - pass\n - \n===========changed ref 3===========\n # module: aioquic.h0.connection\n class H0Connection:\n + def handle_event(self, event: QuicEvent) -> List[H3Event]:\n - def handle_event(self, event: QuicEvent) -> List[HttpEvent]:\n + http_events: List[H3Event] = []\n - http_events: List[HttpEvent] = []\n \n if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0:\n data = event.data\n if not self._headers_received.get(event.stream_id, False):\n if self._is_client:\n http_events.append(\n HeadersReceived(\n headers=[], stream_ended=False, stream_id=event.stream_id\n )\n )\n else:\n method, path = data.rstrip().split(b\" \", 1)\n http_events.append(\n HeadersReceived(\n headers=[(b\":method\", method), (b\":path\", path)],\n stream_ended=False,\n stream_id=event.stream_id,\n )\n )\n data = b\"\"\n self._headers_received[event.stream_id] = True\n \n http_events.append(\n DataReceived(\n data=data, stream_ended=event.end_stream, stream_id=event.stream_id\n )\n )\n \n return http_events\n \n===========changed ref 4===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_push_frame(\n self,\n frame_type: int,\n frame_data: bytes,\n push_id: int,\n stream_id: int,\n stream_ended: bool,\n + ) -> List[H3Event]:\n - ) -> List[HttpEvent]:\n \"\"\"\n Handle a frame received on a push stream.\n \"\"\"\n + http_events: List[H3Event] = []\n - http_events: List[HttpEvent] = []\n \n if frame_type == FrameType.DATA:\n http_events.append(\n DataReceived(\n data=frame_data,\n push_id=push_id,\n stream_ended=stream_ended,\n stream_id=stream_id,\n )\n )\n elif frame_type == FrameType.HEADERS:\n headers = self._decode_headers(stream_id, frame_data)\n http_events.append(\n HeadersReceived(\n headers=headers,\n push_id=push_id,\n stream_id=stream_id,\n stream_ended=stream_ended,\n )\n )\n elif frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.PUSH_PROMISE,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n FrameType.DUPLICATE_PUSH,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on push stream\",\n )\n \n return http_events\n "}}},{"rowIdx":3447,"cells":{"path":{"kind":"string","value":"examples.httpx_client/H3Dispatcher.__init__"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"d290ebea69fdddd2d4afb594a8a312fa5f95d71f"},"commit_message":{"kind":"string","value":"[h3] rename HttpEvent to H3Event"},"ground_truth":{"kind":"string","value":" <3>: self._request_events: Dict[int, Deque[H3Event]] = {}\n self._request_events: Dict[int, Deque[HttpEvent]] = {}\n <4>: self._request_waiter: Dict[int, asyncio.Future[Deque[H3Event]]] = {}\n self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {}\n"},"main_code":{"kind":"string","value":" # module: examples.httpx_client\n class H3Dispatcher(QuicConnectionProtocol, AsyncDispatcher):\n def __init__(self, *args, **kwargs):\n <0> super().__init__(*args, **kwargs)\n <1> \n <2> self._http = H3Connection(self._quic)\n <3> self._request_events: Dict[int, Deque[HttpEvent]] = {}\n <4> self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {}\n <5> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.asyncio.protocol.QuicConnectionProtocol\n __init__(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None)\n __init__(self, quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None)\n \n at: aioquic.asyncio.protocol.QuicConnectionProtocol.__init__\n self._quic = quic\n \n at: aioquic.h3.connection\n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.events\n H3Event()\n \n at: asyncio.futures\n Future(*, loop: Optional[AbstractEventLoop]=...)\n Future = _CFuture = _asyncio.Future\n \n at: typing\n Deque = _alias(collections.deque, 1, name='Deque')\n \n Dict = _alias(dict, 2, inst=False, name='Dict')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.events\n + class H3Event:\n + \"\"\"\n + Base class for HTTP/3 events.\n + \"\"\"\n + \n===========changed ref 1===========\n # module: aioquic.h3.events\n - class HttpEvent:\n - \"\"\"\n - Base class for HTTP/3 events.\n - \"\"\"\n - \n - pass\n - \n===========changed ref 2===========\n # module: examples.http3_client\n class HttpClient(QuicConnectionProtocol):\n def __init__(self, *args, **kwargs):\n super().__init__(*args, **kwargs)\n \n self._http: Optional[HttpConnection] = None\n + self._request_events: Dict[int, Deque[H3Event]] = {}\n - self._request_events: Dict[int, Deque[HttpEvent]] = {}\n + self._request_waiter: Dict[int, asyncio.Future[Deque[H3Event]]] = {}\n - self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {}\n self._websockets: Dict[int, WebSocket] = {}\n \n if self._quic.configuration.alpn_protocols[0].startswith(\"hq-\"):\n self._http = H0Connection(self._quic)\n else:\n self._http = H3Connection(self._quic)\n \n===========changed ref 3===========\n # module: examples.http3_client\n class HttpClient(QuicConnectionProtocol):\n + def get(self, authority: str, path: str) -> Deque[H3Event]:\n - def get(self, authority: str, path: str) -> Deque[HttpEvent]:\n \"\"\"\n Perform a GET request.\n \"\"\"\n stream_id = self._quic.get_next_available_stream_id()\n self._http.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", authority.encode(\"utf8\")),\n (b\":path\", path.encode(\"utf8\")),\n + (b\"user-agent\", b\"aioquic\"),\n ],\n )\n self._http.send_data(stream_id=stream_id, data=b\"\", end_stream=True)\n \n waiter = self._loop.create_future()\n self._request_events[stream_id] = deque()\n self._request_waiter[stream_id] = waiter\n self.transmit()\n \n return await asyncio.shield(waiter)\n \n===========changed ref 4===========\n # module: aioquic.h0.connection\n class H0Connection:\n + def handle_event(self, event: QuicEvent) -> List[H3Event]:\n - def handle_event(self, event: QuicEvent) -> List[HttpEvent]:\n + http_events: List[H3Event] = []\n - http_events: List[HttpEvent] = []\n \n if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0:\n data = event.data\n if not self._headers_received.get(event.stream_id, False):\n if self._is_client:\n http_events.append(\n HeadersReceived(\n headers=[], stream_ended=False, stream_id=event.stream_id\n )\n )\n else:\n method, path = data.rstrip().split(b\" \", 1)\n http_events.append(\n HeadersReceived(\n headers=[(b\":method\", method), (b\":path\", path)],\n stream_ended=False,\n stream_id=event.stream_id,\n )\n )\n data = b\"\"\n self._headers_received[event.stream_id] = True\n \n http_events.append(\n DataReceived(\n data=data, stream_ended=event.end_stream, stream_id=event.stream_id\n )\n )\n \n return http_events\n \n===========changed ref 5===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_push_frame(\n self,\n frame_type: int,\n frame_data: bytes,\n push_id: int,\n stream_id: int,\n stream_ended: bool,\n + ) -> List[H3Event]:\n - ) -> List[HttpEvent]:\n \"\"\"\n Handle a frame received on a push stream.\n \"\"\"\n + http_events: List[H3Event] = []\n - http_events: List[HttpEvent] = []\n \n if frame_type == FrameType.DATA:\n http_events.append(\n DataReceived(\n data=frame_data,\n push_id=push_id,\n stream_ended=stream_ended,\n stream_id=stream_id,\n )\n )\n elif frame_type == FrameType.HEADERS:\n headers = self._decode_headers(stream_id, frame_data)\n http_events.append(\n HeadersReceived(\n headers=headers,\n push_id=push_id,\n stream_id=stream_id,\n stream_ended=stream_ended,\n )\n )\n elif frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.PUSH_PROMISE,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n FrameType.DUPLICATE_PUSH,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on push stream\",\n )\n \n return http_events\n "}}},{"rowIdx":3448,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Stream.__init__"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"2fe6a3623f9ee69fa9c0d718d723a28ee48ec289"},"commit_message":{"kind":"string","value":"[http3] validate state in which headers and data are received"},"ground_truth":{"kind":"string","value":" <5>: self.headers_state: HeadersState = HeadersState.INITIAL\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Stream:\n def __init__(self) -> None:\n <0> self.blocked = False\n <1> self.buffer = b\"\"\n <2> self.ended = False\n <3> self.frame_size: Optional[int] = None\n <4> self.frame_type: Optional[int] = None\n <5> self.push_id: Optional[int] = None\n <6> self.stream_type: Optional[int] = None\n <7> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic._buffer.Buffer\n pull_uint_var() -> int\n \n at: aioquic.h3.connection.parse_settings\n buf = Buffer(data=data)\n \n settings = []\n \n setting = buf.pull_uint_var()\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n + class HeadersState(Enum):\n + INITIAL = 0\n + AFTER_HEADERS = 1\n + AFTER_TRAILERS = 2\n + "}}},{"rowIdx":3449,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_stream_data_bidi"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"2fe6a3623f9ee69fa9c0d718d723a28ee48ec289"},"commit_message":{"kind":"string","value":"[http3] validate state in which headers and data are received"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n <0> \"\"\"\n <1> Client-initiated bidirectional streams carry requests and responses.\n <2> \"\"\"\n <3> http_events: List[H3Event] = []\n <4> \n <5> stream = self._stream[stream_id]\n <6> stream.buffer += data\n <7> if stream_ended:\n <8> stream.ended = True\n <9> if stream.blocked:\n<10> return http_events\n<11> \n<12> # shortcut DATA frame bits\n<13> if (\n<14> stream.frame_type == FrameType.DATA\n<15> and stream.frame_size is not None\n<16> and len(stream.buffer) < stream.frame_size\n<17> ):\n<18> http_events.append(\n<19> DataReceived(\n<20> data=stream.buffer, stream_id=stream_id, stream_ended=False\n<21> )\n<22> )\n<23> stream.frame_size -= len(stream.buffer)\n<24> stream.buffer = b\"\"\n<25> return http_events\n<26> \n<27> # some peers (e.g. f5) end the stream with no data\n<28> if stream_ended and not stream.buffer:\n<29> http_events.append(\n<30> DataReceived(data=b\"\", stream_id=stream_id, stream_ended=True)\n<31> )\n<32> return http_events\n<33> \n<34> buf = Buffer(data=stream.buffer)\n<35> consumed = 0\n<36> \n<37> while not buf.eof():\n<38> # fetch next frame header\n<39> if stream.frame_size is None:\n<40> try:\n<41> stream.frame_type = buf.pull_uint_var()\n<42> stream.frame_size = buf.pull_uint_var()\n<43> except BufferReadError:\n<44> break\n<45> consumed = buf.tell()\n<46> \n<47> # check how much data is available\n<48> chunk_size = min(stream.frame_size, buf.capacity"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 1\n if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size:\n break\n \n # read available data\n frame_data = buf.pull_bytes(chunk_size)\n consumed = buf.tell()\n \n # detect end of frame\n stream.frame_size -= chunk_size\n if not stream.frame_size:\n stream.frame_size = None\n \n if stream.frame_type == FrameType.DATA and (stream_ended or frame_data):\n http_events.append(\n DataReceived(\n data=frame_data,\n stream_id=stream_id,\n stream_ended=stream_ended and buf.eof(),\n )\n )\n elif stream.frame_type == FrameType.HEADERS:\n try:\n headers = self._decode_headers(stream_id, frame_data)\n except StreamBlocked:\n stream.blocked = True\n break\n http_events.append(\n HeadersReceived(\n headers=headers,\n stream_id=stream_id,\n stream_ended=stream_ended and buf.eof(),\n )\n )\n elif stream.frame_type == FrameType.PUSH_PROMISE:\n if not self._is_client:\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n frame_type=None,\n reason_phrase=\"Clients must not send PUSH_PROMISE\",\n )\n frame_buf = Buffer(data=frame_data)\n push_id = frame_buf.pull_uint_var()\n headers = self._decode_headers(\n stream_id, frame_data[frame_buf.tell() :]\n )\n http_events.append(\n PushPromiseReceived(\n headers=headers, push_id=push_id, stream_id=stream_id\n===========below chunk 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 2\n .append(\n PushPromiseReceived(\n headers=headers, push_id=push_id, stream_id=stream_id\n )\n )\n elif stream.frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on request stream\",\n )\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n Setting(x: Union[str, bytes, bytearray], base: int)\n Setting(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n encode_settings(settings: Dict[int, int]) -> bytes\n \n at: aioquic.h3.connection.H3Connection\n _create_uni_stream(stream_type: int) -> int\n \n _handle_request_or_push_frame(frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[H3Event]\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._max_table_capacity = 0x100\n \n self._blocked_streams = 0x10\n \n self._is_client = quic.configuration.is_client\n \n self._quic = quic\n \n \n===========unchanged ref 1===========\n self._stream: Dict[int, H3Stream] = {}\n \n self._max_push_id: Optional[int] = 8 if self._is_client else None\n \n self._local_control_stream_id: Optional[int] = None\n \n self._local_decoder_stream_id: Optional[int] = None\n \n self._local_encoder_stream_id: Optional[int] = None\n \n at: aioquic.h3.connection.H3Connection._handle_control_frame\n self._max_push_id = parse_max_push_id(frame_data)\n \n at: aioquic.h3.connection.H3Connection._handle_request_or_push_frame\n http_events: List[H3Event] = []\n \n at: aioquic.h3.connection.H3Stream.__init__\n self.blocked = False\n \n self.buffer = b\"\"\n \n self.ended = False\n \n self.frame_size: Optional[int] = None\n \n self.frame_type: Optional[int] = None\n \n at: aioquic.h3.events\n H3Event()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.h3.events.DataReceived\n data: bytes\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.quic.connection\n QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)\n \n at: aioquic.quic.connection.QuicConnection\n send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n "}}},{"rowIdx":3450,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_stream_data_uni"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"2fe6a3623f9ee69fa9c0d718d723a28ee48ec289"},"commit_message":{"kind":"string","value":"[http3] validate state in which headers and data are received"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n <0> http_events: List[H3Event] = []\n <1> \n <2> stream = self._stream[stream_id]\n <3> stream.buffer += data\n <4> if stream_ended:\n <5> stream.ended = True\n <6> \n <7> buf = Buffer(data=stream.buffer)\n <8> consumed = 0\n <9> unblocked_streams: Set[int] = set()\n<10> \n<11> while not buf.eof():\n<12> # fetch stream type for unidirectional streams\n<13> if stream.stream_type is None:\n<14> try:\n<15> stream.stream_type = buf.pull_uint_var()\n<16> except BufferReadError:\n<17> break\n<18> consumed = buf.tell()\n<19> \n<20> # check unicity\n<21> if stream.stream_type == StreamType.CONTROL:\n<22> assert self._peer_control_stream_id is None\n<23> self._peer_control_stream_id = stream_id\n<24> elif stream.stream_type == StreamType.QPACK_DECODER:\n<25> assert self._peer_decoder_stream_id is None\n<26> self._peer_decoder_stream_id = stream_id\n<27> elif stream.stream_type == StreamType.QPACK_ENCODER:\n<28> assert self._peer_encoder_stream_id is None\n<29> self._peer_encoder_stream_id = stream_id\n<30> \n<31> if stream.stream_type == StreamType.CONTROL:\n<32> # fetch next frame\n<33> try:\n<34> frame_type = buf.pull_uint_var()\n<35> frame_length = buf.pull_uint_var()\n<36> frame_data = buf.pull_bytes(frame_length)\n<37> except BufferReadError:\n<38> break\n<39> consumed = buf.tell()\n<40> \n<41> self._handle_control_frame(frame_type, frame_data)\n<42> elif stream."},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 1\n # fetch push id\n if stream.push_id is None:\n try:\n stream.push_id = buf.pull_uint_var()\n except BufferReadError:\n break\n consumed = buf.tell()\n \n # fetch next frame\n try:\n frame_type = buf.pull_uint_var()\n frame_length = buf.pull_uint_var()\n frame_data = buf.pull_bytes(frame_length)\n except BufferReadError:\n break\n consumed = buf.tell()\n \n http_events.extend(\n self._handle_push_frame(\n frame_type=frame_type,\n frame_data=frame_data,\n push_id=stream.push_id,\n stream_id=stream_id,\n stream_ended=stream.ended and buf.eof(),\n )\n )\n elif stream.stream_type == StreamType.QPACK_DECODER:\n # feed unframed data to decoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n self._encoder.feed_decoder(data)\n elif stream.stream_type == StreamType.QPACK_ENCODER:\n # feed unframed data to encoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n unblocked_streams.update(self._decoder.feed_encoder(data))\n else:\n # unknown stream type, discard data\n buf.seek(buf.capacity)\n consumed = buf.tell()\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n # process unblocked streams\n for stream_id in unblocked_streams:\n stream = self._stream[stream_id]\n decoder,\n===========below chunk 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 2\n blocked streams\n for stream_id in unblocked_streams:\n stream = self._stream[stream_id]\n decoder, headers = self._decoder.resume_header(stream_id)\n stream.blocked = False\n http_events.append(\n HeadersReceived(\n headers=headers,\n stream_id=stream_id,\n stream_ended=stream.ended and not stream.buffer,\n )\n )\n http_events.extend(\n self._receive_stream_data_bidi(stream_id, b\"\", stream.ended)\n )\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n at: aioquic.h3.connection.H3Connection\n _handle_control_frame(frame_type: int, frame_data: bytes) -> None\n \n _handle_request_or_push_frame(frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[H3Event]\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._encoder = Encoder()\n \n self._stream: Dict[int, H3Stream] = {}\n \n self._peer_control_stream_id: Optional[int] = None\n \n self._peer_decoder_stream_id: Optional[int] = None\n \n self._peer_encoder_stream_id: Optional[int] = None\n \n at: aioquic.h3.connection.H3Connection._receive_stream_data_bidi\n http_events: List[H3Event] = []\n \n stream = self._stream[stream_id]\n \n consumed = buf.tell()\n consumed = 0\n \n at: aioquic.h3.events\n H3Event()\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n Set = _alias(set, 1, inst=False, name='Set')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n + def _handle_request_or_push_frame(\n + self,\n + frame_type: int,\n + frame_data: bytes,\n + push_id: int,\n + stream_id: int,\n + stream_ended: bool,\n + ) -> List[H3Event]:\n + \"\"\"\n + Handle a frame received on a push stream.\n + \"\"\"\n + http_events: List[H3Event] = []\n + stream = self._stream[stream_id]\n + \n + if frame_type == FrameType.DATA:\n + # check DATA frame is allowed\n + if stream.headers_state != HeadersState.AFTER_HEADERS:\n + raise QuicConnectionError(\n + error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n + frame_type=None,\n + reason_phrase=\"DATA frame is not allowed in this state\",\n + )\n + \n + if stream_ended or frame_data:\n + http_events.append(\n + DataReceived(\n + data=frame_data,\n + push_id=push_id,\n + stream_ended=stream_ended,\n + stream_id=stream_id,\n + )\n + )\n + elif frame_type == FrameType.HEADERS:\n + # check HEADERS frame is allowed\n + if stream.headers_state == HeadersState.AFTER_TRAILERS:\n + raise QuicConnectionError(\n + error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n + frame_type=None,\n + reason_phrase=\"HEADERS frame is not allowed in this state\",\n + )\n + \n + # try to decode HEADERS\n + headers = self._decode_headers(stream_id, frame_data)\n + \n + # update state and emit headers\n + if stream.headers_state == HeadersState.INITIAL:\n + stream.headers_state = HeadersState.AFTER_HEADERS\n + else:\n + stream.headers_state = HeadersState.AFTER_TRAILERS\n + http_events.append("}}},{"rowIdx":3451,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_stream_data_uni"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"799c6172486cec794209a6e8e0b0d077d5ff03e6"},"commit_message":{"kind":"string","value":"[http3] send out decoder stream updates after unblocking stream"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n <0> http_events: List[H3Event] = []\n <1> \n <2> stream = self._stream[stream_id]\n <3> stream.buffer += data\n <4> if stream_ended:\n <5> stream.ended = True\n <6> \n <7> buf = Buffer(data=stream.buffer)\n <8> consumed = 0\n <9> unblocked_streams: Set[int] = set()\n<10> \n<11> while not buf.eof():\n<12> # fetch stream type for unidirectional streams\n<13> if stream.stream_type is None:\n<14> try:\n<15> stream.stream_type = buf.pull_uint_var()\n<16> except BufferReadError:\n<17> break\n<18> consumed = buf.tell()\n<19> \n<20> # check unicity\n<21> if stream.stream_type == StreamType.CONTROL:\n<22> assert self._peer_control_stream_id is None\n<23> self._peer_control_stream_id = stream_id\n<24> elif stream.stream_type == StreamType.QPACK_DECODER:\n<25> assert self._peer_decoder_stream_id is None\n<26> self._peer_decoder_stream_id = stream_id\n<27> elif stream.stream_type == StreamType.QPACK_ENCODER:\n<28> assert self._peer_encoder_stream_id is None\n<29> self._peer_encoder_stream_id = stream_id\n<30> \n<31> if stream.stream_type == StreamType.CONTROL:\n<32> # fetch next frame\n<33> try:\n<34> frame_type = buf.pull_uint_var()\n<35> frame_length = buf.pull_uint_var()\n<36> frame_data = buf.pull_bytes(frame_length)\n<37> except BufferReadError:\n<38> break\n<39> consumed = buf.tell()\n<40> \n<41> self._handle_control_frame(frame_type, frame_data)\n<42> elif stream."},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 1\n # fetch push id\n if stream.push_id is None:\n try:\n stream.push_id = buf.pull_uint_var()\n except BufferReadError:\n break\n consumed = buf.tell()\n \n # fetch next frame\n try:\n frame_type = buf.pull_uint_var()\n frame_length = buf.pull_uint_var()\n frame_data = buf.pull_bytes(frame_length)\n except BufferReadError:\n break\n consumed = buf.tell()\n \n http_events.extend(\n self._handle_request_or_push_frame(\n frame_type=frame_type,\n frame_data=frame_data,\n push_id=stream.push_id,\n stream_id=stream_id,\n stream_ended=stream.ended and buf.eof(),\n )\n )\n elif stream.stream_type == StreamType.QPACK_DECODER:\n # feed unframed data to decoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n self._encoder.feed_decoder(data)\n elif stream.stream_type == StreamType.QPACK_ENCODER:\n # feed unframed data to encoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n unblocked_streams.update(self._decoder.feed_encoder(data))\n else:\n # unknown stream type, discard data\n buf.seek(buf.capacity)\n consumed = buf.tell()\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n # process unblocked streams\n for stream_id in unblocked_streams:\n stream = self._stream[stream_id]\n===========below chunk 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 2\n # process unblocked streams\n for stream_id in unblocked_streams:\n stream = self._stream[stream_id]\n decoder, headers = self._decoder.resume_header(stream_id)\n stream.blocked = False\n \n # update state and emit headers\n if stream.headers_state == HeadersState.INITIAL:\n stream.headers_state = HeadersState.AFTER_HEADERS\n else:\n stream.headers_state = HeadersState.AFTER_TRAILERS\n http_events.append(\n HeadersReceived(\n headers=headers,\n stream_id=stream_id,\n stream_ended=stream.ended and not stream.buffer,\n )\n )\n \n # resume processing\n if stream.buffer:\n http_events.extend(\n self._receive_stream_data_bidi(stream_id, b\"\", stream.ended)\n )\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n HeadersState()\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n at: aioquic.h3.connection.H3Connection\n _handle_control_frame(frame_type: int, frame_data: bytes) -> None\n \n _handle_request_or_push_frame(frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[H3Event]\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._encoder = Encoder()\n \n self._stream: Dict[int, H3Stream] = {}\n \n self._peer_control_stream_id: Optional[int] = None\n \n self._peer_decoder_stream_id: Optional[int] = None\n \n self._peer_encoder_stream_id: Optional[int] = None\n \n at: aioquic.h3.connection.H3Stream.__init__\n self.buffer = b\"\"\n \n self.ended = False\n \n self.push_id: Optional[int] = None\n \n self.stream_type: Optional[int] = None\n \n at: aioquic.h3.events\n H3Event()\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n Set = _alias(set, 1, inst=False, name='Set')\n \n "}}},{"rowIdx":3452,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._handle_request_or_push_frame"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"40dde6efab7ee6a9e05bd06a4d6393681d46e5e7"},"commit_message":{"kind":"string","value":"[http3] ensure stream_ended is propagated for server push"},"ground_truth":{"kind":"string","value":"<19>: push_id=stream.push_id,\n push_id=push_id,\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _handle_request_or_push_frame(\n - self,\n - frame_type: int,\n - frame_data: bytes,\n - push_id: int,\n - stream_id: int,\n - stream_ended: bool,\n + self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool\n ) -> List[H3Event]:\n <0> \"\"\"\n <1> Handle a frame received on a push stream.\n <2> \"\"\"\n <3> http_events: List[H3Event] = []\n <4> stream = self._stream[stream_id]\n <5> \n <6> if frame_type == FrameType.DATA:\n <7> # check DATA frame is allowed\n <8> if stream.headers_state != HeadersState.AFTER_HEADERS:\n <9> raise QuicConnectionError(\n<10> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n<11> frame_type=None,\n<12> reason_phrase=\"DATA frame is not allowed in this state\",\n<13> )\n<14> \n<15> if stream_ended or frame_data:\n<16> http_events.append(\n<17> DataReceived(\n<18> data=frame_data,\n<19> push_id=push_id,\n<20> stream_ended=stream_ended,\n<21> stream_id=stream_id,\n<22> )\n<23> )\n<24> elif frame_type == FrameType.HEADERS:\n<25> # check HEADERS frame is allowed\n<26> if stream.headers_state == HeadersState.AFTER_TRAILERS:\n<27> raise QuicConnectionError(\n<28> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n<29> frame_type=None,\n<30> reason_phrase=\"HEADERS frame is not allowed in this state\",\n<31> )\n<32> \n<33> # try to decode HEADERS\n<34> headers = self._decode_headers(stream_id, frame_data)\n<35> \n<36> # update state and emit headers\n<37> if stream.headers_state == HeadersState.INITIAL:\n<38> stream.headers_state = HeadersState.AFTER_HEADERS\n<39> else:"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_request_or_push_frame(\n - self,\n - frame_type: int,\n - frame_data: bytes,\n - push_id: int,\n - stream_id: int,\n - stream_ended: bool,\n + self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 1\n http_events.append(\n HeadersReceived(\n headers=headers,\n push_id=push_id,\n stream_id=stream_id,\n stream_ended=stream_ended,\n )\n )\n elif stream.frame_type == FrameType.PUSH_PROMISE and push_id is None:\n if not self._is_client:\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n frame_type=None,\n reason_phrase=\"Clients must not send PUSH_PROMISE\",\n )\n frame_buf = Buffer(data=frame_data)\n push_id = frame_buf.pull_uint_var()\n headers = self._decode_headers(stream_id, frame_data[frame_buf.tell() :])\n http_events.append(\n PushPromiseReceived(\n headers=headers, push_id=push_id, stream_id=stream_id\n )\n )\n elif frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.PUSH_PROMISE,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n FrameType.DUPLICATE_PUSH,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on push stream\",\n )\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n tell() -> int\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n HeadersState()\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n at: aioquic.h3.connection.H3Connection\n _create_uni_stream(stream_type: int) -> int\n \n _decode_headers(stream_id: int, frame_data: bytes) -> Headers\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._is_client = quic.configuration.is_client\n \n self._quic = quic\n \n self._stream: Dict[int, H3Stream] = {}\n \n self._local_control_stream_id: Optional[int] = None\n \n at: aioquic.h3.connection.H3Stream.__init__\n self.frame_type: Optional[int] = None\n \n self.headers_state: HeadersState = HeadersState.INITIAL\n \n self.push_id: Optional[int] = None\n \n at: aioquic.h3.events\n H3Event()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n \n===========unchanged ref 1===========\n PushPromiseReceived(headers: Headers, push_id: int, stream_id: int)\n \n at: aioquic.h3.events.DataReceived\n data: bytes\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.HeadersReceived\n headers: Headers\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.PushPromiseReceived\n headers: Headers\n \n push_id: int\n \n stream_id: int\n \n at: aioquic.quic.connection\n QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)\n \n at: aioquic.quic.connection.QuicConnection\n send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n "}}},{"rowIdx":3453,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_stream_data_bidi"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"40dde6efab7ee6a9e05bd06a4d6393681d46e5e7"},"commit_message":{"kind":"string","value":"[http3] ensure stream_ended is propagated for server push"},"ground_truth":{"kind":"string","value":"<12>: # shortcut for DATA frame fragments\n # shortcut DATA frame bits\n<20>: data=stream.buffer,\n push_id=stream.push_id,\n stream_id=stream_id,\n stream_ended=False,\n data=stream.buffer, stream_id=stream_id, stream_ended=False\n<27>: # handle lone FIN\n # some peers (e.g. f5) end the stream with no data\n<30>: DataReceived(\n data=b\"\",\n push_id=stream.push_id,\n stream_id=stream_id,\n stream_ended=True,\n )\n DataReceived(data=b\"\", stream_id=stream_id, stream_ended=True)\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n <0> \"\"\"\n <1> Client-initiated bidirectional streams carry requests and responses.\n <2> \"\"\"\n <3> http_events: List[H3Event] = []\n <4> \n <5> stream = self._stream[stream_id]\n <6> stream.buffer += data\n <7> if stream_ended:\n <8> stream.ended = True\n <9> if stream.blocked:\n<10> return http_events\n<11> \n<12> # shortcut DATA frame bits\n<13> if (\n<14> stream.frame_type == FrameType.DATA\n<15> and stream.frame_size is not None\n<16> and len(stream.buffer) < stream.frame_size\n<17> ):\n<18> http_events.append(\n<19> DataReceived(\n<20> data=stream.buffer, stream_id=stream_id, stream_ended=False\n<21> )\n<22> )\n<23> stream.frame_size -= len(stream.buffer)\n<24> stream.buffer = b\"\"\n<25> return http_events\n<26> \n<27> # some peers (e.g. f5) end the stream with no data\n<28> if stream_ended and not stream.buffer:\n<29> http_events.append(\n<30> DataReceived(data=b\"\", stream_id=stream_id, stream_ended=True)\n<31> )\n<32> return http_events\n<33> \n<34> buf = Buffer(data=stream.buffer)\n<35> consumed = 0\n<36> \n<37> while not buf.eof():\n<38> # fetch next frame header\n<39> if stream.frame_size is None:\n<40> try:\n<41> stream.frame_type = buf.pull_uint_var()\n<42> stream.frame_size = buf.pull_uint_var()\n<43> except BufferReadError:\n<44> break\n<45> consumed = buf.tell()\n<46> \n<47> # check how much data is available\n<48> chunk_size = min(stream.frame_size, buf.capacity"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 1\n if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size:\n break\n \n # read available data\n frame_data = buf.pull_bytes(chunk_size)\n consumed = buf.tell()\n \n # detect end of frame\n stream.frame_size -= chunk_size\n if not stream.frame_size:\n stream.frame_size = None\n \n try:\n http_events.extend(\n self._handle_request_or_push_frame(\n frame_type=stream.frame_type,\n frame_data=frame_data,\n push_id=None,\n stream_id=stream_id,\n stream_ended=stream.ended and buf.eof(),\n )\n )\n except StreamBlocked:\n stream.blocked = True\n break\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n at: aioquic.h3.connection.H3Connection\n _handle_request_or_push_frame(frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool) -> List[H3Event]\n _handle_request_or_push_frame(self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool) -> List[H3Event]\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._stream: Dict[int, H3Stream] = {}\n \n at: aioquic.h3.connection.H3Stream.__init__\n self.blocked = False\n \n self.buffer = b\"\"\n \n self.ended = False\n \n self.frame_size: Optional[int] = None\n \n self.frame_type: Optional[int] = None\n \n self.push_id: Optional[int] = None\n \n at: aioquic.h3.events\n H3Event()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_request_or_push_frame(\n - self,\n - frame_type: int,\n - frame_data: bytes,\n - push_id: int,\n - stream_id: int,\n - stream_ended: bool,\n + self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool\n ) -> List[H3Event]:\n \"\"\"\n Handle a frame received on a push stream.\n \"\"\"\n http_events: List[H3Event] = []\n stream = self._stream[stream_id]\n \n if frame_type == FrameType.DATA:\n # check DATA frame is allowed\n if stream.headers_state != HeadersState.AFTER_HEADERS:\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n frame_type=None,\n reason_phrase=\"DATA frame is not allowed in this state\",\n )\n \n if stream_ended or frame_data:\n http_events.append(\n DataReceived(\n data=frame_data,\n + push_id=stream.push_id,\n - push_id=push_id,\n stream_ended=stream_ended,\n stream_id=stream_id,\n )\n )\n elif frame_type == FrameType.HEADERS:\n # check HEADERS frame is allowed\n if stream.headers_state == HeadersState.AFTER_TRAILERS:\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n frame_type=None,\n reason_phrase=\"HEADERS frame is not allowed in this state\",\n )\n \n # try to decode HEADERS\n headers = self._decode_headers(stream_id, frame_data)\n \n # update state and emit headers\n if stream.headers_state == HeadersState.INITIAL:\n stream.headers_state = HeadersState.AFTER_HEADERS\n else:\n stream.headers_state = HeadersState.AFTER_TRAILERS\n http_events.append(\n \n===========changed ref 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_request_or_push_frame(\n - self,\n - frame_type: int,\n - frame_data: bytes,\n - push_id: int,\n - stream_id: int,\n - stream_ended: bool,\n + self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 1\n \n else:\n stream.headers_state = HeadersState.AFTER_TRAILERS\n http_events.append(\n HeadersReceived(\n headers=headers,\n + push_id=stream.push_id,\n - push_id=push_id,\n stream_id=stream_id,\n stream_ended=stream_ended,\n )\n )\n + elif stream.frame_type == FrameType.PUSH_PROMISE and stream.push_id is None:\n - elif stream.frame_type == FrameType.PUSH_PROMISE and push_id is None:\n if not self._is_client:\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n frame_type=None,\n reason_phrase=\"Clients must not send PUSH_PROMISE\",\n )\n frame_buf = Buffer(data=frame_data)\n push_id = frame_buf.pull_uint_var()\n headers = self._decode_headers(stream_id, frame_data[frame_buf.tell() :])\n http_events.append(\n PushPromiseReceived(\n headers=headers, push_id=push_id, stream_id=stream_id\n )\n )\n elif frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.PUSH_PROMISE,\n FrameType.GOAWAY,\n FrameType\n===========changed ref 2===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_request_or_push_frame(\n - self,\n - frame_type: int,\n - frame_data: bytes,\n - push_id: int,\n - stream_id: int,\n - stream_ended: bool,\n + self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 2\n _PUSH_ID,\n FrameType.DUPLICATE_PUSH,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on push stream\",\n )\n \n return http_events\n "}}},{"rowIdx":3454,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_stream_data_uni"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"40dde6efab7ee6a9e05bd06a4d6393681d46e5e7"},"commit_message":{"kind":"string","value":"[http3] ensure stream_ended is propagated for server push"},"ground_truth":{"kind":"string","value":"<11>: while stream.stream_type == StreamType.PUSH or not buf.eof():\n while not buf.eof():\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n <0> http_events: List[H3Event] = []\n <1> \n <2> stream = self._stream[stream_id]\n <3> stream.buffer += data\n <4> if stream_ended:\n <5> stream.ended = True\n <6> \n <7> buf = Buffer(data=stream.buffer)\n <8> consumed = 0\n <9> unblocked_streams: Set[int] = set()\n<10> \n<11> while not buf.eof():\n<12> # fetch stream type for unidirectional streams\n<13> if stream.stream_type is None:\n<14> try:\n<15> stream.stream_type = buf.pull_uint_var()\n<16> except BufferReadError:\n<17> break\n<18> consumed = buf.tell()\n<19> \n<20> # check unicity\n<21> if stream.stream_type == StreamType.CONTROL:\n<22> assert self._peer_control_stream_id is None\n<23> self._peer_control_stream_id = stream_id\n<24> elif stream.stream_type == StreamType.QPACK_DECODER:\n<25> assert self._peer_decoder_stream_id is None\n<26> self._peer_decoder_stream_id = stream_id\n<27> elif stream.stream_type == StreamType.QPACK_ENCODER:\n<28> assert self._peer_encoder_stream_id is None\n<29> self._peer_encoder_stream_id = stream_id\n<30> \n<31> if stream.stream_type == StreamType.CONTROL:\n<32> # fetch next frame\n<33> try:\n<34> frame_type = buf.pull_uint_var()\n<35> frame_length = buf.pull_uint_var()\n<36> frame_data = buf.pull_bytes(frame_length)\n<37> except BufferReadError:\n<38> break\n<39> consumed = buf.tell()\n<40> \n<41> self._handle_control_frame(frame_type, frame_data)\n<42> elif stream."},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 1\n # fetch push id\n if stream.push_id is None:\n try:\n stream.push_id = buf.pull_uint_var()\n except BufferReadError:\n break\n consumed = buf.tell()\n \n # fetch next frame\n try:\n frame_type = buf.pull_uint_var()\n frame_length = buf.pull_uint_var()\n frame_data = buf.pull_bytes(frame_length)\n except BufferReadError:\n break\n consumed = buf.tell()\n \n http_events.extend(\n self._handle_request_or_push_frame(\n frame_type=frame_type,\n frame_data=frame_data,\n push_id=stream.push_id,\n stream_id=stream_id,\n stream_ended=stream.ended and buf.eof(),\n )\n )\n elif stream.stream_type == StreamType.QPACK_DECODER:\n # feed unframed data to decoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n self._encoder.feed_decoder(data)\n elif stream.stream_type == StreamType.QPACK_ENCODER:\n # feed unframed data to encoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n unblocked_streams.update(self._decoder.feed_encoder(data))\n else:\n # unknown stream type, discard data\n buf.seek(buf.capacity)\n consumed = buf.tell()\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n # process unblocked streams\n for stream_id in unblocked_streams:\n stream = self._stream[stream_id]\n===========below chunk 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 2\n # process unblocked streams\n for stream_id in unblocked_streams:\n stream = self._stream[stream_id]\n \n # decode headers\n decoder, headers = self._decoder.resume_header(stream_id)\n self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n stream.blocked = False\n \n # update state and emit headers\n if stream.headers_state == HeadersState.INITIAL:\n stream.headers_state = HeadersState.AFTER_HEADERS\n else:\n stream.headers_state = HeadersState.AFTER_TRAILERS\n http_events.append(\n HeadersReceived(\n headers=headers,\n stream_id=stream_id,\n stream_ended=stream.ended and not stream.buffer,\n )\n )\n \n # resume processing\n if stream.buffer:\n http_events.extend(\n self._receive_stream_data_bidi(stream_id, b\"\", stream.ended)\n )\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n HeadersState()\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n at: aioquic.h3.connection.H3Connection\n _handle_control_frame(frame_type: int, frame_data: bytes) -> None\n \n _handle_request_or_push_frame(frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool) -> List[H3Event]\n _handle_request_or_push_frame(self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool) -> List[H3Event]\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._stream: Dict[int, H3Stream] = {}\n \n self._peer_control_stream_id: Optional[int] = None\n \n self._peer_decoder_stream_id: Optional[int] = None\n \n self._peer_encoder_stream_id: Optional[int] = None\n \n at: aioquic.h3.connection.H3Connection._receive_stream_data_bidi\n http_events: List[H3Event] = []\n \n at: aioquic.h3.events\n H3Event()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n Set = _alias(set, 1, inst=False, name='Set')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_request_or_push_frame(\n - self,\n - frame_type: int,\n - frame_data: bytes,\n - push_id: int,\n - stream_id: int,\n - stream_ended: bool,\n + self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool\n ) -> List[H3Event]:\n \"\"\"\n Handle a frame received on a push stream.\n \"\"\"\n http_events: List[H3Event] = []\n stream = self._stream[stream_id]\n \n if frame_type == FrameType.DATA:\n # check DATA frame is allowed\n if stream.headers_state != HeadersState.AFTER_HEADERS:\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n frame_type=None,\n reason_phrase=\"DATA frame is not allowed in this state\",\n )\n \n if stream_ended or frame_data:\n http_events.append(\n DataReceived(\n data=frame_data,\n + push_id=stream.push_id,\n - push_id=push_id,\n stream_ended=stream_ended,\n stream_id=stream_id,\n )\n )\n elif frame_type == FrameType.HEADERS:\n # check HEADERS frame is allowed\n if stream.headers_state == HeadersState.AFTER_TRAILERS:\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n frame_type=None,\n reason_phrase=\"HEADERS frame is not allowed in this state\",\n )\n \n # try to decode HEADERS\n headers = self._decode_headers(stream_id, frame_data)\n \n # update state and emit headers\n if stream.headers_state == HeadersState.INITIAL:\n stream.headers_state = HeadersState.AFTER_HEADERS\n else:\n stream.headers_state = HeadersState.AFTER_TRAILERS\n http_events.append(\n "}}},{"rowIdx":3455,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_request_headers_only"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"40dde6efab7ee6a9e05bd06a4d6393681d46e5e7"},"commit_message":{"kind":"string","value":"[http3] ensure stream_ended is propagated for server push"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_headers_only(self):\n <0> with client_and_server(\n <1> client_options={\"alpn_protocols\": [\"h3-22\"]},\n <2> server_options={\"alpn_protocols\": [\"h3-22\"]},\n <3> ) as (quic_client, quic_server):\n <4> h3_client = H3Connection(quic_client)\n <5> h3_server = H3Connection(quic_server)\n <6> \n <7> # send request\n <8> stream_id = quic_client.get_next_available_stream_id()\n <9> h3_client.send_headers(\n<10> stream_id=stream_id,\n<11> headers=[\n<12> (b\":method\", b\"HEAD\"),\n<13> (b\":scheme\", b\"https\"),\n<14> (b\":authority\", b\"localhost\"),\n<15> (b\":path\", b\"/\"),\n<16> (b\"x-foo\", b\"client\"),\n<17> ],\n<18> end_stream=True,\n<19> )\n<20> \n<21> # receive request\n<22> events = h3_transfer(quic_client, h3_server)\n<23> self.assertEqual(\n<24> events,\n<25> [\n<26> HeadersReceived(\n<27> headers=[\n<28> (b\":method\", b\"HEAD\"),\n<29> (b\":scheme\", b\"https\"),\n<30> (b\":authority\", b\"localhost\"),\n<31> (b\":path\", b\"/\"),\n<32> (b\"x-foo\", b\"client\"),\n<33> ],\n<34> stream_id=stream_id,\n<35> stream_ended=True,\n<36> )\n<37> ],\n<38> )\n<39> \n<40> # send response\n<41> h3_server.send_headers(\n<42> stream_id=stream_id,\n<43> headers=[\n<44> (b\":status\", b\"200\"),\n<45> (b\"content-type\", b\"text/html; charset=utf-8\"),\n<46> (b"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_headers_only(self):\n # offset: 1\n ],\n end_stream=True,\n )\n \n # receive response\n events = h3_transfer(quic_server, h3_client)\n self.assertEqual(len(events), 1)\n \n self.assertTrue(\n events,\n [\n HeadersReceived(\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n (b\"x-foo\", b\"server\"),\n ],\n stream_id=stream_id,\n stream_ended=True,\n )\n ],\n )\n \n \n===========unchanged ref 0===========\n at: aioquic.h3.connection\n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.events\n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.h3.events.HeadersReceived\n headers: Headers\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: tests.test_connection\n client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_options={}, server_patch=lambda x: None, transport_options={})\n \n at: tests.test_h3\n h3_transfer(quic_sender, h3_receiver)\n \n at: tests.test_h3.H3ConnectionTest\n maxDiff = None\n \n at: unittest.case.TestCase\n failureException: Type[BaseException]\n \n longMessage: bool\n \n maxDiff: Optional[int]\n \n _testMethodName: str\n \n _testMethodDoc: str\n \n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n \"\"\"\n Client-initiated bidirectional streams carry requests and responses.\n \"\"\"\n http_events: List[H3Event] = []\n \n stream = self._stream[stream_id]\n stream.buffer += data\n if stream_ended:\n stream.ended = True\n if stream.blocked:\n return http_events\n \n + # shortcut for DATA frame fragments\n - # shortcut DATA frame bits\n if (\n stream.frame_type == FrameType.DATA\n and stream.frame_size is not None\n and len(stream.buffer) < stream.frame_size\n ):\n http_events.append(\n DataReceived(\n + data=stream.buffer,\n + push_id=stream.push_id,\n + stream_id=stream_id,\n + stream_ended=False,\n - data=stream.buffer, stream_id=stream_id, stream_ended=False\n )\n )\n stream.frame_size -= len(stream.buffer)\n stream.buffer = b\"\"\n return http_events\n \n + # handle lone FIN\n - # some peers (e.g. f5) end the stream with no data\n if stream_ended and not stream.buffer:\n http_events.append(\n + DataReceived(\n + data=b\"\",\n + push_id=stream.push_id,\n + stream_id=stream_id,\n + stream_ended=True,\n + )\n - DataReceived(data=b\"\", stream_id=stream_id, stream_ended=True)\n )\n return http_events\n \n buf = Buffer(data=stream.buffer)\n consumed = 0\n \n while not buf.eof():\n # fetch next frame header\n if stream.frame_size is None:\n try:\n stream.frame_type = buf.pull_uint\n===========changed ref 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_bidi(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 1\n frame header\n if stream.frame_size is None:\n try:\n stream.frame_type = buf.pull_uint_var()\n stream.frame_size = buf.pull_uint_var()\n except BufferReadError:\n break\n consumed = buf.tell()\n \n # check how much data is available\n chunk_size = min(stream.frame_size, buf.capacity - consumed)\n if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size:\n break\n \n # read available data\n frame_data = buf.pull_bytes(chunk_size)\n consumed = buf.tell()\n \n # detect end of frame\n stream.frame_size -= chunk_size\n if not stream.frame_size:\n stream.frame_size = None\n \n try:\n http_events.extend(\n self._handle_request_or_push_frame(\n frame_type=stream.frame_type,\n frame_data=frame_data,\n - push_id=None,\n stream_id=stream_id,\n stream_ended=stream.ended and buf.eof(),\n )\n )\n except StreamBlocked:\n stream.blocked = True\n break\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n return http_events\n \n===========changed ref 2===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_request_or_push_frame(\n - self,\n - frame_type: int,\n - frame_data: bytes,\n - push_id: int,\n - stream_id: int,\n - stream_ended: bool,\n + self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool\n ) -> List[H3Event]:\n \"\"\"\n Handle a frame received on a push stream.\n \"\"\"\n http_events: List[H3Event] = []\n stream = self._stream[stream_id]\n \n if frame_type == FrameType.DATA:\n # check DATA frame is allowed\n if stream.headers_state != HeadersState.AFTER_HEADERS:\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n frame_type=None,\n reason_phrase=\"DATA frame is not allowed in this state\",\n )\n \n if stream_ended or frame_data:\n http_events.append(\n DataReceived(\n data=frame_data,\n + push_id=stream.push_id,\n - push_id=push_id,\n stream_ended=stream_ended,\n stream_id=stream_id,\n )\n )\n elif frame_type == FrameType.HEADERS:\n # check HEADERS frame is allowed\n if stream.headers_state == HeadersState.AFTER_TRAILERS:\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n frame_type=None,\n reason_phrase=\"HEADERS frame is not allowed in this state\",\n )\n \n # try to decode HEADERS\n headers = self._decode_headers(stream_id, frame_data)\n \n # update state and emit headers\n if stream.headers_state == HeadersState.INITIAL:\n stream.headers_state = HeadersState.AFTER_HEADERS\n else:\n stream.headers_state = HeadersState.AFTER_TRAILERS\n http_events.append(\n "}}},{"rowIdx":3456,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_request_fragmented_frame"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"40dde6efab7ee6a9e05bd06a4d6393681d46e5e7"},"commit_message":{"kind":"string","value":"[http3] ensure stream_ended is propagated for server push"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_fragmented_frame(self):\n <0> quic_client = FakeQuicConnection(\n <1> configuration=QuicConfiguration(is_client=True)\n <2> )\n <3> quic_server = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=False)\n <5> )\n <6> \n <7> h3_client = H3Connection(quic_client)\n <8> h3_server = H3Connection(quic_server)\n <9> \n<10> # send request\n<11> stream_id = quic_client.get_next_available_stream_id()\n<12> h3_client.send_headers(\n<13> stream_id=stream_id,\n<14> headers=[\n<15> (b\":method\", b\"GET\"),\n<16> (b\":scheme\", b\"https\"),\n<17> (b\":authority\", b\"localhost\"),\n<18> (b\":path\", b\"/\"),\n<19> (b\"x-foo\", b\"client\"),\n<20> ],\n<21> )\n<22> h3_client.send_data(stream_id=stream_id, data=b\"hello\", end_stream=True)\n<23> \n<24> # receive request\n<25> events = h3_transfer(quic_client, h3_server)\n<26> self.assertEqual(\n<27> events,\n<28> [\n<29> HeadersReceived(\n<30> headers=[\n<31> (b\":method\", b\"GET\"),\n<32> (b\":scheme\", b\"https\"),\n<33> (b\":authority\", b\"localhost\"),\n<34> (b\":path\", b\"/\"),\n<35> (b\"x-foo\", b\"client\"),\n<36> ],\n<37> stream_id=stream_id,\n<38> stream_ended=False,\n<39> ),\n<40> DataReceived(data=b\"h\", stream_id=0, stream_ended=False),\n<41> DataReceived(data=b\"e\", stream_id=0, stream_ended=False),\n<42> DataReceived(data=b\"l\", stream"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_fragmented_frame(self):\n # offset: 1\n DataReceived(data=b\"l\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"o\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"\", stream_id=0, stream_ended=True),\n ],\n )\n \n # send push promise\n push_stream_id = h3_server.send_push_promise(\n stream_id=stream_id,\n headers=[\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/app.txt\"),\n ],\n )\n self.assertEqual(push_stream_id, 15)\n \n # send response\n h3_server.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n ],\n end_stream=False,\n )\n h3_server.send_data(stream_id=stream_id, data=b\"html\", end_stream=True)\n \n #  fulfill push promise\n h3_server.send_headers(\n stream_id=push_stream_id,\n headers=[(b\":status\", b\"200\"), (b\"content-type\", b\"text/plain\")],\n end_stream=False,\n )\n h3_server.send_data(stream_id=push_stream_id, data=b\"text\", end_stream=True)\n \n # receive push promise / reponse\n events = h3_transfer(quic_server, h3_client)\n self.assertEqual(\n events,\n [\n PushPromiseReceived(\n headers=[\n (b\":method\", b\"GET\"),\n (\n===========below chunk 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_fragmented_frame(self):\n # offset: 2\n events,\n [\n PushPromiseReceived(\n headers=[\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/app.txt\"),\n ],\n push_id=0,\n stream_id=stream_id,\n ),\n HeadersReceived(\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n ],\n stream_id=0,\n stream_ended=False,\n ),\n DataReceived(data=b\"h\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"t\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"m\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"l\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"\", stream_id=0, stream_ended=True),\n HeadersReceived(\n headers=[(b\":status\", b\"200\"), (b\"content-type\", b\"text/plain\")],\n stream_id=15,\n stream_ended=False,\n push_id=0,\n ),\n DataReceived(data=b\"text\", stream_id=15, stream_ended=False, push_id=0),\n ],\n )\n \n \n===========unchanged ref 0===========\n at: aioquic.h3.connection\n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n send_push_promise(stream_id: int, headers: Headers) -> int\n \n send_data(stream_id: int, data: bytes, end_stream: bool) -> None\n \n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.events\n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n PushPromiseReceived(headers: Headers, push_id: int, stream_id: int)\n \n at: aioquic.h3.events.DataReceived\n data: bytes\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.PushPromiseReceived\n headers: Headers\n \n push_id: int\n \n stream_id: int\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.configuration.QuicConfiguration\n alpn_protocols: Optional[List[str]] = None\n \n certificate: Any = None\n \n connection_id_length: int = 8\n \n \n===========unchanged ref 1===========\n idle_timeout: float = 60.0\n \n is_client: bool = True\n \n private_key: Any = None\n \n quic_logger: Optional[QuicLogger] = None\n \n secrets_log_file: TextIO = None\n \n server_name: Optional[str] = None\n \n session_ticket: Optional[SessionTicket] = None\n \n supported_versions: List[int] = field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n )\n \n at: tests.test_h3\n h3_transfer(quic_sender, h3_receiver)\n \n FakeQuicConnection(configuration)\n \n at: tests.test_h3.FakeQuicConnection\n get_next_available_stream_id(is_unidirectional=False)\n \n at: tests.test_h3.H3ConnectionTest.test_request_fragmented_frame\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n "}}},{"rowIdx":3457,"cells":{"path":{"kind":"string","value":"examples.http3_server/HttpRequestHandler.http_event_received"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"b84214711641ee82bfeb182d81847a0016d41132"},"commit_message":{"kind":"string","value":"[http3 server] receive request trailers"},"ground_truth":{"kind":"string","value":" <8>: elif isinstance(event, HeadersReceived) and event.stream_ended:\n self.queue.put_nowait(\n {\"type\": \"http.request\", \"body\": b\"\", \"more_body\": False}\n )\n"},"main_code":{"kind":"string","value":" # module: examples.http3_server\n class HttpRequestHandler:\n def http_event_received(self, event: H3Event):\n <0> if isinstance(event, DataReceived):\n <1> self.queue.put_nowait(\n <2> {\n <3> \"type\": \"http.request\",\n <4> \"body\": event.data,\n <5> \"more_body\": not event.stream_ended,\n <6> }\n <7> )\n <8> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h3.events\n H3Event()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: asyncio.queues.Queue\n __class_getitem__ = classmethod(GenericAlias)\n \n put_nowait(item: _T) -> None\n \n at: examples.http3_server.HttpRequestHandler.__init__\n self.queue: asyncio.Queue[Dict] = asyncio.Queue()\n \n "}}},{"rowIdx":3458,"cells":{"path":{"kind":"string","value":"examples.http3_server/HttpServerProtocol.http_event_received"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"b84214711641ee82bfeb182d81847a0016d41132"},"commit_message":{"kind":"string","value":"[http3 server] receive request trailers"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: examples.http3_server\n class HttpServerProtocol(QuicConnectionProtocol):\n def http_event_received(self, event: H3Event) -> None:\n <0> if isinstance(event, HeadersReceived) and event.stream_id not in self._handlers:\n <1> authority = None\n <2> headers = []\n <3> http_version = \"0.9\" if isinstance(self._http, H0Connection) else \"3\"\n <4> raw_path = b\"\"\n <5> method = \"\"\n <6> protocol = None\n <7> for header, value in event.headers:\n <8> if header == b\":authority\":\n <9> authority = value\n<10> headers.append((b\"host\", value))\n<11> elif header == b\":method\":\n<12> method = value.decode(\"utf8\")\n<13> elif header == b\":path\":\n<14> raw_path = value\n<15> elif header == b\":protocol\":\n<16> protocol = value.decode(\"utf8\")\n<17> elif header and not header.startswith(b\":\"):\n<18> headers.append((header, value))\n<19> \n<20> if b\"?\" in raw_path:\n<21> path_bytes, query_string = raw_path.split(b\"?\", maxsplit=1)\n<22> else:\n<23> path_bytes, query_string = raw_path, b\"\"\n<24> path = path_bytes.decode(\"utf8\")\n<25> \n<26> handler: Handler\n<27> if method == \"CONNECT\" and protocol == \"websocket\":\n<28> subprotocols: List[str] = []\n<29> for header, value in event.headers:\n<30> if header == b\"sec-websocket-protocol\":\n<31> subprotocols = [\n<32> x.strip() for x in value.decode(\"utf8\").split(\",\")\n<33> ]\n<34> scope = {\n<35> \"headers\": headers,\n<36> \"http_version\": http_version,\n<37> \"method\": method,\n<38> \"path\": path,\n<39> \"query_string\": query_string,\n<40> \"raw_path\": raw_path,\n<41> \"root_path\": \"\",\n<42> \"scheme\": \"wss\",\n<43> \"subprotocols"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: examples.http3_server\n class HttpServerProtocol(QuicConnectionProtocol):\n def http_event_received(self, event: H3Event) -> None:\n # offset: 1\n \"type\": \"websocket\",\n }\n handler = WebSocketHandler(\n connection=self._http,\n scope=scope,\n stream_id=event.stream_id,\n transmit=self.transmit,\n )\n else:\n extensions: Dict[str, Dict] = {}\n if isinstance(self._http, H3Connection):\n extensions[\"http.response.push\"] = {}\n scope = {\n \"extensions\": extensions,\n \"headers\": headers,\n \"http_version\": http_version,\n \"method\": method,\n \"path\": path,\n \"query_string\": query_string,\n \"raw_path\": raw_path,\n \"root_path\": \"\",\n \"scheme\": \"https\",\n \"type\": \"http\",\n }\n handler = HttpRequestHandler(\n authority=authority,\n connection=self._http,\n protocol=self,\n scope=scope,\n stream_ended=event.stream_ended,\n stream_id=event.stream_id,\n transmit=self.transmit,\n )\n self._handlers[event.stream_id] = handler\n asyncio.ensure_future(handler.run_asgi(application))\n elif isinstance(event, DataReceived) and event.stream_id in self._handlers:\n handler = self._handlers[event.stream_id]\n handler.http_event_received(event)\n \n \n===========unchanged ref 0===========\n at: aioquic.asyncio.protocol.QuicConnectionProtocol\n __init__(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None)\n \n transmit() -> None\n \n at: aioquic.h0.connection\n H0Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection\n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.events\n H3Event()\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: examples.http3_server\n HttpConnection = Union[H0Connection, H3Connection]\n \n HttpRequestHandler(*, authority: bytes, connection: HttpConnection, protocol: QuicConnectionProtocol, scope: Dict, stream_ended: bool, stream_id: int, transmit: Callable[[], None])\n \n WebSocketHandler(*, connection: HttpConnection, scope: Dict, stream_id: int, transmit: Callable[[], None])\n \n Handler = Union[HttpRequestHandler, WebSocketHandler]\n \n at: examples.http3_server.HttpServerProtocol.quic_event_received\n self._http = H3Connection(self._quic)\n self._http = H0Connection(self._quic)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n Dict = _alias(dict, 2, inst=False, name='Dict')\n \n \n===========changed ref 0===========\n # module: examples.http3_server\n class HttpRequestHandler:\n def http_event_received(self, event: H3Event):\n if isinstance(event, DataReceived):\n self.queue.put_nowait(\n {\n \"type\": \"http.request\",\n \"body\": event.data,\n \"more_body\": not event.stream_ended,\n }\n )\n + elif isinstance(event, HeadersReceived) and event.stream_ended:\n + self.queue.put_nowait(\n + {\"type\": \"http.request\", \"body\": b\"\", \"more_body\": False}\n + )\n "}}},{"rowIdx":3459,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection.handle_event"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"67b188972a0b6539a74ba52ddaba87dba341d1dc"},"commit_message":{"kind":"string","value":"[http3] de-duplicate some push / request code"},"ground_truth":{"kind":"string","value":"<10>: return self._receive_request_or_push_data(\n return self._receive_stream_data_bidi(\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n <0> \"\"\"\n <1> Handle a QUIC event and return a list of HTTP events.\n <2> \n <3> :param event: The QUIC event to handle.\n <4> \"\"\"\n <5> if isinstance(event, StreamDataReceived):\n <6> stream_id = event.stream_id\n <7> if stream_id not in self._stream:\n <8> self._stream[stream_id] = H3Stream()\n <9> if stream_id % 4 == 0:\n<10> return self._receive_stream_data_bidi(\n<11> stream_id, event.data, event.end_stream\n<12> )\n<13> elif stream_is_unidirectional(stream_id):\n<14> return self._receive_stream_data_uni(\n<15> stream_id, event.data, event.end_stream\n<16> )\n<17> return []\n<18> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h3.connection\n H3Stream()\n \n at: aioquic.h3.connection.H3Connection\n _receive_request_or_push_data(stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event]\n \n _receive_stream_data_uni(self, stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event]\n _receive_stream_data_uni(stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event]\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._stream: Dict[int, H3Stream] = {}\n \n at: aioquic.h3.events\n H3Event()\n \n at: aioquic.quic.connection\n stream_is_unidirectional(stream_id: int) -> bool\n \n at: aioquic.quic.events\n QuicEvent()\n \n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n "}}},{"rowIdx":3460,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._handle_request_or_push_frame"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"67b188972a0b6539a74ba52ddaba87dba341d1dc"},"commit_message":{"kind":"string","value":"[http3] de-duplicate some push / request code"},"ground_truth":{"kind":"string","value":" <1>: Handle a frame received on a request or push stream.\n Handle a frame received on a push stream.\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _handle_request_or_push_frame(\n self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool\n ) -> List[H3Event]:\n <0> \"\"\"\n <1> Handle a frame received on a push stream.\n <2> \"\"\"\n <3> http_events: List[H3Event] = []\n <4> stream = self._stream[stream_id]\n <5> \n <6> if frame_type == FrameType.DATA:\n <7> # check DATA frame is allowed\n <8> if stream.headers_state != HeadersState.AFTER_HEADERS:\n <9> raise QuicConnectionError(\n<10> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n<11> frame_type=None,\n<12> reason_phrase=\"DATA frame is not allowed in this state\",\n<13> )\n<14> \n<15> if stream_ended or frame_data:\n<16> http_events.append(\n<17> DataReceived(\n<18> data=frame_data,\n<19> push_id=stream.push_id,\n<20> stream_ended=stream_ended,\n<21> stream_id=stream_id,\n<22> )\n<23> )\n<24> elif frame_type == FrameType.HEADERS:\n<25> # check HEADERS frame is allowed\n<26> if stream.headers_state == HeadersState.AFTER_TRAILERS:\n<27> raise QuicConnectionError(\n<28> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n<29> frame_type=None,\n<30> reason_phrase=\"HEADERS frame is not allowed in this state\",\n<31> )\n<32> \n<33> # try to decode HEADERS\n<34> headers = self._decode_headers(stream_id, frame_data)\n<35> \n<36> # update state and emit headers\n<37> if stream.headers_state == HeadersState.INITIAL:\n<38> stream.headers_state = HeadersState.AFTER_HEADERS\n<39> else:\n<40> stream.headers_state = HeadersState.AFTER_TRAILERS\n<41> http_events.append(\n<42> HeadersReceived(\n<43> headers=headers,\n<44> push_id=stream.push"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_request_or_push_frame(\n self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 1\n stream_id=stream_id,\n stream_ended=stream_ended,\n )\n )\n elif stream.frame_type == FrameType.PUSH_PROMISE and stream.push_id is None:\n if not self._is_client:\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n frame_type=None,\n reason_phrase=\"Clients must not send PUSH_PROMISE\",\n )\n frame_buf = Buffer(data=frame_data)\n push_id = frame_buf.pull_uint_var()\n headers = self._decode_headers(stream_id, frame_data[frame_buf.tell() :])\n http_events.append(\n PushPromiseReceived(\n headers=headers, push_id=push_id, stream_id=stream_id\n )\n )\n elif frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.PUSH_PROMISE,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n FrameType.DUPLICATE_PUSH,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on push stream\",\n )\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n tell() -> int\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n HeadersState()\n \n at: aioquic.h3.connection.H3Connection\n _decode_headers(stream_id: int, frame_data: bytes) -> Headers\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._is_client = quic.configuration.is_client\n \n self._stream: Dict[int, H3Stream] = {}\n \n at: aioquic.h3.connection.H3Stream.__init__\n self.frame_type: Optional[int] = None\n \n self.headers_state: HeadersState = HeadersState.INITIAL\n \n self.push_id: Optional[int] = None\n \n at: aioquic.h3.events\n H3Event()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n PushPromiseReceived(headers: Headers, push_id: int, stream_id: int)\n \n at: aioquic.h3.events.DataReceived\n data: bytes\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.HeadersReceived\n headers: Headers\n \n stream_id: int\n \n stream_ended: bool\n \n \n===========unchanged ref 1===========\n push_id: Optional[int] = None\n \n at: aioquic.h3.events.PushPromiseReceived\n headers: Headers\n \n push_id: int\n \n stream_id: int\n \n at: aioquic.quic.connection\n QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_stream_data_bidi(\n stream_id, event.data, event.end_stream\n )\n elif stream_is_unidirectional(stream_id):\n return self._receive_stream_data_uni(\n stream_id, event.data, event.end_stream\n )\n return []\n "}}},{"rowIdx":3461,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_stream_data_uni"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"67b188972a0b6539a74ba52ddaba87dba341d1dc"},"commit_message":{"kind":"string","value":"[http3] de-duplicate some push / request code"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n <0> http_events: List[H3Event] = []\n <1> \n <2> stream = self._stream[stream_id]\n <3> stream.buffer += data\n <4> if stream_ended:\n <5> stream.ended = True\n <6> \n <7> buf = Buffer(data=stream.buffer)\n <8> consumed = 0\n <9> unblocked_streams: Set[int] = set()\n<10> \n<11> while stream.stream_type == StreamType.PUSH or not buf.eof():\n<12> # fetch stream type for unidirectional streams\n<13> if stream.stream_type is None:\n<14> try:\n<15> stream.stream_type = buf.pull_uint_var()\n<16> except BufferReadError:\n<17> break\n<18> consumed = buf.tell()\n<19> \n<20> # check unicity\n<21> if stream.stream_type == StreamType.CONTROL:\n<22> assert self._peer_control_stream_id is None\n<23> self._peer_control_stream_id = stream_id\n<24> elif stream.stream_type == StreamType.QPACK_DECODER:\n<25> assert self._peer_decoder_stream_id is None\n<26> self._peer_decoder_stream_id = stream_id\n<27> elif stream.stream_type == StreamType.QPACK_ENCODER:\n<28> assert self._peer_encoder_stream_id is None\n<29> self._peer_encoder_stream_id = stream_id\n<30> \n<31> if stream.stream_type == StreamType.CONTROL:\n<32> # fetch next frame\n<33> try:\n<34> frame_type = buf.pull_uint_var()\n<35> frame_length = buf.pull_uint_var()\n<36> frame_data = buf.pull_bytes(frame_length)\n<37> except BufferReadError:\n<38> break\n<39> consumed = buf.tell()\n<40> \n<41> self._handle_control_frame(frame_type"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 1\n elif stream.stream_type == StreamType.PUSH:\n # fetch push id\n if stream.push_id is None:\n try:\n stream.push_id = buf.pull_uint_var()\n except BufferReadError:\n break\n consumed = buf.tell()\n \n # handle lone FIN\n if stream_ended and buf.eof():\n http_events.append(\n DataReceived(\n data=b\"\",\n push_id=stream.push_id,\n stream_id=stream_id,\n stream_ended=True,\n )\n )\n \n # fetch next frame\n try:\n frame_type = buf.pull_uint_var()\n frame_length = buf.pull_uint_var()\n frame_data = buf.pull_bytes(frame_length)\n except BufferReadError:\n break\n consumed = buf.tell()\n \n http_events.extend(\n self._handle_request_or_push_frame(\n frame_type=frame_type,\n frame_data=frame_data,\n stream_id=stream_id,\n stream_ended=stream.ended and buf.eof(),\n )\n )\n \n # stop if there is no more data\n if buf.eof():\n break\n elif stream.stream_type == StreamType.QPACK_DECODER:\n # feed unframed data to decoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n self._encoder.feed_decoder(data)\n elif stream.stream_type == StreamType.QPACK_ENCODER:\n # feed unframed data to encoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n unblocked_streams\n===========below chunk 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 2\n buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n unblocked_streams.update(self._decoder.feed_encoder(data))\n else:\n # unknown stream type, discard data\n buf.seek(buf.capacity)\n consumed = buf.tell()\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n # process unblocked streams\n for stream_id in unblocked_streams:\n stream = self._stream[stream_id]\n \n # decode headers\n decoder, headers = self._decoder.resume_header(stream_id)\n self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n stream.blocked = False\n \n # update state and emit headers\n if stream.headers_state == HeadersState.INITIAL:\n stream.headers_state = HeadersState.AFTER_HEADERS\n else:\n stream.headers_state = HeadersState.AFTER_TRAILERS\n http_events.append(\n HeadersReceived(\n headers=headers,\n stream_id=stream_id,\n stream_ended=stream.ended and not stream.buffer,\n )\n )\n \n # resume processing\n if stream.buffer:\n http_events.extend(\n self._receive_stream_data_bidi(stream_id, b\"\", stream.ended)\n )\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n seek(pos: int) -> None\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n HeadersState()\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n at: aioquic.h3.connection.H3Connection\n _handle_control_frame(frame_type: int, frame_data: bytes) -> None\n \n _receive_request_or_push_data(stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event]\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._decoder = Decoder(self._max_table_capacity, self._blocked_streams)\n \n self._encoder = Encoder()\n \n self._stream: Dict[int, H3Stream] = {}\n \n self._peer_control_stream_id: Optional[int] = None\n \n self._peer_decoder_stream_id: Optional[int] = None\n \n self._peer_encoder_stream_id: Optional[int] = None\n \n at: aioquic.h3.connection.H3Connection._receive_request_or_push_data\n http_events: List[H3Event] = []\n \n at: aioquic.h3.connection.H3Stream.__init__\n self.buffer = b\"\"\n \n self.ended = False\n \n self.push_id: Optional[int] = None\n \n self.stream_type: Optional[int] = None\n \n at: aioquic.h3.events\n H3Event()\n \n \n===========unchanged ref 1===========\n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n Set = _alias(set, 1, inst=False, name='Set')\n \n "}}},{"rowIdx":3462,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_push_frame_wrong_frame_type"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"67b188972a0b6539a74ba52ddaba87dba341d1dc"},"commit_message":{"kind":"string","value":"[http3] de-duplicate some push / request code"},"ground_truth":{"kind":"string","value":"<16>: self.assertEqual(\n str(cm.exception), \"Error: 10, reason: Invalid frame type on push stream\"\n )\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_push_frame_wrong_frame_type(self):\n <0> quic_client = FakeQuicConnection(\n <1> configuration=QuicConfiguration(is_client=True)\n <2> )\n <3> h3_client = H3Connection(quic_client)\n <4> \n <5> with self.assertRaises(QuicConnectionError) as cm:\n <6> h3_client.handle_event(\n <7> StreamDataReceived(\n <8> stream_id=15,\n <9> data=encode_uint_var(StreamType.PUSH)\n<10> + encode_uint_var(0) # push ID\n<11> + encode_frame(FrameType.SETTINGS, b\"\"),\n<12> end_stream=False,\n<13> )\n<14> )\n<15> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n<16> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.configuration.QuicConfiguration\n alpn_protocols: Optional[List[str]] = None\n \n certificate: Any = None\n \n connection_id_length: int = 8\n \n idle_timeout: float = 60.0\n \n is_client: bool = True\n \n private_key: Any = None\n \n quic_logger: Optional[QuicLogger] = None\n \n secrets_log_file: TextIO = None\n \n \n===========unchanged ref 1===========\n server_name: Optional[str] = None\n \n session_ticket: Optional[SessionTicket] = None\n \n supported_versions: List[int] = field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n )\n \n at: aioquic.quic.connection\n QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: aioquic.quic.events.StreamDataReceived\n data: bytes\n \n end_stream: bool\n \n stream_id: int\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: tests.test_h3.H3ConnectionTest\n maxDiff = None\n \n at: unittest.case.TestCase\n failureException: Type[BaseException]\n \n longMessage: bool\n \n maxDiff: Optional[int]\n \n _testMethodName: str\n \n _testMethodDoc: str\n \n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E]\n assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None\n \n at: unittest.case._AssertRaisesContext.__exit__\n self.exception = exc_value.with_traceback(None)\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_stream_data_bidi(\n stream_id, event.data, event.end_stream\n )\n elif stream_is_unidirectional(stream_id):\n return self._receive_stream_data_uni(\n stream_id, event.data, event.end_stream\n )\n return []\n \n===========changed ref 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n + def _receive_request_or_push_data(\n + self, stream_id: int, data: bytes, stream_ended: bool\n + ) -> List[H3Event]:\n + \"\"\"\n + Handle data received on a request or push stream.\n + \"\"\"\n + http_events: List[H3Event] = []\n + \n + stream = self._stream[stream_id]\n + stream.buffer += data\n + if stream_ended:\n + stream.ended = True\n + if stream.blocked:\n + return http_events\n + \n + # shortcut for DATA frame fragments\n + if (\n + stream.frame_type == FrameType.DATA\n + and stream.frame_size is not None\n + and len(stream.buffer) < stream.frame_size\n + ):\n + http_events.append(\n + DataReceived(\n + data=stream.buffer,\n + push_id=stream.push_id,\n + stream_id=stream_id,\n + stream_ended=False,\n + )\n + )\n + stream.frame_size -= len(stream.buffer)\n + stream.buffer = b\"\"\n + return http_events\n + \n + # handle lone FIN\n + if stream_ended and not stream.buffer:\n + http_events.append(\n + DataReceived(\n + data=b\"\",\n + push_id=stream.push_id,\n + stream_id=stream_id,\n + stream_ended=True,\n + )\n + )\n + return http_events\n + \n + buf = Buffer(data=stream.buffer)\n + consumed = 0\n + \n + while not buf.eof():\n + # fetch next frame header\n + if stream.frame_size is None:\n + try:\n + stream.frame_type = buf.pull_uint_var()\n + stream.frame_size = buf.pull_uint_var()\n + except BufferReadError:\n + break\n + "}}},{"rowIdx":3463,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_request_frame_wrong_frame_type"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"67b188972a0b6539a74ba52ddaba87dba341d1dc"},"commit_message":{"kind":"string","value":"[http3] de-duplicate some push / request code"},"ground_truth":{"kind":"string","value":"<14>: self.assertEqual(\n str(cm.exception), \"Error: 10, reason: Invalid frame type on request stream\"\n )\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_wrong_frame_type(self):\n <0> quic_server = FakeQuicConnection(\n <1> configuration=QuicConfiguration(is_client=False)\n <2> )\n <3> h3_server = H3Connection(quic_server)\n <4> \n <5> with self.assertRaises(QuicConnectionError) as cm:\n <6> h3_server.handle_event(\n <7> StreamDataReceived(\n <8> stream_id=0,\n <9> data=encode_frame(FrameType.SETTINGS, b\"\"),\n<10> end_stream=False,\n<11> )\n<12> )\n<13> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n<14> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.connection\n QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str)\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========unchanged ref 1===========\n assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E]\n assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None\n \n at: unittest.case._AssertRaisesContext.__exit__\n self.exception = exc_value.with_traceback(None)\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_stream_data_bidi(\n stream_id, event.data, event.end_stream\n )\n elif stream_is_unidirectional(stream_id):\n return self._receive_stream_data_uni(\n stream_id, event.data, event.end_stream\n )\n return []\n \n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_push_frame_wrong_frame_type(self):\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n with self.assertRaises(QuicConnectionError) as cm:\n h3_client.handle_event(\n StreamDataReceived(\n stream_id=15,\n data=encode_uint_var(StreamType.PUSH)\n + encode_uint_var(0) # push ID\n + encode_frame(FrameType.SETTINGS, b\"\"),\n end_stream=False,\n )\n )\n self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n + self.assertEqual(\n + str(cm.exception), \"Error: 10, reason: Invalid frame type on push stream\"\n + )\n \n===========changed ref 2===========\n # module: aioquic.h3.connection\n class H3Connection:\n + def _receive_request_or_push_data(\n + self, stream_id: int, data: bytes, stream_ended: bool\n + ) -> List[H3Event]:\n + \"\"\"\n + Handle data received on a request or push stream.\n + \"\"\"\n + http_events: List[H3Event] = []\n + \n + stream = self._stream[stream_id]\n + stream.buffer += data\n + if stream_ended:\n + stream.ended = True\n + if stream.blocked:\n + return http_events\n + \n + # shortcut for DATA frame fragments\n + if (\n + stream.frame_type == FrameType.DATA\n + and stream.frame_size is not None\n + and len(stream.buffer) < stream.frame_size\n + ):\n + http_events.append(\n + DataReceived(\n + data=stream.buffer,\n + push_id=stream.push_id,\n + stream_id=stream_id,\n + stream_ended=False,\n + )\n + )\n + stream.frame_size -= len(stream.buffer)\n + stream.buffer = b\"\"\n + return http_events\n + \n + # handle lone FIN\n + if stream_ended and not stream.buffer:\n + http_events.append(\n + DataReceived(\n + data=b\"\",\n + push_id=stream.push_id,\n + stream_id=stream_id,\n + stream_ended=True,\n + )\n + )\n + return http_events\n + \n + buf = Buffer(data=stream.buffer)\n + consumed = 0\n + \n + while not buf.eof():\n + # fetch next frame header\n + if stream.frame_size is None:\n + try:\n + stream.frame_type = buf.pull_uint_var()\n + stream.frame_size = buf.pull_uint_var()\n + except BufferReadError:\n + break\n + \n===========changed ref 3===========\n # module: aioquic.h3.connection\n class H3Connection:\n + def _receive_request_or_push_data(\n + self, stream_id: int, data: bytes, stream_ended: bool\n + ) -> List[H3Event]:\n # offset: 1\n stream.frame_size = buf.pull_uint_var()\n + except BufferReadError:\n + break\n + consumed = buf.tell()\n + \n + # check how much data is available\n + chunk_size = min(stream.frame_size, buf.capacity - consumed)\n + if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size:\n + break\n + \n + # read available data\n + frame_data = buf.pull_bytes(chunk_size)\n + consumed = buf.tell()\n + \n + # detect end of frame\n + stream.frame_size -= chunk_size\n + if not stream.frame_size:\n + stream.frame_size = None\n + \n + try:\n + http_events.extend(\n + self._handle_request_or_push_frame(\n + frame_type=stream.frame_type,\n + frame_data=frame_data,\n + stream_id=stream_id,\n + stream_ended=stream.ended and buf.eof(),\n + )\n + )\n + except StreamBlocked:\n + stream.blocked = True\n + break\n + \n + # remove processed data from buffer\n + stream.buffer = stream.buffer[consumed:]\n + \n + return http_events\n + "}}},{"rowIdx":3464,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_request_fragmented_frame"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"67b188972a0b6539a74ba52ddaba87dba341d1dc"},"commit_message":{"kind":"string","value":"[http3] de-duplicate some push / request code"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_fragmented_frame(self):\n <0> quic_client = FakeQuicConnection(\n <1> configuration=QuicConfiguration(is_client=True)\n <2> )\n <3> quic_server = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=False)\n <5> )\n <6> \n <7> h3_client = H3Connection(quic_client)\n <8> h3_server = H3Connection(quic_server)\n <9> \n<10> # send request\n<11> stream_id = quic_client.get_next_available_stream_id()\n<12> h3_client.send_headers(\n<13> stream_id=stream_id,\n<14> headers=[\n<15> (b\":method\", b\"GET\"),\n<16> (b\":scheme\", b\"https\"),\n<17> (b\":authority\", b\"localhost\"),\n<18> (b\":path\", b\"/\"),\n<19> (b\"x-foo\", b\"client\"),\n<20> ],\n<21> )\n<22> h3_client.send_data(stream_id=stream_id, data=b\"hello\", end_stream=True)\n<23> \n<24> # receive request\n<25> events = h3_transfer(quic_client, h3_server)\n<26> self.assertEqual(\n<27> events,\n<28> [\n<29> HeadersReceived(\n<30> headers=[\n<31> (b\":method\", b\"GET\"),\n<32> (b\":scheme\", b\"https\"),\n<33> (b\":authority\", b\"localhost\"),\n<34> (b\":path\", b\"/\"),\n<35> (b\"x-foo\", b\"client\"),\n<36> ],\n<37> stream_id=stream_id,\n<38> stream_ended=False,\n<39> ),\n<40> DataReceived(data=b\"h\", stream_id=0, stream_ended=False),\n<41> DataReceived(data=b\"e\", stream_id=0, stream_ended=False),\n<42> DataReceived(data=b\"l\", stream"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_fragmented_frame(self):\n # offset: 1\n DataReceived(data=b\"l\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"o\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"\", stream_id=0, stream_ended=True),\n ],\n )\n \n # send push promise\n push_stream_id = h3_server.send_push_promise(\n stream_id=stream_id,\n headers=[\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/app.txt\"),\n ],\n )\n self.assertEqual(push_stream_id, 15)\n \n # send response\n h3_server.send_headers(\n stream_id=stream_id,\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n ],\n end_stream=False,\n )\n h3_server.send_data(stream_id=stream_id, data=b\"html\", end_stream=True)\n \n #  fulfill push promise\n h3_server.send_headers(\n stream_id=push_stream_id,\n headers=[(b\":status\", b\"200\"), (b\"content-type\", b\"text/plain\")],\n end_stream=False,\n )\n h3_server.send_data(stream_id=push_stream_id, data=b\"text\", end_stream=True)\n \n # receive push promise / reponse\n events = h3_transfer(quic_server, h3_client)\n self.assertEqual(\n events,\n [\n PushPromiseReceived(\n headers=[\n (b\":method\", b\"GET\"),\n (\n===========below chunk 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_request_fragmented_frame(self):\n # offset: 2\n events,\n [\n PushPromiseReceived(\n headers=[\n (b\":method\", b\"GET\"),\n (b\":scheme\", b\"https\"),\n (b\":authority\", b\"localhost\"),\n (b\":path\", b\"/app.txt\"),\n ],\n push_id=0,\n stream_id=stream_id,\n ),\n HeadersReceived(\n headers=[\n (b\":status\", b\"200\"),\n (b\"content-type\", b\"text/html; charset=utf-8\"),\n ],\n stream_id=0,\n stream_ended=False,\n ),\n DataReceived(data=b\"h\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"t\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"m\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"l\", stream_id=0, stream_ended=False),\n DataReceived(data=b\"\", stream_id=0, stream_ended=True),\n HeadersReceived(\n headers=[(b\":status\", b\"200\"), (b\"content-type\", b\"text/plain\")],\n stream_id=15,\n stream_ended=False,\n push_id=0,\n ),\n DataReceived(data=b\"text\", stream_id=15, stream_ended=False, push_id=0),\n DataReceived(data=b\"\", stream_id=15, stream_ended=True, push_id=0),\n ],\n )\n \n \n===========unchanged ref 0===========\n at: aioquic.h3.connection\n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n send_push_promise(stream_id: int, headers: Headers) -> int\n \n send_data(stream_id: int, data: bytes, end_stream: bool) -> None\n \n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: aioquic.h3.events\n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n PushPromiseReceived(headers: Headers, push_id: int, stream_id: int)\n \n at: aioquic.h3.events.DataReceived\n data: bytes\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.HeadersReceived\n headers: Headers\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.PushPromiseReceived\n headers: Headers\n \n push_id: int\n \n stream_id: int\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n \n===========unchanged ref 1===========\n at: tests.test_h3\n h3_transfer(quic_sender, h3_receiver)\n \n FakeQuicConnection(configuration)\n \n at: tests.test_h3.FakeQuicConnection\n get_next_available_stream_id(is_unidirectional=False)\n \n at: tests.test_h3.H3ConnectionTest.test_request_headers_only\n stream_id = quic_client.get_next_available_stream_id()\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_wrong_frame_type(self):\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n with self.assertRaises(QuicConnectionError) as cm:\n h3_server.handle_event(\n StreamDataReceived(\n stream_id=0,\n data=encode_frame(FrameType.SETTINGS, b\"\"),\n end_stream=False,\n )\n )\n self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n + self.assertEqual(\n + str(cm.exception), \"Error: 10, reason: Invalid frame type on request stream\"\n + )\n "}}},{"rowIdx":3465,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection.__init__"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"286c400feb5e3fdee22b0434ae89351de094c88a"},"commit_message":{"kind":"string","value":"[http3] add some internal exception types"},"ground_truth":{"kind":"string","value":" <5>: self._decoder = pylsqpack.Decoder(\n self._max_table_capacity, self._blocked_streams\n self._decoder = Decoder(self._max_table_capacity, self._blocked_streams)\n <6>: )\n self._encoder = pylsqpack.Encoder()\n self._encoder = Encoder()\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def __init__(self, quic: QuicConnection):\n <0> self._max_table_capacity = 0x100\n <1> self._blocked_streams = 0x10\n <2> \n <3> self._is_client = quic.configuration.is_client\n <4> self._quic = quic\n <5> self._decoder = Decoder(self._max_table_capacity, self._blocked_streams)\n <6> self._encoder = Encoder()\n <7> self._stream: Dict[int, H3Stream] = {}\n <8> \n <9> self._max_push_id: Optional[int] = 8 if self._is_client else None\n<10> self._next_push_id: int = 0\n<11> \n<12> self._local_control_stream_id: Optional[int] = None\n<13> self._local_decoder_stream_id: Optional[int] = None\n<14> self._local_encoder_stream_id: Optional[int] = None\n<15> \n<16> self._peer_control_stream_id: Optional[int] = None\n<17> self._peer_decoder_stream_id: Optional[int] = None\n<18> self._peer_encoder_stream_id: Optional[int] = None\n<19> \n<20> self._init_connection()\n<21> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic._buffer\n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n pull_uint_var() -> int\n \n at: typing\n Dict = _alias(dict, 2, inst=False, name='Dict')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n + class WrongStream(ProtocolError):\n + error_code = ErrorCode.HTTP_WRONG_STREAM\n + \n===========changed ref 1===========\n # module: aioquic.h3.connection\n + class UnexpectedFrame(ProtocolError):\n + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME\n + \n===========changed ref 2===========\n # module: aioquic.h3.connection\n + class StreamCreationError(ProtocolError):\n + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR\n + \n===========changed ref 3===========\n # module: aioquic.h3.connection\n + class QpackEncoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR\n + \n===========changed ref 4===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + def __init__(self, reason_phrase: str = \"\"):\n + self.reason_phrase = reason_phrase\n + \n===========changed ref 5===========\n # module: aioquic.h3.connection\n + class QpackDecoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR\n + \n===========changed ref 6===========\n # module: aioquic.h3.connection\n + class QpackDecompressionFailed(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED\n + \n===========changed ref 7===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + \"\"\"\n + Base class for protocol errors.\n + \n + These errors are not exposed to the API user, they are handled\n + in :meth:`H3Connection.handle_event`.\n + \"\"\"\n + \n + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR\n + \n===========changed ref 8===========\n # module: aioquic.h3.connection\n class ErrorCode(IntEnum):\n HTTP_NO_ERROR = 0x00\n HTTP_GENERAL_PROTOCOL_ERROR = 0x01\n HTTP_INTERNAL_ERROR = 0x03\n HTTP_REQUEST_CANCELLED = 0x05\n HTTP_INCOMPLETE_REQUEST = 0x06\n HTTP_CONNECT_ERROR = 0x07\n HTTP_EXCESSIVE_LOAD = 0x08\n HTTP_VERSION_FALLBACK = 0x09\n HTTP_WRONG_STREAM = 0x0A\n HTTP_ID_ERROR = 0x0B\n HTTP_STREAM_CREATION_ERROR = 0x0D\n HTTP_CLOSED_CRITICAL_STREAM = 0x0F\n HTTP_EARLY_RESPONSE = 0x11\n HTTP_MISSING_SETTINGS = 0x12\n HTTP_UNEXPECTED_FRAME = 0x13\n HTTP_REQUEST_REJECTED = 0x14\n HTTP_SETTINGS_ERROR = 0xFF\n + HTTP_QPACK_DECOMPRESSION_FAILED = 0x200\n + HTTP_QPACK_ENCODER_STREAM_ERROR = 0x201\n + HTTP_QPACK_DECODER_STREAM_ERROR = 0x202\n "}}},{"rowIdx":3466,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._decode_headers"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"286c400feb5e3fdee22b0434ae89351de094c88a"},"commit_message":{"kind":"string","value":"[http3] add some internal exception types"},"ground_truth":{"kind":"string","value":" <3>: try:\n decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n <4>: self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n <5>: except pylsqpack.DecompressionFailed as exc:\n raise QpackDecompressionFailed() from exc\n \n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers:\n <0> \"\"\"\n <1> Decode a HEADERS block and send decoder updates on the decoder stream.\n <2> \"\"\"\n <3> decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n <4> self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n <5> return headers\n <6> \n "},"context":{"kind":"string","value":"===========changed ref 0===========\n # module: aioquic.h3.connection\n + class WrongStream(ProtocolError):\n + error_code = ErrorCode.HTTP_WRONG_STREAM\n + \n===========changed ref 1===========\n # module: aioquic.h3.connection\n + class UnexpectedFrame(ProtocolError):\n + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME\n + \n===========changed ref 2===========\n # module: aioquic.h3.connection\n + class StreamCreationError(ProtocolError):\n + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR\n + \n===========changed ref 3===========\n # module: aioquic.h3.connection\n + class QpackEncoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR\n + \n===========changed ref 4===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + def __init__(self, reason_phrase: str = \"\"):\n + self.reason_phrase = reason_phrase\n + \n===========changed ref 5===========\n # module: aioquic.h3.connection\n + class QpackDecoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR\n + \n===========changed ref 6===========\n # module: aioquic.h3.connection\n + class QpackDecompressionFailed(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED\n + \n===========changed ref 7===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + \"\"\"\n + Base class for protocol errors.\n + \n + These errors are not exposed to the API user, they are handled\n + in :meth:`H3Connection.handle_event`.\n + \"\"\"\n + \n + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR\n + \n===========changed ref 8===========\n # module: aioquic.h3.connection\n class H3Connection:\n def __init__(self, quic: QuicConnection):\n self._max_table_capacity = 0x100\n self._blocked_streams = 0x10\n \n self._is_client = quic.configuration.is_client\n self._quic = quic\n + self._decoder = pylsqpack.Decoder(\n + self._max_table_capacity, self._blocked_streams\n - self._decoder = Decoder(self._max_table_capacity, self._blocked_streams)\n + )\n + self._encoder = pylsqpack.Encoder()\n - self._encoder = Encoder()\n self._stream: Dict[int, H3Stream] = {}\n \n self._max_push_id: Optional[int] = 8 if self._is_client else None\n self._next_push_id: int = 0\n \n self._local_control_stream_id: Optional[int] = None\n self._local_decoder_stream_id: Optional[int] = None\n self._local_encoder_stream_id: Optional[int] = None\n \n self._peer_control_stream_id: Optional[int] = None\n self._peer_decoder_stream_id: Optional[int] = None\n self._peer_encoder_stream_id: Optional[int] = None\n \n self._init_connection()\n \n===========changed ref 9===========\n # module: aioquic.h3.connection\n class ErrorCode(IntEnum):\n HTTP_NO_ERROR = 0x00\n HTTP_GENERAL_PROTOCOL_ERROR = 0x01\n HTTP_INTERNAL_ERROR = 0x03\n HTTP_REQUEST_CANCELLED = 0x05\n HTTP_INCOMPLETE_REQUEST = 0x06\n HTTP_CONNECT_ERROR = 0x07\n HTTP_EXCESSIVE_LOAD = 0x08\n HTTP_VERSION_FALLBACK = 0x09\n HTTP_WRONG_STREAM = 0x0A\n HTTP_ID_ERROR = 0x0B\n HTTP_STREAM_CREATION_ERROR = 0x0D\n HTTP_CLOSED_CRITICAL_STREAM = 0x0F\n HTTP_EARLY_RESPONSE = 0x11\n HTTP_MISSING_SETTINGS = 0x12\n HTTP_UNEXPECTED_FRAME = 0x13\n HTTP_REQUEST_REJECTED = 0x14\n HTTP_SETTINGS_ERROR = 0xFF\n + HTTP_QPACK_DECOMPRESSION_FAILED = 0x200\n + HTTP_QPACK_ENCODER_STREAM_ERROR = 0x201\n + HTTP_QPACK_DECODER_STREAM_ERROR = 0x202\n "}}},{"rowIdx":3467,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._handle_control_frame"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"286c400feb5e3fdee22b0434ae89351de094c88a"},"commit_message":{"kind":"string","value":"[http3] add some internal exception types"},"ground_truth":{"kind":"string","value":"<12>: raise QuicConnectionError(\n<13>: error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n<14>: frame_type=None,\n<15>: raise UnexpectedFrame(\"Servers must not send MAX_PUSH_ID\")\n reason_phrase=\"Servers must not send MAX_PUSH_ID\",\n<16>: )\n<24>: raise QuicConnectionError(\n<25>: error_code=ErrorCode.HTTP_WRONG_STREAM,\n<26>: frame_type=None,\n<27>: raise WrongStream(\"Invalid frame type on control stream\")\n reason_phrase=\"Invalid frame type on control stream\",\n<28>: )\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _handle_control_frame(self, frame_type: int, frame_data: bytes) -> None:\n <0> \"\"\"\n <1> Handle a frame received on the peer's control stream.\n <2> \"\"\"\n <3> if frame_type == FrameType.SETTINGS:\n <4> settings = parse_settings(frame_data)\n <5> encoder = self._encoder.apply_settings(\n <6> max_table_capacity=settings.get(Setting.QPACK_MAX_TABLE_CAPACITY, 0),\n <7> blocked_streams=settings.get(Setting.QPACK_BLOCKED_STREAMS, 0),\n <8> )\n <9> self._quic.send_stream_data(self._local_encoder_stream_id, encoder)\n<10> elif frame_type == FrameType.MAX_PUSH_ID:\n<11> if self._is_client:\n<12> raise QuicConnectionError(\n<13> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n<14> frame_type=None,\n<15> reason_phrase=\"Servers must not send MAX_PUSH_ID\",\n<16> )\n<17> self._max_push_id = parse_max_push_id(frame_data)\n<18> elif frame_type in (\n<19> FrameType.DATA,\n<20> FrameType.HEADERS,\n<21> FrameType.PUSH_PROMISE,\n<22> FrameType.DUPLICATE_PUSH,\n<23> ):\n<24> raise QuicConnectionError(\n<25> error_code=ErrorCode.HTTP_WRONG_STREAM,\n<26> frame_type=None,\n<27> reason_phrase=\"Invalid frame type on control stream\",\n<28> )\n<29> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n at: aioquic.h3.connection.H3Connection\n _encode_headers(stream_id, headers: Headers) -> bytes\n _encode_headers(self, stream_id, headers: Headers) -> bytes\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._quic = quic\n \n self._decoder = pylsqpack.Decoder(\n self._max_table_capacity, self._blocked_streams\n )\n \n self._local_decoder_stream_id: Optional[int] = None\n \n at: aioquic.h3.connection.H3Connection._init_connection\n self._local_decoder_stream_id = self._create_uni_stream(\n StreamType.QPACK_DECODER\n )\n \n at: aioquic.h3.events\n Headers = List[Tuple[bytes, bytes]]\n \n at: aioquic.quic.connection.QuicConnection\n get_next_available_stream_id(is_unidirectional=False) -> int\n \n send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers:\n \"\"\"\n Decode a HEADERS block and send decoder updates on the decoder stream.\n \"\"\"\n + try:\n + decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n - decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n + self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n - self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n + except pylsqpack.DecompressionFailed as exc:\n + raise QpackDecompressionFailed() from exc\n + \n return headers\n \n===========changed ref 1===========\n # module: aioquic.h3.connection\n + class WrongStream(ProtocolError):\n + error_code = ErrorCode.HTTP_WRONG_STREAM\n + \n===========changed ref 2===========\n # module: aioquic.h3.connection\n + class UnexpectedFrame(ProtocolError):\n + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME\n + \n===========changed ref 3===========\n # module: aioquic.h3.connection\n + class StreamCreationError(ProtocolError):\n + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR\n + \n===========changed ref 4===========\n # module: aioquic.h3.connection\n + class QpackEncoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR\n + \n===========changed ref 5===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + def __init__(self, reason_phrase: str = \"\"):\n + self.reason_phrase = reason_phrase\n + \n===========changed ref 6===========\n # module: aioquic.h3.connection\n + class QpackDecoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR\n + \n===========changed ref 7===========\n # module: aioquic.h3.connection\n + class QpackDecompressionFailed(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED\n + \n===========changed ref 8===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + \"\"\"\n + Base class for protocol errors.\n + \n + These errors are not exposed to the API user, they are handled\n + in :meth:`H3Connection.handle_event`.\n + \"\"\"\n + \n + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR\n + \n===========changed ref 9===========\n # module: aioquic.h3.connection\n class H3Connection:\n def __init__(self, quic: QuicConnection):\n self._max_table_capacity = 0x100\n self._blocked_streams = 0x10\n \n self._is_client = quic.configuration.is_client\n self._quic = quic\n + self._decoder = pylsqpack.Decoder(\n + self._max_table_capacity, self._blocked_streams\n - self._decoder = Decoder(self._max_table_capacity, self._blocked_streams)\n + )\n + self._encoder = pylsqpack.Encoder()\n - self._encoder = Encoder()\n self._stream: Dict[int, H3Stream] = {}\n \n self._max_push_id: Optional[int] = 8 if self._is_client else None\n self._next_push_id: int = 0\n \n self._local_control_stream_id: Optional[int] = None\n self._local_decoder_stream_id: Optional[int] = None\n self._local_encoder_stream_id: Optional[int] = None\n \n self._peer_control_stream_id: Optional[int] = None\n self._peer_decoder_stream_id: Optional[int] = None\n self._peer_encoder_stream_id: Optional[int] = None\n \n self._init_connection()\n \n===========changed ref 10===========\n # module: aioquic.h3.connection\n class ErrorCode(IntEnum):\n HTTP_NO_ERROR = 0x00\n HTTP_GENERAL_PROTOCOL_ERROR = 0x01\n HTTP_INTERNAL_ERROR = 0x03\n HTTP_REQUEST_CANCELLED = 0x05\n HTTP_INCOMPLETE_REQUEST = 0x06\n HTTP_CONNECT_ERROR = 0x07\n HTTP_EXCESSIVE_LOAD = 0x08\n HTTP_VERSION_FALLBACK = 0x09\n HTTP_WRONG_STREAM = 0x0A\n HTTP_ID_ERROR = 0x0B\n HTTP_STREAM_CREATION_ERROR = 0x0D\n HTTP_CLOSED_CRITICAL_STREAM = 0x0F\n HTTP_EARLY_RESPONSE = 0x11\n HTTP_MISSING_SETTINGS = 0x12\n HTTP_UNEXPECTED_FRAME = 0x13\n HTTP_REQUEST_REJECTED = 0x14\n HTTP_SETTINGS_ERROR = 0xFF\n + HTTP_QPACK_DECOMPRESSION_FAILED = 0x200\n + HTTP_QPACK_ENCODER_STREAM_ERROR = 0x201\n + HTTP_QPACK_DECODER_STREAM_ERROR = 0x202\n "}}},{"rowIdx":3468,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._handle_request_or_push_frame"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"286c400feb5e3fdee22b0434ae89351de094c88a"},"commit_message":{"kind":"string","value":"[http3] add some internal exception types"},"ground_truth":{"kind":"string","value":" <9>: raise QuicConnectionError(\n<10>: error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n<11>: frame_type=None,\n<12>: raise UnexpectedFrame(\"DATA frame is not allowed in this state\")\n reason_phrase=\"DATA frame is not allowed in this state\",\n<13>: )\n<27>: raise QuicConnectionError(\n<28>: error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n<29>: frame_type=None,\n<30>: raise UnexpectedFrame(\"HEADERS frame is not allowed in this state\")\n reason_phrase=\"HEADERS frame is not allowed in this state\",\n<31>: )\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _handle_request_or_push_frame(\n self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool\n ) -> List[H3Event]:\n <0> \"\"\"\n <1> Handle a frame received on a request or push stream.\n <2> \"\"\"\n <3> http_events: List[H3Event] = []\n <4> stream = self._stream[stream_id]\n <5> \n <6> if frame_type == FrameType.DATA:\n <7> # check DATA frame is allowed\n <8> if stream.headers_state != HeadersState.AFTER_HEADERS:\n <9> raise QuicConnectionError(\n<10> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n<11> frame_type=None,\n<12> reason_phrase=\"DATA frame is not allowed in this state\",\n<13> )\n<14> \n<15> if stream_ended or frame_data:\n<16> http_events.append(\n<17> DataReceived(\n<18> data=frame_data,\n<19> push_id=stream.push_id,\n<20> stream_ended=stream_ended,\n<21> stream_id=stream_id,\n<22> )\n<23> )\n<24> elif frame_type == FrameType.HEADERS:\n<25> # check HEADERS frame is allowed\n<26> if stream.headers_state == HeadersState.AFTER_TRAILERS:\n<27> raise QuicConnectionError(\n<28> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n<29> frame_type=None,\n<30> reason_phrase=\"HEADERS frame is not allowed in this state\",\n<31> )\n<32> \n<33> # try to decode HEADERS\n<34> headers = self._decode_headers(stream_id, frame_data)\n<35> \n<36> # update state and emit headers\n<37> if stream.headers_state == HeadersState.INITIAL:\n<38> stream.headers_state = HeadersState.AFTER_HEADERS\n<39> else:\n<40> stream.headers_state = HeadersState.AFTER_TRAILERS\n<41> http_events.append(\n<42> HeadersReceived(\n<43> headers=headers,\n<44> push_id=stream"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _handle_request_or_push_frame(\n self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 1\n stream_id=stream_id,\n stream_ended=stream_ended,\n )\n )\n elif stream.frame_type == FrameType.PUSH_PROMISE and stream.push_id is None:\n if not self._is_client:\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_UNEXPECTED_FRAME,\n frame_type=None,\n reason_phrase=\"Clients must not send PUSH_PROMISE\",\n )\n frame_buf = Buffer(data=frame_data)\n push_id = frame_buf.pull_uint_var()\n headers = self._decode_headers(stream_id, frame_data[frame_buf.tell() :])\n http_events.append(\n PushPromiseReceived(\n headers=headers, push_id=push_id, stream_id=stream_id\n )\n )\n elif frame_type in (\n FrameType.PRIORITY,\n FrameType.CANCEL_PUSH,\n FrameType.SETTINGS,\n FrameType.PUSH_PROMISE,\n FrameType.GOAWAY,\n FrameType.MAX_PUSH_ID,\n FrameType.DUPLICATE_PUSH,\n ):\n raise QuicConnectionError(\n error_code=ErrorCode.HTTP_WRONG_STREAM,\n frame_type=None,\n reason_phrase=\"Invalid frame type on request stream\"\n if stream.push_id is None\n else \"Invalid frame type on push stream\",\n )\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n tell() -> int\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n HeadersState()\n \n Setting(x: Union[str, bytes, bytearray], base: int)\n Setting(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n QpackDecompressionFailed(reason_phrase: str=\"\")\n \n UnexpectedFrame(reason_phrase: str=\"\")\n \n WrongStream(reason_phrase: str=\"\")\n \n parse_max_push_id(data: bytes) -> int\n \n parse_settings(data: bytes) -> Dict[int, int]\n \n at: aioquic.h3.connection.H3Connection\n _decode_headers(stream_id: int, frame_data: bytes) -> Headers\n _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._is_client = quic.configuration.is_client\n \n self._quic = quic\n \n self._encoder = pylsqpack.Encoder()\n \n self._stream: Dict[int, H3Stream] = {}\n \n self._max_push_id: Optional[int] = 8 if self._is_client else None\n \n self._local_encoder_stream_id: Optional[int] = None\n \n at: aioquic.h3.connection.H3Connection._decode_headers\n decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n \n \n===========unchanged ref 1===========\n at: aioquic.h3.connection.H3Connection._init_connection\n self._local_encoder_stream_id = self._create_uni_stream(\n StreamType.QPACK_ENCODER\n )\n \n at: aioquic.h3.connection.H3Stream.__init__\n self.frame_type: Optional[int] = None\n \n self.headers_state: HeadersState = HeadersState.INITIAL\n \n self.push_id: Optional[int] = None\n \n at: aioquic.h3.events\n Headers = List[Tuple[bytes, bytes]]\n \n H3Event()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.h3.events.DataReceived\n data: bytes\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.h3.events.HeadersReceived\n headers: Headers\n \n stream_id: int\n \n stream_ended: bool\n \n push_id: Optional[int] = None\n \n at: aioquic.quic.connection.QuicConnection\n send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n at: typing.Mapping\n get(key: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T]\n get(key: _KT) -> Optional[_VT_co]\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers:\n \"\"\"\n Decode a HEADERS block and send decoder updates on the decoder stream.\n \"\"\"\n + try:\n + decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n - decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n + self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n - self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n + except pylsqpack.DecompressionFailed as exc:\n + raise QpackDecompressionFailed() from exc\n + \n return headers\n \n===========changed ref 1===========\n # module: aioquic.h3.connection\n + class WrongStream(ProtocolError):\n + error_code = ErrorCode.HTTP_WRONG_STREAM\n + \n===========changed ref 2===========\n # module: aioquic.h3.connection\n + class UnexpectedFrame(ProtocolError):\n + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME\n + \n===========changed ref 3===========\n # module: aioquic.h3.connection\n + class QpackDecompressionFailed(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED\n + \n===========changed ref 4===========\n # module: aioquic.h3.connection\n + class StreamCreationError(ProtocolError):\n + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR\n + \n===========changed ref 5===========\n # module: aioquic.h3.connection\n + class QpackEncoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR\n + \n===========changed ref 6===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + def __init__(self, reason_phrase: str = \"\"):\n + self.reason_phrase = reason_phrase\n + \n===========changed ref 7===========\n # module: aioquic.h3.connection\n + class QpackDecoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR\n + \n===========changed ref 8===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + \"\"\"\n + Base class for protocol errors.\n + \n + These errors are not exposed to the API user, they are handled\n + in :meth:`H3Connection.handle_event`.\n + \"\"\"\n + \n + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR\n + "}}},{"rowIdx":3469,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_request_or_push_data"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"286c400feb5e3fdee22b0434ae89351de094c88a"},"commit_message":{"kind":"string","value":"[http3] add some internal exception types"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_request_or_push_data(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n <0> \"\"\"\n <1> Handle data received on a request or push stream.\n <2> \"\"\"\n <3> http_events: List[H3Event] = []\n <4> \n <5> stream = self._stream[stream_id]\n <6> stream.buffer += data\n <7> if stream_ended:\n <8> stream.ended = True\n <9> if stream.blocked:\n<10> return http_events\n<11> \n<12> # shortcut for DATA frame fragments\n<13> if (\n<14> stream.frame_type == FrameType.DATA\n<15> and stream.frame_size is not None\n<16> and len(stream.buffer) < stream.frame_size\n<17> ):\n<18> http_events.append(\n<19> DataReceived(\n<20> data=stream.buffer,\n<21> push_id=stream.push_id,\n<22> stream_id=stream_id,\n<23> stream_ended=False,\n<24> )\n<25> )\n<26> stream.frame_size -= len(stream.buffer)\n<27> stream.buffer = b\"\"\n<28> return http_events\n<29> \n<30> # handle lone FIN\n<31> if stream_ended and not stream.buffer:\n<32> http_events.append(\n<33> DataReceived(\n<34> data=b\"\",\n<35> push_id=stream.push_id,\n<36> stream_id=stream_id,\n<37> stream_ended=True,\n<38> )\n<39> )\n<40> return http_events\n<41> \n<42> buf = Buffer(data=stream.buffer)\n<43> consumed = 0\n<44> \n<45> while not buf.eof():\n<46> # fetch next frame header\n<47> if stream.frame_size is None:\n<48> try:\n<49> stream.frame_type = buf.pull_uint_var()\n<50> stream.frame_size = buf.pull_uint_var()\n<51> except BufferReadError:\n<52> break\n<53> consumed = buf"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_request_or_push_data(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 1\n \n # check how much data is available\n chunk_size = min(stream.frame_size, buf.capacity - consumed)\n if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size:\n break\n \n # read available data\n frame_data = buf.pull_bytes(chunk_size)\n consumed = buf.tell()\n \n # detect end of frame\n stream.frame_size -= chunk_size\n if not stream.frame_size:\n stream.frame_size = None\n \n try:\n http_events.extend(\n self._handle_request_or_push_frame(\n frame_type=stream.frame_type,\n frame_data=frame_data,\n stream_id=stream_id,\n stream_ended=stream.ended and buf.eof(),\n )\n )\n except StreamBlocked:\n stream.blocked = True\n break\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n Setting(x: Union[str, bytes, bytearray], base: int)\n Setting(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n at: aioquic.h3.connection.H3Connection\n _create_uni_stream(stream_type: int) -> int\n _create_uni_stream(self, stream_type: int) -> int\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._max_table_capacity = 0x100\n \n self._blocked_streams = 0x10\n \n self._is_client = quic.configuration.is_client\n \n self._quic = quic\n \n self._stream: Dict[int, H3Stream] = {}\n \n self._max_push_id: Optional[int] = 8 if self._is_client else None\n \n self._local_control_stream_id: Optional[int] = None\n \n self._local_decoder_stream_id: Optional[int] = None\n \n self._local_encoder_stream_id: Optional[int] = None\n \n \n===========unchanged ref 1===========\n at: aioquic.h3.connection.H3Connection._handle_control_frame\n self._max_push_id = parse_max_push_id(frame_data)\n \n at: aioquic.h3.connection.H3Connection._init_connection\n self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL)\n \n at: aioquic.h3.connection.H3Stream.__init__\n self.blocked = False\n \n self.buffer = b\"\"\n \n self.ended = False\n \n self.frame_size: Optional[int] = None\n \n self.frame_type: Optional[int] = None\n \n self.push_id: Optional[int] = None\n \n at: aioquic.h3.events\n H3Event()\n \n DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None)\n \n at: aioquic.quic.connection.QuicConnection\n send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers:\n \"\"\"\n Decode a HEADERS block and send decoder updates on the decoder stream.\n \"\"\"\n + try:\n + decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n - decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n + self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n - self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n + except pylsqpack.DecompressionFailed as exc:\n + raise QpackDecompressionFailed() from exc\n + \n return headers\n \n===========changed ref 1===========\n # module: aioquic.h3.connection\n + class WrongStream(ProtocolError):\n + error_code = ErrorCode.HTTP_WRONG_STREAM\n + \n===========changed ref 2===========\n # module: aioquic.h3.connection\n + class UnexpectedFrame(ProtocolError):\n + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME\n + \n===========changed ref 3===========\n # module: aioquic.h3.connection\n + class StreamCreationError(ProtocolError):\n + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR\n + \n===========changed ref 4===========\n # module: aioquic.h3.connection\n + class QpackEncoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR\n + \n===========changed ref 5===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + def __init__(self, reason_phrase: str = \"\"):\n + self.reason_phrase = reason_phrase\n + \n===========changed ref 6===========\n # module: aioquic.h3.connection\n + class QpackDecoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR\n + \n===========changed ref 7===========\n # module: aioquic.h3.connection\n + class QpackDecompressionFailed(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED\n + \n===========changed ref 8===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + \"\"\"\n + Base class for protocol errors.\n + \n + These errors are not exposed to the API user, they are handled\n + in :meth:`H3Connection.handle_event`.\n + \"\"\"\n + \n + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR\n + "}}},{"rowIdx":3470,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_stream_data_uni"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"286c400feb5e3fdee22b0434ae89351de094c88a"},"commit_message":{"kind":"string","value":"[http3] add some internal exception types"},"ground_truth":{"kind":"string","value":"<22>: if self._peer_control_stream_id is not None:\n assert self._peer_control_stream_id is None\n<23>: raise StreamCreationError(\"Only one control stream is allowed\")\n<25>: if self._peer_decoder_stream_id is not None:\n assert self._peer_decoder_stream_id is None\n<26>: raise StreamCreationError(\n \"Only one QPACK decoder stream is allowed\"\n )\n<28>: if self._peer_encoder_stream_id is not None:\n assert self._peer_encoder_stream_id is None\n<29>: raise StreamCreationError(\n \"Only one QPACK encoder stream is allowed\"\n )\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n <0> http_events: List[H3Event] = []\n <1> \n <2> stream = self._stream[stream_id]\n <3> stream.buffer += data\n <4> if stream_ended:\n <5> stream.ended = True\n <6> \n <7> buf = Buffer(data=stream.buffer)\n <8> consumed = 0\n <9> unblocked_streams: Set[int] = set()\n<10> \n<11> while stream.stream_type == StreamType.PUSH or not buf.eof():\n<12> # fetch stream type for unidirectional streams\n<13> if stream.stream_type is None:\n<14> try:\n<15> stream.stream_type = buf.pull_uint_var()\n<16> except BufferReadError:\n<17> break\n<18> consumed = buf.tell()\n<19> \n<20> # check unicity\n<21> if stream.stream_type == StreamType.CONTROL:\n<22> assert self._peer_control_stream_id is None\n<23> self._peer_control_stream_id = stream_id\n<24> elif stream.stream_type == StreamType.QPACK_DECODER:\n<25> assert self._peer_decoder_stream_id is None\n<26> self._peer_decoder_stream_id = stream_id\n<27> elif stream.stream_type == StreamType.QPACK_ENCODER:\n<28> assert self._peer_encoder_stream_id is None\n<29> self._peer_encoder_stream_id = stream_id\n<30> \n<31> if stream.stream_type == StreamType.CONTROL:\n<32> # fetch next frame\n<33> try:\n<34> frame_type = buf.pull_uint_var()\n<35> frame_length = buf.pull_uint_var()\n<36> frame_data = buf.pull_bytes(frame_length)\n<37> except BufferReadError:\n<38> break\n<39> consumed = buf.tell()\n<40> \n<41> self._handle_control_frame(frame_type"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 1\n elif stream.stream_type == StreamType.PUSH:\n # fetch push id\n if stream.push_id is None:\n try:\n stream.push_id = buf.pull_uint_var()\n except BufferReadError:\n break\n consumed = buf.tell()\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n return self._receive_request_or_push_data(stream_id, b\"\", stream_ended)\n elif stream.stream_type == StreamType.QPACK_DECODER:\n # feed unframed data to decoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n self._encoder.feed_decoder(data)\n elif stream.stream_type == StreamType.QPACK_ENCODER:\n # feed unframed data to encoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n unblocked_streams.update(self._decoder.feed_encoder(data))\n else:\n # unknown stream type, discard data\n buf.seek(buf.capacity)\n consumed = buf.tell()\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n # process unblocked streams\n for stream_id in unblocked_streams:\n stream = self._stream[stream_id]\n \n # decode headers\n decoder, headers = self._decoder.resume_header(stream_id)\n self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n stream.blocked = False\n \n # update state and emit headers\n if stream.headers_state == HeadersState.INITIAL:\n stream.headers_state = HeadersState.AFTER_HEADERS\n else:\n===========below chunk 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 2\n if stream.headers_state == HeadersState.INITIAL:\n stream.headers_state = HeadersState.AFTER_HEADERS\n else:\n stream.headers_state = HeadersState.AFTER_TRAILERS\n http_events.append(\n HeadersReceived(\n headers=headers,\n stream_id=stream_id,\n stream_ended=stream.ended and not stream.buffer,\n )\n )\n \n # resume processing\n if stream.buffer:\n http_events.extend(\n self._receive_request_or_push_data(stream_id, b\"\", stream.ended)\n )\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n seek(pos: int) -> None\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n QpackDecoderStreamError(reason_phrase: str=\"\")\n \n QpackEncoderStreamError(reason_phrase: str=\"\")\n \n StreamCreationError(reason_phrase: str=\"\")\n \n at: aioquic.h3.connection.H3Connection\n _handle_control_frame(frame_type: int, frame_data: bytes) -> None\n _handle_control_frame(self, frame_type: int, frame_data: bytes) -> None\n \n _handle_request_or_push_frame(frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool) -> List[H3Event]\n _handle_request_or_push_frame(self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool) -> List[H3Event]\n \n _receive_request_or_push_data(self, stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event]\n _receive_request_or_push_data(stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event]\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._decoder = pylsqpack.Decoder(\n self._max_table_capacity, self._blocked_streams\n )\n \n self._encoder = pylsqpack.Encoder()\n \n \n===========unchanged ref 1===========\n self._stream: Dict[int, H3Stream] = {}\n \n self._peer_control_stream_id: Optional[int] = None\n \n self._peer_decoder_stream_id: Optional[int] = None\n \n self._peer_encoder_stream_id: Optional[int] = None\n \n at: aioquic.h3.connection.H3Connection._receive_request_or_push_data\n http_events: List[H3Event] = []\n \n stream = self._stream[stream_id]\n \n buf = Buffer(data=stream.buffer)\n \n consumed = buf.tell()\n consumed = 0\n \n frame_data = buf.pull_bytes(chunk_size)\n \n at: aioquic.h3.events\n H3Event()\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n Set = _alias(set, 1, inst=False, name='Set')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n + class StreamCreationError(ProtocolError):\n + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR\n + \n===========changed ref 1===========\n # module: aioquic.h3.connection\n + class QpackEncoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR\n + \n===========changed ref 2===========\n # module: aioquic.h3.connection\n + class QpackDecoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR\n + "}}},{"rowIdx":3471,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_control_frame_headers"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"286c400feb5e3fdee22b0434ae89351de094c88a"},"commit_message":{"kind":"string","value":"[http3] add some internal exception types"},"ground_truth":{"kind":"string","value":" <8>: with self.assertRaises(WrongStream) as cm:\n with self.assertRaises(QuicConnectionError) as cm:\n <9>: h3_server.handle_event(\n StreamDataReceived(\n stream_id=2,\n data=encode_uint_var(StreamType.CONTROL)\n + encode_frame(FrameType.HEADERS, b\"\"),\n end_stream=False,\n )\n )\n self.assertEqual(str(cm.exception), \"Invalid frame type on control stream\")\n h3_server._handle_control_frame(FrameType.HEADERS, b\"\")\n<10>: self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_headers(self):\n <0> \"\"\"\n <1> We should not receive HEADERS on the control stream.\n <2> \"\"\"\n <3> quic_server = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=False)\n <5> )\n <6> h3_server = H3Connection(quic_server)\n <7> \n <8> with self.assertRaises(QuicConnectionError) as cm:\n <9> h3_server._handle_control_frame(FrameType.HEADERS, b\"\")\n<10> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n<11> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h3.connection\n H3Connection(quic: QuicConnection)\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.configuration.QuicConfiguration\n alpn_protocols: Optional[List[str]] = None\n \n certificate: Any = None\n \n connection_id_length: int = 8\n \n idle_timeout: float = 60.0\n \n is_client: bool = True\n \n private_key: Any = None\n \n quic_logger: Optional[QuicLogger] = None\n \n secrets_log_file: TextIO = None\n \n server_name: Optional[str] = None\n \n session_ticket: Optional[SessionTicket] = None\n \n supported_versions: List[int] = field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n )\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: tests.test_h3.H3ConnectionTest\n maxDiff = None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + def __init__(self, reason_phrase: str = \"\"):\n + self.reason_phrase = reason_phrase\n + \n===========changed ref 1===========\n # module: aioquic.h3.connection\n + class WrongStream(ProtocolError):\n + error_code = ErrorCode.HTTP_WRONG_STREAM\n + \n===========changed ref 2===========\n # module: aioquic.h3.connection\n + class UnexpectedFrame(ProtocolError):\n + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME\n + \n===========changed ref 3===========\n # module: aioquic.h3.connection\n + class StreamCreationError(ProtocolError):\n + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR\n + \n===========changed ref 4===========\n # module: aioquic.h3.connection\n + class QpackDecompressionFailed(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED\n + \n===========changed ref 5===========\n # module: aioquic.h3.connection\n + class QpackEncoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR\n + \n===========changed ref 6===========\n # module: aioquic.h3.connection\n + class QpackDecoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR\n + \n===========changed ref 7===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + \"\"\"\n + Base class for protocol errors.\n + \n + These errors are not exposed to the API user, they are handled\n + in :meth:`H3Connection.handle_event`.\n + \"\"\"\n + \n + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR\n + \n===========changed ref 8===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers:\n \"\"\"\n Decode a HEADERS block and send decoder updates on the decoder stream.\n \"\"\"\n + try:\n + decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n - decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n + self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n - self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n + except pylsqpack.DecompressionFailed as exc:\n + raise QpackDecompressionFailed() from exc\n + \n return headers\n \n===========changed ref 9===========\n # module: aioquic.h3.connection\n class ErrorCode(IntEnum):\n HTTP_NO_ERROR = 0x00\n HTTP_GENERAL_PROTOCOL_ERROR = 0x01\n HTTP_INTERNAL_ERROR = 0x03\n HTTP_REQUEST_CANCELLED = 0x05\n HTTP_INCOMPLETE_REQUEST = 0x06\n HTTP_CONNECT_ERROR = 0x07\n HTTP_EXCESSIVE_LOAD = 0x08\n HTTP_VERSION_FALLBACK = 0x09\n HTTP_WRONG_STREAM = 0x0A\n HTTP_ID_ERROR = 0x0B\n HTTP_STREAM_CREATION_ERROR = 0x0D\n HTTP_CLOSED_CRITICAL_STREAM = 0x0F\n HTTP_EARLY_RESPONSE = 0x11\n HTTP_MISSING_SETTINGS = 0x12\n HTTP_UNEXPECTED_FRAME = 0x13\n HTTP_REQUEST_REJECTED = 0x14\n HTTP_SETTINGS_ERROR = 0xFF\n + HTTP_QPACK_DECOMPRESSION_FAILED = 0x200\n + HTTP_QPACK_ENCODER_STREAM_ERROR = 0x201\n + HTTP_QPACK_DECODER_STREAM_ERROR = 0x202\n \n===========changed ref 10===========\n # module: aioquic.h3.connection\n class H3Connection:\n def __init__(self, quic: QuicConnection):\n self._max_table_capacity = 0x100\n self._blocked_streams = 0x10\n \n self._is_client = quic.configuration.is_client\n self._quic = quic\n + self._decoder = pylsqpack.Decoder(\n + self._max_table_capacity, self._blocked_streams\n - self._decoder = Decoder(self._max_table_capacity, self._blocked_streams)\n + )\n + self._encoder = pylsqpack.Encoder()\n - self._encoder = Encoder()\n self._stream: Dict[int, H3Stream] = {}\n \n self._max_push_id: Optional[int] = 8 if self._is_client else None\n self._next_push_id: int = 0\n \n self._local_control_stream_id: Optional[int] = None\n self._local_decoder_stream_id: Optional[int] = None\n self._local_encoder_stream_id: Optional[int] = None\n \n self._peer_control_stream_id: Optional[int] = None\n self._peer_decoder_stream_id: Optional[int] = None\n self._peer_encoder_stream_id: Optional[int] = None\n \n self._init_connection()\n "}}},{"rowIdx":3472,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_control_frame_max_push_id_from_server"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"286c400feb5e3fdee22b0434ae89351de094c88a"},"commit_message":{"kind":"string","value":"[http3] add some internal exception types"},"ground_truth":{"kind":"string","value":" <8>: with self.assertRaises(UnexpectedFrame) as cm:\n with self.assertRaises(QuicConnectionError) as cm:\n <9>: h3_client.handle_event(\n StreamDataReceived(\n stream_id=3,\n data=encode_uint_var(StreamType.CONTROL)\n + encode_frame(FrameType.MAX_PUSH_ID, b\"\"),\n end_stream=False,\n )\n )\n self.assertEqual(str(cm.exception), \"Servers must not send MAX_PUSH_ID\")\n h3_client._handle_control_frame(FrameType.MAX_PUSH_ID, encode_uint_var(0))\n<10>: self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_max_push_id_from_server(self):\n <0> \"\"\"\n <1> A client should not receive MAX_PUSH_ID on the control stream.\n <2> \"\"\"\n <3> quic_client = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=True)\n <5> )\n <6> h3_client = H3Connection(quic_client)\n <7> \n <8> with self.assertRaises(QuicConnectionError) as cm:\n <9> h3_client._handle_control_frame(FrameType.MAX_PUSH_ID, encode_uint_var(0))\n<10> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)\n<11> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n WrongStream(reason_phrase: str=\"\")\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: aioquic.quic.events.StreamDataReceived\n data: bytes\n \n end_stream: bool\n \n stream_id: int\n \n at: tests.test_h3.H3ConnectionTest.test_handle_control_frame_headers\n h3_server = H3Connection(quic_server)\n \n at: unittest.case.TestCase\n failureException: Type[BaseException]\n \n longMessage: bool\n \n maxDiff: Optional[int]\n \n _testMethodName: str\n \n _testMethodDoc: str\n \n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E]\n assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None\n \n at: unittest.case._AssertRaisesContext.__exit__\n self.exception = exc_value.with_traceback(None)\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n + class WrongStream(ProtocolError):\n + error_code = ErrorCode.HTTP_WRONG_STREAM\n + \n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_headers(self):\n \"\"\"\n We should not receive HEADERS on the control stream.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n + with self.assertRaises(WrongStream) as cm:\n - with self.assertRaises(QuicConnectionError) as cm:\n + h3_server.handle_event(\n + StreamDataReceived(\n + stream_id=2,\n + data=encode_uint_var(StreamType.CONTROL)\n + + encode_frame(FrameType.HEADERS, b\"\"),\n + end_stream=False,\n + )\n + )\n + self.assertEqual(str(cm.exception), \"Invalid frame type on control stream\")\n - h3_server._handle_control_frame(FrameType.HEADERS, b\"\")\n - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n \n===========changed ref 2===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + def __init__(self, reason_phrase: str = \"\"):\n + self.reason_phrase = reason_phrase\n + \n===========changed ref 3===========\n # module: aioquic.h3.connection\n + class UnexpectedFrame(ProtocolError):\n + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME\n + \n===========changed ref 4===========\n # module: aioquic.h3.connection\n + class StreamCreationError(ProtocolError):\n + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR\n + \n===========changed ref 5===========\n # module: aioquic.h3.connection\n + class QpackDecompressionFailed(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED\n + \n===========changed ref 6===========\n # module: aioquic.h3.connection\n + class QpackEncoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR\n + \n===========changed ref 7===========\n # module: aioquic.h3.connection\n + class QpackDecoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR\n + \n===========changed ref 8===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + \"\"\"\n + Base class for protocol errors.\n + \n + These errors are not exposed to the API user, they are handled\n + in :meth:`H3Connection.handle_event`.\n + \"\"\"\n + \n + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR\n + \n===========changed ref 9===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers:\n \"\"\"\n Decode a HEADERS block and send decoder updates on the decoder stream.\n \"\"\"\n + try:\n + decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n - decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n + self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n - self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n + except pylsqpack.DecompressionFailed as exc:\n + raise QpackDecompressionFailed() from exc\n + \n return headers\n \n===========changed ref 10===========\n # module: aioquic.h3.connection\n class ErrorCode(IntEnum):\n HTTP_NO_ERROR = 0x00\n HTTP_GENERAL_PROTOCOL_ERROR = 0x01\n HTTP_INTERNAL_ERROR = 0x03\n HTTP_REQUEST_CANCELLED = 0x05\n HTTP_INCOMPLETE_REQUEST = 0x06\n HTTP_CONNECT_ERROR = 0x07\n HTTP_EXCESSIVE_LOAD = 0x08\n HTTP_VERSION_FALLBACK = 0x09\n HTTP_WRONG_STREAM = 0x0A\n HTTP_ID_ERROR = 0x0B\n HTTP_STREAM_CREATION_ERROR = 0x0D\n HTTP_CLOSED_CRITICAL_STREAM = 0x0F\n HTTP_EARLY_RESPONSE = 0x11\n HTTP_MISSING_SETTINGS = 0x12\n HTTP_UNEXPECTED_FRAME = 0x13\n HTTP_REQUEST_REJECTED = 0x14\n HTTP_SETTINGS_ERROR = 0xFF\n + HTTP_QPACK_DECOMPRESSION_FAILED = 0x200\n + HTTP_QPACK_ENCODER_STREAM_ERROR = 0x201\n + HTTP_QPACK_DECODER_STREAM_ERROR = 0x202\n \n===========changed ref 11===========\n # module: aioquic.h3.connection\n class H3Connection:\n def __init__(self, quic: QuicConnection):\n self._max_table_capacity = 0x100\n self._blocked_streams = 0x10\n \n self._is_client = quic.configuration.is_client\n self._quic = quic\n + self._decoder = pylsqpack.Decoder(\n + self._max_table_capacity, self._blocked_streams\n - self._decoder = Decoder(self._max_table_capacity, self._blocked_streams)\n + )\n + self._encoder = pylsqpack.Encoder()\n - self._encoder = Encoder()\n self._stream: Dict[int, H3Stream] = {}\n \n self._max_push_id: Optional[int] = 8 if self._is_client else None\n self._next_push_id: int = 0\n \n self._local_control_stream_id: Optional[int] = None\n self._local_decoder_stream_id: Optional[int] = None\n self._local_encoder_stream_id: Optional[int] = None\n \n self._peer_control_stream_id: Optional[int] = None\n self._peer_decoder_stream_id: Optional[int] = None\n self._peer_encoder_stream_id: Optional[int] = None\n \n self._init_connection()\n "}}},{"rowIdx":3473,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_push_frame_wrong_frame_type"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"286c400feb5e3fdee22b0434ae89351de094c88a"},"commit_message":{"kind":"string","value":"[http3] add some internal exception types"},"ground_truth":{"kind":"string","value":" <0>: \"\"\"\n We should not received SETTINGS on a push stream.\n \"\"\"\n <5>: with self.assertRaises(WrongStream) as cm:\n with self.assertRaises(QuicConnectionError) as cm:\n<15>: self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n<16>: self.assertEqual(\n<17>: self.assertEqual(str(cm.exception), \"Invalid frame type on push stream\")\n str(cm.exception), \"Error: 10, reason: Invalid frame type on push stream\"\n<18>: )\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_push_frame_wrong_frame_type(self):\n <0> quic_client = FakeQuicConnection(\n <1> configuration=QuicConfiguration(is_client=True)\n <2> )\n <3> h3_client = H3Connection(quic_client)\n <4> \n <5> with self.assertRaises(QuicConnectionError) as cm:\n <6> h3_client.handle_event(\n <7> StreamDataReceived(\n <8> stream_id=15,\n <9> data=encode_uint_var(StreamType.PUSH)\n<10> + encode_uint_var(0) # push ID\n<11> + encode_frame(FrameType.SETTINGS, b\"\"),\n<12> end_stream=False,\n<13> )\n<14> )\n<15> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n<16> self.assertEqual(\n<17> str(cm.exception), \"Error: 10, reason: Invalid frame type on push stream\"\n<18> )\n<19> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n UnexpectedFrame(reason_phrase: str=\"\")\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========unchanged ref 1===========\n assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E]\n assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None\n \n at: unittest.case._AssertRaisesContext.__exit__\n self.exception = exc_value.with_traceback(None)\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n + class UnexpectedFrame(ProtocolError):\n + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME\n + \n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_headers(self):\n \"\"\"\n We should not receive HEADERS on the control stream.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n + with self.assertRaises(WrongStream) as cm:\n - with self.assertRaises(QuicConnectionError) as cm:\n + h3_server.handle_event(\n + StreamDataReceived(\n + stream_id=2,\n + data=encode_uint_var(StreamType.CONTROL)\n + + encode_frame(FrameType.HEADERS, b\"\"),\n + end_stream=False,\n + )\n + )\n + self.assertEqual(str(cm.exception), \"Invalid frame type on control stream\")\n - h3_server._handle_control_frame(FrameType.HEADERS, b\"\")\n - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n \n===========changed ref 2===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_max_push_id_from_server(self):\n \"\"\"\n A client should not receive MAX_PUSH_ID on the control stream.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n + with self.assertRaises(UnexpectedFrame) as cm:\n - with self.assertRaises(QuicConnectionError) as cm:\n + h3_client.handle_event(\n + StreamDataReceived(\n + stream_id=3,\n + data=encode_uint_var(StreamType.CONTROL)\n + + encode_frame(FrameType.MAX_PUSH_ID, b\"\"),\n + end_stream=False,\n + )\n + )\n + self.assertEqual(str(cm.exception), \"Servers must not send MAX_PUSH_ID\")\n - h3_client._handle_control_frame(FrameType.MAX_PUSH_ID, encode_uint_var(0))\n - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)\n \n===========changed ref 3===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + def __init__(self, reason_phrase: str = \"\"):\n + self.reason_phrase = reason_phrase\n + \n===========changed ref 4===========\n # module: aioquic.h3.connection\n + class WrongStream(ProtocolError):\n + error_code = ErrorCode.HTTP_WRONG_STREAM\n + \n===========changed ref 5===========\n # module: aioquic.h3.connection\n + class StreamCreationError(ProtocolError):\n + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR\n + \n===========changed ref 6===========\n # module: aioquic.h3.connection\n + class QpackDecompressionFailed(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED\n + \n===========changed ref 7===========\n # module: aioquic.h3.connection\n + class QpackEncoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR\n + \n===========changed ref 8===========\n # module: aioquic.h3.connection\n + class QpackDecoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR\n + \n===========changed ref 9===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + \"\"\"\n + Base class for protocol errors.\n + \n + These errors are not exposed to the API user, they are handled\n + in :meth:`H3Connection.handle_event`.\n + \"\"\"\n + \n + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR\n + \n===========changed ref 10===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers:\n \"\"\"\n Decode a HEADERS block and send decoder updates on the decoder stream.\n \"\"\"\n + try:\n + decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n - decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n + self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n - self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n + except pylsqpack.DecompressionFailed as exc:\n + raise QpackDecompressionFailed() from exc\n + \n return headers\n "}}},{"rowIdx":3474,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_request_frame_data_before_headers"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"286c400feb5e3fdee22b0434ae89351de094c88a"},"commit_message":{"kind":"string","value":"[http3] add some internal exception types"},"ground_truth":{"kind":"string","value":" <8>: with self.assertRaises(UnexpectedFrame) as cm:\n with self.assertRaises(QuicConnectionError) as cm:\n<16>: self.assertEqual(str(cm.exception), \"DATA frame is not allowed in this state\")\n self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_data_before_headers(self):\n <0> \"\"\"\n <1> We should not receive DATA before receiving headers.\n <2> \"\"\"\n <3> quic_server = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=False)\n <5> )\n <6> h3_server = H3Connection(quic_server)\n <7> \n <8> with self.assertRaises(QuicConnectionError) as cm:\n <9> h3_server.handle_event(\n<10> StreamDataReceived(\n<11> stream_id=0,\n<12> data=encode_frame(FrameType.DATA, b\"\"),\n<13> end_stream=False,\n<14> )\n<15> )\n<16> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)\n<17> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n StreamCreationError(reason_phrase: str=\"\")\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: unittest.case.TestCase\n assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E]\n assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n + class StreamCreationError(ProtocolError):\n + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR\n + \n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n + def test_handle_control_stream_duplicate(self):\n + \"\"\"\n + We must only receive a single control stream.\n + \"\"\"\n + quic_server = FakeQuicConnection(\n + configuration=QuicConfiguration(is_client=False)\n + )\n + h3_server = H3Connection(quic_server)\n + \n + # receive a first control stream\n + h3_server.handle_event(\n + StreamDataReceived(\n + stream_id=2, data=encode_uint_var(StreamType.CONTROL), end_stream=False\n + )\n + )\n + with self.assertRaises(StreamCreationError) as cm:\n + # receive a second control stream\n + h3_server.handle_event(\n + StreamDataReceived(\n + stream_id=6,\n + data=encode_uint_var(StreamType.CONTROL),\n + end_stream=False,\n + )\n + )\n + self.assertEqual(str(cm.exception), \"Only one control stream is allowed\")\n + \n===========changed ref 2===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_push_frame_wrong_frame_type(self):\n + \"\"\"\n + We should not received SETTINGS on a push stream.\n + \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n + with self.assertRaises(WrongStream) as cm:\n - with self.assertRaises(QuicConnectionError) as cm:\n h3_client.handle_event(\n StreamDataReceived(\n stream_id=15,\n data=encode_uint_var(StreamType.PUSH)\n + encode_uint_var(0) # push ID\n + encode_frame(FrameType.SETTINGS, b\"\"),\n end_stream=False,\n )\n )\n - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n - self.assertEqual(\n + self.assertEqual(str(cm.exception), \"Invalid frame type on push stream\")\n - str(cm.exception), \"Error: 10, reason: Invalid frame type on push stream\"\n - )\n \n===========changed ref 3===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_headers(self):\n \"\"\"\n We should not receive HEADERS on the control stream.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n + with self.assertRaises(WrongStream) as cm:\n - with self.assertRaises(QuicConnectionError) as cm:\n + h3_server.handle_event(\n + StreamDataReceived(\n + stream_id=2,\n + data=encode_uint_var(StreamType.CONTROL)\n + + encode_frame(FrameType.HEADERS, b\"\"),\n + end_stream=False,\n + )\n + )\n + self.assertEqual(str(cm.exception), \"Invalid frame type on control stream\")\n - h3_server._handle_control_frame(FrameType.HEADERS, b\"\")\n - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n \n===========changed ref 4===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_max_push_id_from_server(self):\n \"\"\"\n A client should not receive MAX_PUSH_ID on the control stream.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n + with self.assertRaises(UnexpectedFrame) as cm:\n - with self.assertRaises(QuicConnectionError) as cm:\n + h3_client.handle_event(\n + StreamDataReceived(\n + stream_id=3,\n + data=encode_uint_var(StreamType.CONTROL)\n + + encode_frame(FrameType.MAX_PUSH_ID, b\"\"),\n + end_stream=False,\n + )\n + )\n + self.assertEqual(str(cm.exception), \"Servers must not send MAX_PUSH_ID\")\n - h3_client._handle_control_frame(FrameType.MAX_PUSH_ID, encode_uint_var(0))\n - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)\n \n===========changed ref 5===========\n # module: aioquic.h3.connection\n + class ProtocolError(Exception):\n + def __init__(self, reason_phrase: str = \"\"):\n + self.reason_phrase = reason_phrase\n + \n===========changed ref 6===========\n # module: aioquic.h3.connection\n + class WrongStream(ProtocolError):\n + error_code = ErrorCode.HTTP_WRONG_STREAM\n + \n===========changed ref 7===========\n # module: aioquic.h3.connection\n + class UnexpectedFrame(ProtocolError):\n + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME\n + \n===========changed ref 8===========\n # module: aioquic.h3.connection\n + class QpackDecompressionFailed(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED\n + \n===========changed ref 9===========\n # module: aioquic.h3.connection\n + class QpackEncoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR\n + \n===========changed ref 10===========\n # module: aioquic.h3.connection\n + class QpackDecoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR\n + "}}},{"rowIdx":3475,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_request_frame_headers_after_trailers"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"286c400feb5e3fdee22b0434ae89351de094c88a"},"commit_message":{"kind":"string","value":"[http3] add some internal exception types"},"ground_truth":{"kind":"string","value":"<28>: with self.assertRaises(UnexpectedFrame) as cm:\n with self.assertRaises(QuicConnectionError) as cm:\n<36>: self.assertEqual(\n str(cm.exception), \"HEADERS frame is not allowed in this state\"\n )\n self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_headers_after_trailers(self):\n <0> \"\"\"\n <1> We should not receive HEADERS after receiving trailers.\n <2> \"\"\"\n <3> quic_client = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=True)\n <5> )\n <6> quic_server = FakeQuicConnection(\n <7> configuration=QuicConfiguration(is_client=False)\n <8> )\n <9> \n<10> h3_client = H3Connection(quic_client)\n<11> h3_server = H3Connection(quic_server)\n<12> \n<13> stream_id = quic_client.get_next_available_stream_id()\n<14> h3_client.send_headers(\n<15> stream_id=stream_id,\n<16> headers=[\n<17> (b\":method\", b\"GET\"),\n<18> (b\":scheme\", b\"https\"),\n<19> (b\":authority\", b\"localhost\"),\n<20> (b\":path\", b\"/\"),\n<21> ],\n<22> )\n<23> h3_client.send_headers(\n<24> stream_id=stream_id, headers=[(b\"x-some-trailer\", b\"foo\")], end_stream=True\n<25> )\n<26> h3_transfer(quic_client, h3_server)\n<27> \n<28> with self.assertRaises(QuicConnectionError) as cm:\n<29> h3_server.handle_event(\n<30> StreamDataReceived(\n<31> stream_id=0,\n<32> data=encode_frame(FrameType.HEADERS, b\"\"),\n<33> end_stream=False,\n<34> )\n<35> )\n<36> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)\n<37> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n WrongStream(reason_phrase: str=\"\")\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========unchanged ref 1===========\n assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E]\n assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None\n \n at: unittest.case._AssertRaisesContext.__exit__\n self.exception = exc_value.with_traceback(None)\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n + class WrongStream(ProtocolError):\n + error_code = ErrorCode.HTTP_WRONG_STREAM\n + \n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_data_before_headers(self):\n \"\"\"\n We should not receive DATA before receiving headers.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n + with self.assertRaises(UnexpectedFrame) as cm:\n - with self.assertRaises(QuicConnectionError) as cm:\n h3_server.handle_event(\n StreamDataReceived(\n stream_id=0,\n data=encode_frame(FrameType.DATA, b\"\"),\n end_stream=False,\n )\n )\n + self.assertEqual(str(cm.exception), \"DATA frame is not allowed in this state\")\n - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)\n \n===========changed ref 2===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n + def test_handle_control_stream_duplicate(self):\n + \"\"\"\n + We must only receive a single control stream.\n + \"\"\"\n + quic_server = FakeQuicConnection(\n + configuration=QuicConfiguration(is_client=False)\n + )\n + h3_server = H3Connection(quic_server)\n + \n + # receive a first control stream\n + h3_server.handle_event(\n + StreamDataReceived(\n + stream_id=2, data=encode_uint_var(StreamType.CONTROL), end_stream=False\n + )\n + )\n + with self.assertRaises(StreamCreationError) as cm:\n + # receive a second control stream\n + h3_server.handle_event(\n + StreamDataReceived(\n + stream_id=6,\n + data=encode_uint_var(StreamType.CONTROL),\n + end_stream=False,\n + )\n + )\n + self.assertEqual(str(cm.exception), \"Only one control stream is allowed\")\n + \n===========changed ref 3===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_push_frame_wrong_frame_type(self):\n + \"\"\"\n + We should not received SETTINGS on a push stream.\n + \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n + with self.assertRaises(WrongStream) as cm:\n - with self.assertRaises(QuicConnectionError) as cm:\n h3_client.handle_event(\n StreamDataReceived(\n stream_id=15,\n data=encode_uint_var(StreamType.PUSH)\n + encode_uint_var(0) # push ID\n + encode_frame(FrameType.SETTINGS, b\"\"),\n end_stream=False,\n )\n )\n - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n - self.assertEqual(\n + self.assertEqual(str(cm.exception), \"Invalid frame type on push stream\")\n - str(cm.exception), \"Error: 10, reason: Invalid frame type on push stream\"\n - )\n \n===========changed ref 4===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_headers(self):\n \"\"\"\n We should not receive HEADERS on the control stream.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n + with self.assertRaises(WrongStream) as cm:\n - with self.assertRaises(QuicConnectionError) as cm:\n + h3_server.handle_event(\n + StreamDataReceived(\n + stream_id=2,\n + data=encode_uint_var(StreamType.CONTROL)\n + + encode_frame(FrameType.HEADERS, b\"\"),\n + end_stream=False,\n + )\n + )\n + self.assertEqual(str(cm.exception), \"Invalid frame type on control stream\")\n - h3_server._handle_control_frame(FrameType.HEADERS, b\"\")\n - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n "}}},{"rowIdx":3476,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_request_frame_push_promise_from_client"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"286c400feb5e3fdee22b0434ae89351de094c88a"},"commit_message":{"kind":"string","value":"[http3] add some internal exception types"},"ground_truth":{"kind":"string","value":" <8>: with self.assertRaises(UnexpectedFrame) as cm:\n with self.assertRaises(QuicConnectionError) as cm:\n<16>: self.assertEqual(str(cm.exception), \"Clients must not send PUSH_PROMISE\")\n self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_push_promise_from_client(self):\n <0> \"\"\"\n <1> A server should not receive PUSH_PROMISE on a request stream.\n <2> \"\"\"\n <3> quic_server = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=False)\n <5> )\n <6> h3_server = H3Connection(quic_server)\n <7> \n <8> with self.assertRaises(QuicConnectionError) as cm:\n <9> h3_server.handle_event(\n<10> StreamDataReceived(\n<11> stream_id=0,\n<12> data=encode_frame(FrameType.PUSH_PROMISE, b\"\"),\n<13> end_stream=False,\n<14> )\n<15> )\n<16> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)\n<17> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n StreamCreationError(reason_phrase: str=\"\")\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: tests.test_h3.H3ConnectionTest.test_handle_qpack_decoder_duplicate\n h3_client = H3Connection(quic_client)\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E]\n assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None\n \n \n===========unchanged ref 1===========\n at: unittest.case._AssertRaisesContext.__exit__\n self.exception = exc_value.with_traceback(None)\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n + class StreamCreationError(ProtocolError):\n + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR\n + \n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n + def test_handle_qpack_decoder_duplicate(self):\n + \"\"\"\n + We must only receive a single QPACK decoder stream.\n + \"\"\"\n + quic_client = FakeQuicConnection(\n + configuration=QuicConfiguration(is_client=True)\n + )\n + h3_client = H3Connection(quic_client)\n + \n + h3_client.handle_event(\n + StreamDataReceived(\n + stream_id=11,\n + data=encode_uint_var(StreamType.QPACK_DECODER),\n + end_stream=False,\n + )\n + )\n + with self.assertRaises(StreamCreationError) as cm:\n + h3_client.handle_event(\n + StreamDataReceived(\n + stream_id=15,\n + data=encode_uint_var(StreamType.QPACK_DECODER),\n + end_stream=False,\n + )\n + )\n + self.assertEqual(str(cm.exception), \"Only one QPACK decoder stream is allowed\")\n + \n===========changed ref 2===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_data_before_headers(self):\n \"\"\"\n We should not receive DATA before receiving headers.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n + with self.assertRaises(UnexpectedFrame) as cm:\n - with self.assertRaises(QuicConnectionError) as cm:\n h3_server.handle_event(\n StreamDataReceived(\n stream_id=0,\n data=encode_frame(FrameType.DATA, b\"\"),\n end_stream=False,\n )\n )\n + self.assertEqual(str(cm.exception), \"DATA frame is not allowed in this state\")\n - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)\n \n===========changed ref 3===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n + def test_handle_control_stream_duplicate(self):\n + \"\"\"\n + We must only receive a single control stream.\n + \"\"\"\n + quic_server = FakeQuicConnection(\n + configuration=QuicConfiguration(is_client=False)\n + )\n + h3_server = H3Connection(quic_server)\n + \n + # receive a first control stream\n + h3_server.handle_event(\n + StreamDataReceived(\n + stream_id=2, data=encode_uint_var(StreamType.CONTROL), end_stream=False\n + )\n + )\n + with self.assertRaises(StreamCreationError) as cm:\n + # receive a second control stream\n + h3_server.handle_event(\n + StreamDataReceived(\n + stream_id=6,\n + data=encode_uint_var(StreamType.CONTROL),\n + end_stream=False,\n + )\n + )\n + self.assertEqual(str(cm.exception), \"Only one control stream is allowed\")\n + \n===========changed ref 4===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_push_frame_wrong_frame_type(self):\n + \"\"\"\n + We should not received SETTINGS on a push stream.\n + \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n + with self.assertRaises(WrongStream) as cm:\n - with self.assertRaises(QuicConnectionError) as cm:\n h3_client.handle_event(\n StreamDataReceived(\n stream_id=15,\n data=encode_uint_var(StreamType.PUSH)\n + encode_uint_var(0) # push ID\n + encode_frame(FrameType.SETTINGS, b\"\"),\n end_stream=False,\n )\n )\n - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n - self.assertEqual(\n + self.assertEqual(str(cm.exception), \"Invalid frame type on push stream\")\n - str(cm.exception), \"Error: 10, reason: Invalid frame type on push stream\"\n - )\n \n===========changed ref 5===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_headers(self):\n \"\"\"\n We should not receive HEADERS on the control stream.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n + with self.assertRaises(WrongStream) as cm:\n - with self.assertRaises(QuicConnectionError) as cm:\n + h3_server.handle_event(\n + StreamDataReceived(\n + stream_id=2,\n + data=encode_uint_var(StreamType.CONTROL)\n + + encode_frame(FrameType.HEADERS, b\"\"),\n + end_stream=False,\n + )\n + )\n + self.assertEqual(str(cm.exception), \"Invalid frame type on control stream\")\n - h3_server._handle_control_frame(FrameType.HEADERS, b\"\")\n - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n "}}},{"rowIdx":3477,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_request_frame_wrong_frame_type"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"286c400feb5e3fdee22b0434ae89351de094c88a"},"commit_message":{"kind":"string","value":"[http3] add some internal exception types"},"ground_truth":{"kind":"string","value":" <5>: with self.assertRaises(WrongStream) as cm:\n with self.assertRaises(QuicConnectionError) as cm:\n<13>: self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n<14>: self.assertEqual(\n<15>: self.assertEqual(str(cm.exception), \"Invalid frame type on request stream\")\n str(cm.exception), \"Error: 10, reason: Invalid frame type on request stream\"\n<16>: )\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_wrong_frame_type(self):\n <0> quic_server = FakeQuicConnection(\n <1> configuration=QuicConfiguration(is_client=False)\n <2> )\n <3> h3_server = H3Connection(quic_server)\n <4> \n <5> with self.assertRaises(QuicConnectionError) as cm:\n <6> h3_server.handle_event(\n <7> StreamDataReceived(\n <8> stream_id=0,\n <9> data=encode_frame(FrameType.SETTINGS, b\"\"),\n<10> end_stream=False,\n<11> )\n<12> )\n<13> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)\n<14> self.assertEqual(\n<15> str(cm.exception), \"Error: 10, reason: Invalid frame type on request stream\"\n<16> )\n<17> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n QpackDecoderStreamError(reason_phrase: str=\"\")\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: tests.test_h3.H3ConnectionTest.test_handle_qpack_decoder_stream_error\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========unchanged ref 1===========\n assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E]\n assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None\n \n at: unittest.case._AssertRaisesContext.__exit__\n self.exception = exc_value.with_traceback(None)\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n + class QpackDecoderStreamError(ProtocolError):\n + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR\n + \n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n + def test_handle_qpack_decoder_stream_error(self):\n + \"\"\"\n + Receiving garbage on the QPACK decoder stream triggers an exception.\n + \"\"\"\n + quic_client = FakeQuicConnection(\n + configuration=QuicConfiguration(is_client=True)\n + )\n + h3_client = H3Connection(quic_client)\n + \n + with self.assertRaises(QpackDecoderStreamError) as cm:\n + h3_client.handle_event(\n + StreamDataReceived(\n + stream_id=11,\n + data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n + end_stream=False,\n + )\n + )\n + self.assertEqual(str(cm.exception), \"\")\n + \n===========changed ref 2===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_push_promise_from_client(self):\n \"\"\"\n A server should not receive PUSH_PROMISE on a request stream.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n + with self.assertRaises(UnexpectedFrame) as cm:\n - with self.assertRaises(QuicConnectionError) as cm:\n h3_server.handle_event(\n StreamDataReceived(\n stream_id=0,\n data=encode_frame(FrameType.PUSH_PROMISE, b\"\"),\n end_stream=False,\n )\n )\n + self.assertEqual(str(cm.exception), \"Clients must not send PUSH_PROMISE\")\n - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)\n \n===========changed ref 3===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n + def test_handle_qpack_decoder_duplicate(self):\n + \"\"\"\n + We must only receive a single QPACK decoder stream.\n + \"\"\"\n + quic_client = FakeQuicConnection(\n + configuration=QuicConfiguration(is_client=True)\n + )\n + h3_client = H3Connection(quic_client)\n + \n + h3_client.handle_event(\n + StreamDataReceived(\n + stream_id=11,\n + data=encode_uint_var(StreamType.QPACK_DECODER),\n + end_stream=False,\n + )\n + )\n + with self.assertRaises(StreamCreationError) as cm:\n + h3_client.handle_event(\n + StreamDataReceived(\n + stream_id=15,\n + data=encode_uint_var(StreamType.QPACK_DECODER),\n + end_stream=False,\n + )\n + )\n + self.assertEqual(str(cm.exception), \"Only one QPACK decoder stream is allowed\")\n + \n===========changed ref 4===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_data_before_headers(self):\n \"\"\"\n We should not receive DATA before receiving headers.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n + with self.assertRaises(UnexpectedFrame) as cm:\n - with self.assertRaises(QuicConnectionError) as cm:\n h3_server.handle_event(\n StreamDataReceived(\n stream_id=0,\n data=encode_frame(FrameType.DATA, b\"\"),\n end_stream=False,\n )\n )\n + self.assertEqual(str(cm.exception), \"DATA frame is not allowed in this state\")\n - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)\n \n===========changed ref 5===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n + def test_handle_control_stream_duplicate(self):\n + \"\"\"\n + We must only receive a single control stream.\n + \"\"\"\n + quic_server = FakeQuicConnection(\n + configuration=QuicConfiguration(is_client=False)\n + )\n + h3_server = H3Connection(quic_server)\n + \n + # receive a first control stream\n + h3_server.handle_event(\n + StreamDataReceived(\n + stream_id=2, data=encode_uint_var(StreamType.CONTROL), end_stream=False\n + )\n + )\n + with self.assertRaises(StreamCreationError) as cm:\n + # receive a second control stream\n + h3_server.handle_event(\n + StreamDataReceived(\n + stream_id=6,\n + data=encode_uint_var(StreamType.CONTROL),\n + end_stream=False,\n + )\n + )\n + self.assertEqual(str(cm.exception), \"Only one control stream is allowed\")\n + "}}},{"rowIdx":3478,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection.__init__"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":" <4>: self._is_done = False\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def __init__(self, quic: QuicConnection):\n <0> self._max_table_capacity = 0x100\n <1> self._blocked_streams = 0x10\n <2> \n <3> self._is_client = quic.configuration.is_client\n <4> self._quic = quic\n <5> self._decoder = pylsqpack.Decoder(\n <6> self._max_table_capacity, self._blocked_streams\n <7> )\n <8> self._encoder = pylsqpack.Encoder()\n <9> self._stream: Dict[int, H3Stream] = {}\n<10> \n<11> self._max_push_id: Optional[int] = 8 if self._is_client else None\n<12> self._next_push_id: int = 0\n<13> \n<14> self._local_control_stream_id: Optional[int] = None\n<15> self._local_decoder_stream_id: Optional[int] = None\n<16> self._local_encoder_stream_id: Optional[int] = None\n<17> \n<18> self._peer_control_stream_id: Optional[int] = None\n<19> self._peer_decoder_stream_id: Optional[int] = None\n<20> self._peer_encoder_stream_id: Optional[int] = None\n<21> \n<22> self._init_connection()\n<23> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h3.connection\n H3Stream()\n \n at: aioquic.h3.connection.H3Connection._handle_control_frame\n self._max_push_id = parse_max_push_id(frame_data)\n \n at: aioquic.h3.connection.H3Connection._init_connection\n self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL)\n \n self._local_encoder_stream_id = self._create_uni_stream(\n StreamType.QPACK_ENCODER\n )\n \n self._local_decoder_stream_id = self._create_uni_stream(\n StreamType.QPACK_DECODER\n )\n \n at: aioquic.h3.connection.H3Connection._receive_stream_data_uni\n self._peer_control_stream_id = stream_id\n \n self._peer_decoder_stream_id = stream_id\n \n self._peer_encoder_stream_id = stream_id\n \n at: aioquic.h3.connection.H3Connection.handle_event\n self._is_done = True\n \n at: aioquic.h3.connection.H3Connection.send_push_promise\n self._next_push_id += 1\n \n at: aioquic.quic.configuration.QuicConfiguration\n alpn_protocols: Optional[List[str]] = None\n \n certificate: Any = None\n \n connection_id_length: int = 8\n \n idle_timeout: float = 60.0\n \n is_client: bool = True\n \n private_key: Any = None\n \n quic_logger: Optional[QuicLogger] = None\n \n secrets_log_file: TextIO = None\n \n server_name: Optional[str] = None\n \n session_ticket: Optional[SessionTicket] = None\n \n supported_versions: List[int] = field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n )\n \n \n===========unchanged ref 1===========\n at: aioquic.quic.connection\n QuicConnection(*, configuration: QuicConfiguration, logger_connection_id: Optional[bytes]=None, original_connection_id: Optional[bytes]=None, session_ticket_fetcher: Optional[tls.SessionTicketFetcher]=None, session_ticket_handler: Optional[tls.SessionTicketHandler]=None)\n \n at: typing\n Dict = _alias(dict, 2, inst=False, name='Dict')\n \n "}}},{"rowIdx":3479,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection.handle_event"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":" <5>: if isinstance(event, StreamDataReceived) and not self._is_done:\n if isinstance(event, StreamDataReceived):\n <9>: try:\n if stream_id % 4 == 0:\n if stream_id % 4 == 0:\n<10>: return self._receive_request_or_push_data(\n return self._receive_request_or_push_data(\n<11>: stream_id, event.data, event.end_stream\n stream_id, event.data, event.end_stream\n<12>: )\n )\n<13>: elif stream_is_unidirectional(stream_id):\n elif stream_is_unidirectional(stream_id):\n<14>: return self._receive_stream_data_uni(\n return self._receive_stream_data_uni(\n<15>: stream_id, event.data, event.end_stream\n stream_id, event.data, event.end_stream\n<16>: )\n except ProtocolError as exc:\n self._is_done = True\n self._quic.close(\n error_code=exc.error_code, reason_phrase=exc.reason_phrase\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n <0> \"\"\"\n <1> Handle a QUIC event and return a list of HTTP events.\n <2> \n <3> :param event: The QUIC event to handle.\n <4> \"\"\"\n <5> if isinstance(event, StreamDataReceived):\n <6> stream_id = event.stream_id\n <7> if stream_id not in self._stream:\n <8> self._stream[stream_id] = H3Stream()\n <9> if stream_id % 4 == 0:\n<10> return self._receive_request_or_push_data(\n<11> stream_id, event.data, event.end_stream\n<12> )\n<13> elif stream_is_unidirectional(stream_id):\n<14> return self._receive_stream_data_uni(\n<15> stream_id, event.data, event.end_stream\n<16> )\n<17> return []\n<18> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h3.connection\n H3Stream()\n \n at: aioquic.h3.connection.H3Connection\n _receive_request_or_push_data(stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event]\n \n _receive_stream_data_uni(stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event]\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._is_done = False\n \n self._stream: Dict[int, H3Stream] = {}\n \n at: aioquic.h3.connection.H3Connection.handle_event\n self._is_done = True\n \n at: aioquic.h3.events\n H3Event()\n \n at: aioquic.quic.connection\n stream_is_unidirectional(stream_id: int) -> bool\n \n at: aioquic.quic.events\n QuicEvent()\n \n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def __init__(self, quic: QuicConnection):\n self._max_table_capacity = 0x100\n self._blocked_streams = 0x10\n \n self._is_client = quic.configuration.is_client\n + self._is_done = False\n self._quic = quic\n self._decoder = pylsqpack.Decoder(\n self._max_table_capacity, self._blocked_streams\n )\n self._encoder = pylsqpack.Encoder()\n self._stream: Dict[int, H3Stream] = {}\n \n self._max_push_id: Optional[int] = 8 if self._is_client else None\n self._next_push_id: int = 0\n \n self._local_control_stream_id: Optional[int] = None\n self._local_decoder_stream_id: Optional[int] = None\n self._local_encoder_stream_id: Optional[int] = None\n \n self._peer_control_stream_id: Optional[int] = None\n self._peer_decoder_stream_id: Optional[int] = None\n self._peer_encoder_stream_id: Optional[int] = None\n \n self._init_connection()\n "}}},{"rowIdx":3480,"cells":{"path":{"kind":"string","value":"tests.test_h3/FakeQuicConnection.__init__"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":" <0>: self.closed = None\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class FakeQuicConnection:\n def __init__(self, configuration):\n <0> self.configuration = configuration\n <1> self.stream_queue = []\n <2> self._events = []\n <3> self._next_stream_bidi = 0 if configuration.is_client else 1\n <4> self._next_stream_uni = 2 if configuration.is_client else 3\n <5> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.quic.configuration.QuicConfiguration\n alpn_protocols: Optional[List[str]] = None\n \n certificate: Any = None\n \n connection_id_length: int = 8\n \n idle_timeout: float = 60.0\n \n is_client: bool = True\n \n private_key: Any = None\n \n quic_logger: Optional[QuicLogger] = None\n \n secrets_log_file: TextIO = None\n \n server_name: Optional[str] = None\n \n session_ticket: Optional[SessionTicket] = None\n \n supported_versions: List[int] = field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n )\n \n at: tests.test_h3.FakeQuicConnection.__init__\n self.closed = None\n \n at: tests.test_h3.FakeQuicConnection.get_next_available_stream_id\n self._next_stream_uni += 4\n \n self._next_stream_bidi += 4\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def __init__(self, quic: QuicConnection):\n self._max_table_capacity = 0x100\n self._blocked_streams = 0x10\n \n self._is_client = quic.configuration.is_client\n + self._is_done = False\n self._quic = quic\n self._decoder = pylsqpack.Decoder(\n self._max_table_capacity, self._blocked_streams\n )\n self._encoder = pylsqpack.Encoder()\n self._stream: Dict[int, H3Stream] = {}\n \n self._max_push_id: Optional[int] = 8 if self._is_client else None\n self._next_push_id: int = 0\n \n self._local_control_stream_id: Optional[int] = None\n self._local_decoder_stream_id: Optional[int] = None\n self._local_encoder_stream_id: Optional[int] = None\n \n self._peer_control_stream_id: Optional[int] = None\n self._peer_decoder_stream_id: Optional[int] = None\n self._peer_encoder_stream_id: Optional[int] = None\n \n self._init_connection()\n \n===========changed ref 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n + if isinstance(event, StreamDataReceived) and not self._is_done:\n - if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n + try:\n + if stream_id % 4 == 0:\n - if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_request_or_push_data(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n - )\n + elif stream_is_unidirectional(stream_id):\n - elif stream_is_unidirectional(stream_id):\n + return self._receive_stream_data_uni(\n - return self._receive_stream_data_uni(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n + except ProtocolError as exc:\n + self._is_done = True\n + self._quic.close(\n + error_code=exc.error_code, reason_phrase=exc.reason_phrase\n )\n return []\n "}}},{"rowIdx":3481,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_control_frame_headers"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":" <8>: with self.assertRaises(WrongStream) as cm:\n <9>: h3_server.handle_event(\n h3_server.handle_event(\n<10>: StreamDataReceived(\n StreamDataReceived(\n<11>: stream_id=2,\n stream_id=2,\n<12>: data=encode_uint_var(StreamType.CONTROL)\n data=encode_uint_var(StreamType.CONTROL)\n<13>: + encode_frame(FrameType.HEADERS, b\"\"),\n + encode_frame(FrameType.HEADERS, b\"\"),\n<14>: end_stream=False,\n end_stream=False,\n<15>: )\n<17>: )\n self.assertEqual(\n quic_server.closed,\n (ErrorCode.HTTP_WRONG_STREAM, \"Invalid frame type on control stream\"),\n )\n self.assertEqual(str(cm.exception), \"Invalid frame type on control stream\")\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_headers(self):\n <0> \"\"\"\n <1> We should not receive HEADERS on the control stream.\n <2> \"\"\"\n <3> quic_server = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=False)\n <5> )\n <6> h3_server = H3Connection(quic_server)\n <7> \n <8> with self.assertRaises(WrongStream) as cm:\n <9> h3_server.handle_event(\n<10> StreamDataReceived(\n<11> stream_id=2,\n<12> data=encode_uint_var(StreamType.CONTROL)\n<13> + encode_frame(FrameType.HEADERS, b\"\"),\n<14> end_stream=False,\n<15> )\n<16> )\n<17> self.assertEqual(str(cm.exception), \"Invalid frame type on control stream\")\n<18> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: aioquic.quic.events.StreamDataReceived\n data: bytes\n \n end_stream: bool\n \n stream_id: int\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: tests.test_h3.FakeQuicConnection.__init__\n self.closed = None\n \n \n===========unchanged ref 1===========\n at: tests.test_h3.FakeQuicConnection.close\n self.closed = (error_code, reason_phrase)\n \n at: unittest.case.TestCase\n failureException: Type[BaseException]\n \n longMessage: bool\n \n maxDiff: Optional[int]\n \n _testMethodName: str\n \n _testMethodDoc: str\n \n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n + if isinstance(event, StreamDataReceived) and not self._is_done:\n - if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n + try:\n + if stream_id % 4 == 0:\n - if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_request_or_push_data(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n - )\n + elif stream_is_unidirectional(stream_id):\n - elif stream_is_unidirectional(stream_id):\n + return self._receive_stream_data_uni(\n - return self._receive_stream_data_uni(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n + except ProtocolError as exc:\n + self._is_done = True\n + self._quic.close(\n + error_code=exc.error_code, reason_phrase=exc.reason_phrase\n )\n return []\n \n===========changed ref 1===========\n # module: tests.test_h3\n class FakeQuicConnection:\n + def close(self, error_code, reason_phrase):\n + self.closed = (error_code, reason_phrase)\n + \n===========changed ref 2===========\n # module: tests.test_h3\n class FakeQuicConnection:\n def __init__(self, configuration):\n + self.closed = None\n self.configuration = configuration\n self.stream_queue = []\n self._events = []\n self._next_stream_bidi = 0 if configuration.is_client else 1\n self._next_stream_uni = 2 if configuration.is_client else 3\n \n===========changed ref 3===========\n # module: aioquic.h3.connection\n class H3Connection:\n def __init__(self, quic: QuicConnection):\n self._max_table_capacity = 0x100\n self._blocked_streams = 0x10\n \n self._is_client = quic.configuration.is_client\n + self._is_done = False\n self._quic = quic\n self._decoder = pylsqpack.Decoder(\n self._max_table_capacity, self._blocked_streams\n )\n self._encoder = pylsqpack.Encoder()\n self._stream: Dict[int, H3Stream] = {}\n \n self._max_push_id: Optional[int] = 8 if self._is_client else None\n self._next_push_id: int = 0\n \n self._local_control_stream_id: Optional[int] = None\n self._local_decoder_stream_id: Optional[int] = None\n self._local_encoder_stream_id: Optional[int] = None\n \n self._peer_control_stream_id: Optional[int] = None\n self._peer_decoder_stream_id: Optional[int] = None\n self._peer_encoder_stream_id: Optional[int] = None\n \n self._init_connection()\n "}}},{"rowIdx":3482,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_control_frame_max_push_id_from_server"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":" <8>: with self.assertRaises(UnexpectedFrame) as cm:\n <9>: h3_client.handle_event(\n h3_client.handle_event(\n<10>: StreamDataReceived(\n StreamDataReceived(\n<11>: stream_id=3,\n stream_id=3,\n<12>: data=encode_uint_var(StreamType.CONTROL)\n data=encode_uint_var(StreamType.CONTROL)\n<13>: + encode_frame(FrameType.MAX_PUSH_ID, b\"\"),\n + encode_frame(FrameType.MAX_PUSH_ID, b\"\"),\n<14>: end_stream=False,\n end_stream=False,\n<15>: )\n<17>: )\n self.assertEqual(\n quic_client.closed,\n (ErrorCode.HTTP_UNEXPECTED_FRAME, \"Servers must not send MAX_PUSH_ID\"),\n )\n self.assertEqual(str(cm.exception), \"Servers must not send MAX_PUSH_ID\")\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_max_push_id_from_server(self):\n <0> \"\"\"\n <1> A client should not receive MAX_PUSH_ID on the control stream.\n <2> \"\"\"\n <3> quic_client = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=True)\n <5> )\n <6> h3_client = H3Connection(quic_client)\n <7> \n <8> with self.assertRaises(UnexpectedFrame) as cm:\n <9> h3_client.handle_event(\n<10> StreamDataReceived(\n<11> stream_id=3,\n<12> data=encode_uint_var(StreamType.CONTROL)\n<13> + encode_frame(FrameType.MAX_PUSH_ID, b\"\"),\n<14> end_stream=False,\n<15> )\n<16> )\n<17> self.assertEqual(str(cm.exception), \"Servers must not send MAX_PUSH_ID\")\n<18> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: tests.test_h3.H3ConnectionTest\n maxDiff = None\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n + if isinstance(event, StreamDataReceived) and not self._is_done:\n - if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n + try:\n + if stream_id % 4 == 0:\n - if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_request_or_push_data(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n - )\n + elif stream_is_unidirectional(stream_id):\n - elif stream_is_unidirectional(stream_id):\n + return self._receive_stream_data_uni(\n - return self._receive_stream_data_uni(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n + except ProtocolError as exc:\n + self._is_done = True\n + self._quic.close(\n + error_code=exc.error_code, reason_phrase=exc.reason_phrase\n )\n return []\n \n===========changed ref 1===========\n # module: tests.test_h3\n class FakeQuicConnection:\n + def close(self, error_code, reason_phrase):\n + self.closed = (error_code, reason_phrase)\n + \n===========changed ref 2===========\n # module: tests.test_h3\n class FakeQuicConnection:\n def __init__(self, configuration):\n + self.closed = None\n self.configuration = configuration\n self.stream_queue = []\n self._events = []\n self._next_stream_bidi = 0 if configuration.is_client else 1\n self._next_stream_uni = 2 if configuration.is_client else 3\n \n===========changed ref 3===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_headers(self):\n \"\"\"\n We should not receive HEADERS on the control stream.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n - with self.assertRaises(WrongStream) as cm:\n + h3_server.handle_event(\n - h3_server.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=2,\n - stream_id=2,\n + data=encode_uint_var(StreamType.CONTROL)\n - data=encode_uint_var(StreamType.CONTROL)\n + + encode_frame(FrameType.HEADERS, b\"\"),\n - + encode_frame(FrameType.HEADERS, b\"\"),\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_server.closed,\n + (ErrorCode.HTTP_WRONG_STREAM, \"Invalid frame type on control stream\"),\n + )\n - self.assertEqual(str(cm.exception), \"Invalid frame type on control stream\")\n \n===========changed ref 4===========\n # module: aioquic.h3.connection\n class H3Connection:\n def __init__(self, quic: QuicConnection):\n self._max_table_capacity = 0x100\n self._blocked_streams = 0x10\n \n self._is_client = quic.configuration.is_client\n + self._is_done = False\n self._quic = quic\n self._decoder = pylsqpack.Decoder(\n self._max_table_capacity, self._blocked_streams\n )\n self._encoder = pylsqpack.Encoder()\n self._stream: Dict[int, H3Stream] = {}\n \n self._max_push_id: Optional[int] = 8 if self._is_client else None\n self._next_push_id: int = 0\n \n self._local_control_stream_id: Optional[int] = None\n self._local_decoder_stream_id: Optional[int] = None\n self._local_encoder_stream_id: Optional[int] = None\n \n self._peer_control_stream_id: Optional[int] = None\n self._peer_decoder_stream_id: Optional[int] = None\n self._peer_encoder_stream_id: Optional[int] = None\n \n self._init_connection()\n "}}},{"rowIdx":3483,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_control_stream_duplicate"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":"<14>: \n with self.assertRaises(StreamCreationError) as cm:\n<15>: # receive a second control stream\n # receive a second control stream\n<16>: h3_server.handle_event(\n h3_server.handle_event(\n<17>: StreamDataReceived(\n StreamDataReceived(\n<18>: stream_id=6,\n<19>: stream_id=6, data=encode_uint_var(StreamType.CONTROL), end_stream=False\n data=encode_uint_var(StreamType.CONTROL),\n<20>: end_stream=False,\n<21>: )\n<23>: )\n self.assertEqual(\n quic_server.closed,\n (\n ErrorCode.HTTP_STREAM_CREATION_ERROR,\n \"Only one control stream is allowed\",\n ),\n )\n self.assertEqual(str(cm.exception), \"Only one control stream is allowed\")\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_stream_duplicate(self):\n <0> \"\"\"\n <1> We must only receive a single control stream.\n <2> \"\"\"\n <3> quic_server = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=False)\n <5> )\n <6> h3_server = H3Connection(quic_server)\n <7> \n <8> # receive a first control stream\n <9> h3_server.handle_event(\n<10> StreamDataReceived(\n<11> stream_id=2, data=encode_uint_var(StreamType.CONTROL), end_stream=False\n<12> )\n<13> )\n<14> with self.assertRaises(StreamCreationError) as cm:\n<15> # receive a second control stream\n<16> h3_server.handle_event(\n<17> StreamDataReceived(\n<18> stream_id=6,\n<19> data=encode_uint_var(StreamType.CONTROL),\n<20> end_stream=False,\n<21> )\n<22> )\n<23> self.assertEqual(str(cm.exception), \"Only one control stream is allowed\")\n<24> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n + if isinstance(event, StreamDataReceived) and not self._is_done:\n - if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n + try:\n + if stream_id % 4 == 0:\n - if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_request_or_push_data(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n - )\n + elif stream_is_unidirectional(stream_id):\n - elif stream_is_unidirectional(stream_id):\n + return self._receive_stream_data_uni(\n - return self._receive_stream_data_uni(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n + except ProtocolError as exc:\n + self._is_done = True\n + self._quic.close(\n + error_code=exc.error_code, reason_phrase=exc.reason_phrase\n )\n return []\n \n===========changed ref 1===========\n # module: tests.test_h3\n class FakeQuicConnection:\n + def close(self, error_code, reason_phrase):\n + self.closed = (error_code, reason_phrase)\n + \n===========changed ref 2===========\n # module: tests.test_h3\n class FakeQuicConnection:\n def __init__(self, configuration):\n + self.closed = None\n self.configuration = configuration\n self.stream_queue = []\n self._events = []\n self._next_stream_bidi = 0 if configuration.is_client else 1\n self._next_stream_uni = 2 if configuration.is_client else 3\n \n===========changed ref 3===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_max_push_id_from_server(self):\n \"\"\"\n A client should not receive MAX_PUSH_ID on the control stream.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(UnexpectedFrame) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=3,\n - stream_id=3,\n + data=encode_uint_var(StreamType.CONTROL)\n - data=encode_uint_var(StreamType.CONTROL)\n + + encode_frame(FrameType.MAX_PUSH_ID, b\"\"),\n - + encode_frame(FrameType.MAX_PUSH_ID, b\"\"),\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed,\n + (ErrorCode.HTTP_UNEXPECTED_FRAME, \"Servers must not send MAX_PUSH_ID\"),\n + )\n - self.assertEqual(str(cm.exception), \"Servers must not send MAX_PUSH_ID\")\n \n===========changed ref 4===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_headers(self):\n \"\"\"\n We should not receive HEADERS on the control stream.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n - with self.assertRaises(WrongStream) as cm:\n + h3_server.handle_event(\n - h3_server.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=2,\n - stream_id=2,\n + data=encode_uint_var(StreamType.CONTROL)\n - data=encode_uint_var(StreamType.CONTROL)\n + + encode_frame(FrameType.HEADERS, b\"\"),\n - + encode_frame(FrameType.HEADERS, b\"\"),\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_server.closed,\n + (ErrorCode.HTTP_WRONG_STREAM, \"Invalid frame type on control stream\"),\n + )\n - self.assertEqual(str(cm.exception), \"Invalid frame type on control stream\")\n \n===========changed ref 5===========\n # module: aioquic.h3.connection\n class H3Connection:\n def __init__(self, quic: QuicConnection):\n self._max_table_capacity = 0x100\n self._blocked_streams = 0x10\n \n self._is_client = quic.configuration.is_client\n + self._is_done = False\n self._quic = quic\n self._decoder = pylsqpack.Decoder(\n self._max_table_capacity, self._blocked_streams\n )\n self._encoder = pylsqpack.Encoder()\n self._stream: Dict[int, H3Stream] = {}\n \n self._max_push_id: Optional[int] = 8 if self._is_client else None\n self._next_push_id: int = 0\n \n self._local_control_stream_id: Optional[int] = None\n self._local_decoder_stream_id: Optional[int] = None\n self._local_encoder_stream_id: Optional[int] = None\n \n self._peer_control_stream_id: Optional[int] = None\n self._peer_decoder_stream_id: Optional[int] = None\n self._peer_encoder_stream_id: Optional[int] = None\n \n self._init_connection()\n "}}},{"rowIdx":3484,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_push_frame_wrong_frame_type"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":" <8>: with self.assertRaises(WrongStream) as cm:\n <9>: h3_client.handle_event(\n h3_client.handle_event(\n<10>: StreamDataReceived(\n StreamDataReceived(\n<11>: stream_id=15,\n stream_id=15,\n<12>: data=encode_uint_var(StreamType.PUSH)\n data=encode_uint_var(StreamType.PUSH)\n<13>: + encode_uint_var(0) # push ID\n + encode_uint_var(0) # push ID\n<14>: + encode_frame(FrameType.SETTINGS, b\"\"),\n + encode_frame(FrameType.SETTINGS, b\"\"),\n<15>: end_stream=False,\n end_stream=False,\n<16>: )\n<18>: )\n self.assertEqual(\n quic_client.closed,\n (ErrorCode.HTTP_WRONG_STREAM, \"Invalid frame type on push stream\"),\n )\n self.assertEqual(str(cm.exception), \"Invalid frame type on push stream\")\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_push_frame_wrong_frame_type(self):\n <0> \"\"\"\n <1> We should not received SETTINGS on a push stream.\n <2> \"\"\"\n <3> quic_client = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=True)\n <5> )\n <6> h3_client = H3Connection(quic_client)\n <7> \n <8> with self.assertRaises(WrongStream) as cm:\n <9> h3_client.handle_event(\n<10> StreamDataReceived(\n<11> stream_id=15,\n<12> data=encode_uint_var(StreamType.PUSH)\n<13> + encode_uint_var(0) # push ID\n<14> + encode_frame(FrameType.SETTINGS, b\"\"),\n<15> end_stream=False,\n<16> )\n<17> )\n<18> self.assertEqual(str(cm.exception), \"Invalid frame type on push stream\")\n<19> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: tests.test_h3.FakeQuicConnection.__init__\n self.closed = None\n \n at: tests.test_h3.FakeQuicConnection.close\n self.closed = (error_code, reason_phrase)\n \n at: tests.test_h3.H3ConnectionTest.test_handle_control_stream_duplicate\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n + if isinstance(event, StreamDataReceived) and not self._is_done:\n - if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n + try:\n + if stream_id % 4 == 0:\n - if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_request_or_push_data(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n - )\n + elif stream_is_unidirectional(stream_id):\n - elif stream_is_unidirectional(stream_id):\n + return self._receive_stream_data_uni(\n - return self._receive_stream_data_uni(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n + except ProtocolError as exc:\n + self._is_done = True\n + self._quic.close(\n + error_code=exc.error_code, reason_phrase=exc.reason_phrase\n )\n return []\n \n===========changed ref 1===========\n # module: tests.test_h3\n class FakeQuicConnection:\n + def close(self, error_code, reason_phrase):\n + self.closed = (error_code, reason_phrase)\n + \n===========changed ref 2===========\n # module: tests.test_h3\n class FakeQuicConnection:\n def __init__(self, configuration):\n + self.closed = None\n self.configuration = configuration\n self.stream_queue = []\n self._events = []\n self._next_stream_bidi = 0 if configuration.is_client else 1\n self._next_stream_uni = 2 if configuration.is_client else 3\n \n===========changed ref 3===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_max_push_id_from_server(self):\n \"\"\"\n A client should not receive MAX_PUSH_ID on the control stream.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(UnexpectedFrame) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=3,\n - stream_id=3,\n + data=encode_uint_var(StreamType.CONTROL)\n - data=encode_uint_var(StreamType.CONTROL)\n + + encode_frame(FrameType.MAX_PUSH_ID, b\"\"),\n - + encode_frame(FrameType.MAX_PUSH_ID, b\"\"),\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed,\n + (ErrorCode.HTTP_UNEXPECTED_FRAME, \"Servers must not send MAX_PUSH_ID\"),\n + )\n - self.assertEqual(str(cm.exception), \"Servers must not send MAX_PUSH_ID\")\n \n===========changed ref 4===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_headers(self):\n \"\"\"\n We should not receive HEADERS on the control stream.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n - with self.assertRaises(WrongStream) as cm:\n + h3_server.handle_event(\n - h3_server.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=2,\n - stream_id=2,\n + data=encode_uint_var(StreamType.CONTROL)\n - data=encode_uint_var(StreamType.CONTROL)\n + + encode_frame(FrameType.HEADERS, b\"\"),\n - + encode_frame(FrameType.HEADERS, b\"\"),\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_server.closed,\n + (ErrorCode.HTTP_WRONG_STREAM, \"Invalid frame type on control stream\"),\n + )\n - self.assertEqual(str(cm.exception), \"Invalid frame type on control stream\")\n "}}},{"rowIdx":3485,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_qpack_decoder_duplicate"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":" <8>: # receive a first decoder stream\n<15>: \n # receive a second decoder stream\n with self.assertRaises(StreamCreationError) as cm:\n<16>: h3_client.handle_event(\n h3_client.handle_event(\n<17>: StreamDataReceived(\n StreamDataReceived(\n<18>: stream_id=15,\n stream_id=15,\n<19>: data=encode_uint_var(StreamType.QPACK_DECODER),\n data=encode_uint_var(StreamType.QPACK_DECODER),\n<20>: end_stream=False,\n end_stream=False,\n<21>: )\n<23>: )\n self.assertEqual(\n quic_client.closed,\n (\n ErrorCode.HTTP_STREAM_CREATION_ERROR,\n \"Only one QPACK decoder stream is allowed\",\n ),\n )\n self.assertEqual(str(cm.exception), \"Only one QPACK decoder stream is allowed\")\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_decoder_duplicate(self):\n <0> \"\"\"\n <1> We must only receive a single QPACK decoder stream.\n <2> \"\"\"\n <3> quic_client = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=True)\n <5> )\n <6> h3_client = H3Connection(quic_client)\n <7> \n <8> h3_client.handle_event(\n <9> StreamDataReceived(\n<10> stream_id=11,\n<11> data=encode_uint_var(StreamType.QPACK_DECODER),\n<12> end_stream=False,\n<13> )\n<14> )\n<15> with self.assertRaises(StreamCreationError) as cm:\n<16> h3_client.handle_event(\n<17> StreamDataReceived(\n<18> stream_id=15,\n<19> data=encode_uint_var(StreamType.QPACK_DECODER),\n<20> end_stream=False,\n<21> )\n<22> )\n<23> self.assertEqual(str(cm.exception), \"Only one QPACK decoder stream is allowed\")\n<24> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: tests.test_h3.FakeQuicConnection.__init__\n self.closed = None\n \n at: tests.test_h3.FakeQuicConnection.close\n self.closed = (error_code, reason_phrase)\n \n \n===========unchanged ref 1===========\n at: tests.test_h3.H3ConnectionTest.test_handle_push_frame_wrong_frame_type\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n + if isinstance(event, StreamDataReceived) and not self._is_done:\n - if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n + try:\n + if stream_id % 4 == 0:\n - if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_request_or_push_data(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n - )\n + elif stream_is_unidirectional(stream_id):\n - elif stream_is_unidirectional(stream_id):\n + return self._receive_stream_data_uni(\n - return self._receive_stream_data_uni(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n + except ProtocolError as exc:\n + self._is_done = True\n + self._quic.close(\n + error_code=exc.error_code, reason_phrase=exc.reason_phrase\n )\n return []\n \n===========changed ref 1===========\n # module: tests.test_h3\n class FakeQuicConnection:\n + def close(self, error_code, reason_phrase):\n + self.closed = (error_code, reason_phrase)\n + \n===========changed ref 2===========\n # module: tests.test_h3\n class FakeQuicConnection:\n def __init__(self, configuration):\n + self.closed = None\n self.configuration = configuration\n self.stream_queue = []\n self._events = []\n self._next_stream_bidi = 0 if configuration.is_client else 1\n self._next_stream_uni = 2 if configuration.is_client else 3\n \n===========changed ref 3===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_push_frame_wrong_frame_type(self):\n \"\"\"\n We should not received SETTINGS on a push stream.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(WrongStream) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=15,\n - stream_id=15,\n + data=encode_uint_var(StreamType.PUSH)\n - data=encode_uint_var(StreamType.PUSH)\n + + encode_uint_var(0) # push ID\n - + encode_uint_var(0) # push ID\n + + encode_frame(FrameType.SETTINGS, b\"\"),\n - + encode_frame(FrameType.SETTINGS, b\"\"),\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed,\n + (ErrorCode.HTTP_WRONG_STREAM, \"Invalid frame type on push stream\"),\n + )\n - self.assertEqual(str(cm.exception), \"Invalid frame type on push stream\")\n \n===========changed ref 4===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_control_frame_max_push_id_from_server(self):\n \"\"\"\n A client should not receive MAX_PUSH_ID on the control stream.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(UnexpectedFrame) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=3,\n - stream_id=3,\n + data=encode_uint_var(StreamType.CONTROL)\n - data=encode_uint_var(StreamType.CONTROL)\n + + encode_frame(FrameType.MAX_PUSH_ID, b\"\"),\n - + encode_frame(FrameType.MAX_PUSH_ID, b\"\"),\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed,\n + (ErrorCode.HTTP_UNEXPECTED_FRAME, \"Servers must not send MAX_PUSH_ID\"),\n + )\n - self.assertEqual(str(cm.exception), \"Servers must not send MAX_PUSH_ID\")\n "}}},{"rowIdx":3486,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_qpack_decoder_stream_error"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":" <8>: with self.assertRaises(QpackDecoderStreamError) as cm:\n <9>: h3_client.handle_event(\n h3_client.handle_event(\n<10>: StreamDataReceived(\n StreamDataReceived(\n<11>: stream_id=11,\n stream_id=11,\n<12>: data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n<13>: end_stream=False,\n end_stream=False,\n<14>: )\n<16>: )\n self.assertEqual(\n quic_client.closed, (ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR, \"\")\n )\n self.assertEqual(str(cm.exception), \"\")\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_decoder_stream_error(self):\n <0> \"\"\"\n <1> Receiving garbage on the QPACK decoder stream triggers an exception.\n <2> \"\"\"\n <3> quic_client = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=True)\n <5> )\n <6> h3_client = H3Connection(quic_client)\n <7> \n <8> with self.assertRaises(QpackDecoderStreamError) as cm:\n <9> h3_client.handle_event(\n<10> StreamDataReceived(\n<11> stream_id=11,\n<12> data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n<13> end_stream=False,\n<14> )\n<15> )\n<16> self.assertEqual(str(cm.exception), \"\")\n<17> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_h3.FakeQuicConnection.__init__\n self.closed = None\n \n at: tests.test_h3.FakeQuicConnection.close\n self.closed = (error_code, reason_phrase)\n \n at: tests.test_h3.H3ConnectionTest.test_handle_qpack_decoder_duplicate\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n \n h3_client = H3Connection(quic_client)\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n + if isinstance(event, StreamDataReceived) and not self._is_done:\n - if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n + try:\n + if stream_id % 4 == 0:\n - if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_request_or_push_data(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n - )\n + elif stream_is_unidirectional(stream_id):\n - elif stream_is_unidirectional(stream_id):\n + return self._receive_stream_data_uni(\n - return self._receive_stream_data_uni(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n + except ProtocolError as exc:\n + self._is_done = True\n + self._quic.close(\n + error_code=exc.error_code, reason_phrase=exc.reason_phrase\n )\n return []\n \n===========changed ref 1===========\n # module: tests.test_h3\n class FakeQuicConnection:\n + def close(self, error_code, reason_phrase):\n + self.closed = (error_code, reason_phrase)\n + \n===========changed ref 2===========\n # module: tests.test_h3\n class FakeQuicConnection:\n def __init__(self, configuration):\n + self.closed = None\n self.configuration = configuration\n self.stream_queue = []\n self._events = []\n self._next_stream_bidi = 0 if configuration.is_client else 1\n self._next_stream_uni = 2 if configuration.is_client else 3\n \n===========changed ref 3===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_push_frame_wrong_frame_type(self):\n \"\"\"\n We should not received SETTINGS on a push stream.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(WrongStream) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=15,\n - stream_id=15,\n + data=encode_uint_var(StreamType.PUSH)\n - data=encode_uint_var(StreamType.PUSH)\n + + encode_uint_var(0) # push ID\n - + encode_uint_var(0) # push ID\n + + encode_frame(FrameType.SETTINGS, b\"\"),\n - + encode_frame(FrameType.SETTINGS, b\"\"),\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed,\n + (ErrorCode.HTTP_WRONG_STREAM, \"Invalid frame type on push stream\"),\n + )\n - self.assertEqual(str(cm.exception), \"Invalid frame type on push stream\")\n \n===========changed ref 4===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_decoder_duplicate(self):\n \"\"\"\n We must only receive a single QPACK decoder stream.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n + # receive a first decoder stream\n h3_client.handle_event(\n StreamDataReceived(\n stream_id=11,\n data=encode_uint_var(StreamType.QPACK_DECODER),\n end_stream=False,\n )\n )\n + \n + # receive a second decoder stream\n - with self.assertRaises(StreamCreationError) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=15,\n - stream_id=15,\n + data=encode_uint_var(StreamType.QPACK_DECODER),\n - data=encode_uint_var(StreamType.QPACK_DECODER),\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed,\n + (\n + ErrorCode.HTTP_STREAM_CREATION_ERROR,\n + \"Only one QPACK decoder stream is allowed\",\n + ),\n + )\n - self.assertEqual(str(cm.exception), \"Only one QPACK decoder stream is allowed\")\n "}}},{"rowIdx":3487,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_qpack_encoder_duplicate"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":" <8>: # receive a first encoder stream\n<15>: \n # receive a second encoder stream\n with self.assertRaises(StreamCreationError) as cm:\n<16>: h3_client.handle_event(\n h3_client.handle_event(\n<17>: StreamDataReceived(\n StreamDataReceived(\n<18>: stream_id=15,\n stream_id=15,\n<19>: data=encode_uint_var(StreamType.QPACK_ENCODER),\n data=encode_uint_var(StreamType.QPACK_ENCODER),\n<20>: end_stream=False,\n end_stream=False,\n<21>: )\n<23>: )\n self.assertEqual(\n quic_client.closed,\n (\n ErrorCode.HTTP_STREAM_CREATION_ERROR,\n \"Only one QPACK encoder stream is allowed\",\n ),\n )\n self.assertEqual(str(cm.exception), \"Only one QPACK encoder stream is allowed\")\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_encoder_duplicate(self):\n <0> \"\"\"\n <1> We must only receive a single QPACK encoder stream.\n <2> \"\"\"\n <3> quic_client = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=True)\n <5> )\n <6> h3_client = H3Connection(quic_client)\n <7> \n <8> h3_client.handle_event(\n <9> StreamDataReceived(\n<10> stream_id=11,\n<11> data=encode_uint_var(StreamType.QPACK_ENCODER),\n<12> end_stream=False,\n<13> )\n<14> )\n<15> with self.assertRaises(StreamCreationError) as cm:\n<16> h3_client.handle_event(\n<17> StreamDataReceived(\n<18> stream_id=15,\n<19> data=encode_uint_var(StreamType.QPACK_ENCODER),\n<20> end_stream=False,\n<21> )\n<22> )\n<23> self.assertEqual(str(cm.exception), \"Only one QPACK encoder stream is allowed\")\n<24> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: tests.test_h3.FakeQuicConnection.__init__\n self.closed = None\n \n at: tests.test_h3.FakeQuicConnection.close\n self.closed = (error_code, reason_phrase)\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n + if isinstance(event, StreamDataReceived) and not self._is_done:\n - if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n + try:\n + if stream_id % 4 == 0:\n - if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_request_or_push_data(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n - )\n + elif stream_is_unidirectional(stream_id):\n - elif stream_is_unidirectional(stream_id):\n + return self._receive_stream_data_uni(\n - return self._receive_stream_data_uni(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n + except ProtocolError as exc:\n + self._is_done = True\n + self._quic.close(\n + error_code=exc.error_code, reason_phrase=exc.reason_phrase\n )\n return []\n \n===========changed ref 1===========\n # module: tests.test_h3\n class FakeQuicConnection:\n + def close(self, error_code, reason_phrase):\n + self.closed = (error_code, reason_phrase)\n + \n===========changed ref 2===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_decoder_stream_error(self):\n \"\"\"\n Receiving garbage on the QPACK decoder stream triggers an exception.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(QpackDecoderStreamError) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=11,\n - stream_id=11,\n + data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n - data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed, (ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR, \"\")\n + )\n - self.assertEqual(str(cm.exception), \"\")\n \n===========changed ref 3===========\n # module: tests.test_h3\n class FakeQuicConnection:\n def __init__(self, configuration):\n + self.closed = None\n self.configuration = configuration\n self.stream_queue = []\n self._events = []\n self._next_stream_bidi = 0 if configuration.is_client else 1\n self._next_stream_uni = 2 if configuration.is_client else 3\n \n===========changed ref 4===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_push_frame_wrong_frame_type(self):\n \"\"\"\n We should not received SETTINGS on a push stream.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(WrongStream) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=15,\n - stream_id=15,\n + data=encode_uint_var(StreamType.PUSH)\n - data=encode_uint_var(StreamType.PUSH)\n + + encode_uint_var(0) # push ID\n - + encode_uint_var(0) # push ID\n + + encode_frame(FrameType.SETTINGS, b\"\"),\n - + encode_frame(FrameType.SETTINGS, b\"\"),\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed,\n + (ErrorCode.HTTP_WRONG_STREAM, \"Invalid frame type on push stream\"),\n + )\n - self.assertEqual(str(cm.exception), \"Invalid frame type on push stream\")\n "}}},{"rowIdx":3488,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_qpack_encoder_stream_error"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":" <8>: with self.assertRaises(QpackEncoderStreamError) as cm:\n <9>: h3_client.handle_event(\n h3_client.handle_event(\n<10>: StreamDataReceived(\n StreamDataReceived(\n<11>: stream_id=7,\n stream_id=7,\n<12>: data=encode_uint_var(StreamType.QPACK_ENCODER) + b\"\\x00\",\n data=encode_uint_var(StreamType.QPACK_ENCODER) + b\"\\x00\",\n<13>: end_stream=False,\n end_stream=False,\n<14>: )\n<16>: )\n self.assertEqual(\n quic_client.closed, (ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR, \"\")\n )\n self.assertEqual(str(cm.exception), \"\")\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_encoder_stream_error(self):\n <0> \"\"\"\n <1> Receiving garbage on the QPACK encoder stream triggers an exception.\n <2> \"\"\"\n <3> quic_client = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=True)\n <5> )\n <6> h3_client = H3Connection(quic_client)\n <7> \n <8> with self.assertRaises(QpackEncoderStreamError) as cm:\n <9> h3_client.handle_event(\n<10> StreamDataReceived(\n<11> stream_id=7,\n<12> data=encode_uint_var(StreamType.QPACK_ENCODER) + b\"\\x00\",\n<13> end_stream=False,\n<14> )\n<15> )\n<16> self.assertEqual(str(cm.exception), \"\")\n<17> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_h3.H3ConnectionTest.test_handle_qpack_encoder_duplicate\n h3_client = H3Connection(quic_client)\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n + if isinstance(event, StreamDataReceived) and not self._is_done:\n - if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n + try:\n + if stream_id % 4 == 0:\n - if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_request_or_push_data(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n - )\n + elif stream_is_unidirectional(stream_id):\n - elif stream_is_unidirectional(stream_id):\n + return self._receive_stream_data_uni(\n - return self._receive_stream_data_uni(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n + except ProtocolError as exc:\n + self._is_done = True\n + self._quic.close(\n + error_code=exc.error_code, reason_phrase=exc.reason_phrase\n )\n return []\n \n===========changed ref 1===========\n # module: tests.test_h3\n class FakeQuicConnection:\n + def close(self, error_code, reason_phrase):\n + self.closed = (error_code, reason_phrase)\n + \n===========changed ref 2===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_decoder_stream_error(self):\n \"\"\"\n Receiving garbage on the QPACK decoder stream triggers an exception.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(QpackDecoderStreamError) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=11,\n - stream_id=11,\n + data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n - data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed, (ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR, \"\")\n + )\n - self.assertEqual(str(cm.exception), \"\")\n \n===========changed ref 3===========\n # module: tests.test_h3\n class FakeQuicConnection:\n def __init__(self, configuration):\n + self.closed = None\n self.configuration = configuration\n self.stream_queue = []\n self._events = []\n self._next_stream_bidi = 0 if configuration.is_client else 1\n self._next_stream_uni = 2 if configuration.is_client else 3\n \n===========changed ref 4===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_encoder_duplicate(self):\n \"\"\"\n We must only receive a single QPACK encoder stream.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n + # receive a first encoder stream\n h3_client.handle_event(\n StreamDataReceived(\n stream_id=11,\n data=encode_uint_var(StreamType.QPACK_ENCODER),\n end_stream=False,\n )\n )\n + \n + # receive a second encoder stream\n - with self.assertRaises(StreamCreationError) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=15,\n - stream_id=15,\n + data=encode_uint_var(StreamType.QPACK_ENCODER),\n - data=encode_uint_var(StreamType.QPACK_ENCODER),\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed,\n + (\n + ErrorCode.HTTP_STREAM_CREATION_ERROR,\n + \"Only one QPACK encoder stream is allowed\",\n + ),\n + )\n - self.assertEqual(str(cm.exception), \"Only one QPACK encoder stream is allowed\")\n \n===========changed ref 5===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_push_frame_wrong_frame_type(self):\n \"\"\"\n We should not received SETTINGS on a push stream.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(WrongStream) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=15,\n - stream_id=15,\n + data=encode_uint_var(StreamType.PUSH)\n - data=encode_uint_var(StreamType.PUSH)\n + + encode_uint_var(0) # push ID\n - + encode_uint_var(0) # push ID\n + + encode_frame(FrameType.SETTINGS, b\"\"),\n - + encode_frame(FrameType.SETTINGS, b\"\"),\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed,\n + (ErrorCode.HTTP_WRONG_STREAM, \"Invalid frame type on push stream\"),\n + )\n - self.assertEqual(str(cm.exception), \"Invalid frame type on push stream\")\n "}}},{"rowIdx":3489,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_request_frame_bad_headers"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":" <8>: with self.assertRaises(QpackDecompressionFailed) as cm:\n <9>: h3_server.handle_event(\n h3_server.handle_event(\n<10>: StreamDataReceived(\n StreamDataReceived(\n<11>: stream_id=0,\n<12>: stream_id=0, data=encode_frame(FrameType.HEADERS, b\"\"), end_stream=False\n data=encode_frame(FrameType.HEADERS, b\"\"),\n<13>: end_stream=False,\n<14>: )\n<16>: )\n self.assertEqual(\n quic_server.closed, (ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED, \"\")\n )\n self.assertEqual(str(cm.exception), \"\")\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_bad_headers(self):\n <0> \"\"\"\n <1> We should not receive HEADERS which cannot be decoded.\n <2> \"\"\"\n <3> quic_server = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=False)\n <5> )\n <6> h3_server = H3Connection(quic_server)\n <7> \n <8> with self.assertRaises(QpackDecompressionFailed) as cm:\n <9> h3_server.handle_event(\n<10> StreamDataReceived(\n<11> stream_id=0,\n<12> data=encode_frame(FrameType.HEADERS, b\"\"),\n<13> end_stream=False,\n<14> )\n<15> )\n<16> self.assertEqual(str(cm.exception), \"\")\n<17> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: tests.test_h3.FakeQuicConnection.__init__\n self.closed = None\n \n at: tests.test_h3.FakeQuicConnection.close\n self.closed = (error_code, reason_phrase)\n \n at: tests.test_h3.H3ConnectionTest.test_handle_qpack_encoder_duplicate\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n + if isinstance(event, StreamDataReceived) and not self._is_done:\n - if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n + try:\n + if stream_id % 4 == 0:\n - if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_request_or_push_data(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n - )\n + elif stream_is_unidirectional(stream_id):\n - elif stream_is_unidirectional(stream_id):\n + return self._receive_stream_data_uni(\n - return self._receive_stream_data_uni(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n + except ProtocolError as exc:\n + self._is_done = True\n + self._quic.close(\n + error_code=exc.error_code, reason_phrase=exc.reason_phrase\n )\n return []\n \n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_encoder_stream_error(self):\n \"\"\"\n Receiving garbage on the QPACK encoder stream triggers an exception.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(QpackEncoderStreamError) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=7,\n - stream_id=7,\n + data=encode_uint_var(StreamType.QPACK_ENCODER) + b\"\\x00\",\n - data=encode_uint_var(StreamType.QPACK_ENCODER) + b\"\\x00\",\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed, (ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR, \"\")\n + )\n - self.assertEqual(str(cm.exception), \"\")\n \n===========changed ref 2===========\n # module: tests.test_h3\n class FakeQuicConnection:\n + def close(self, error_code, reason_phrase):\n + self.closed = (error_code, reason_phrase)\n + \n===========changed ref 3===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_decoder_stream_error(self):\n \"\"\"\n Receiving garbage on the QPACK decoder stream triggers an exception.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(QpackDecoderStreamError) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=11,\n - stream_id=11,\n + data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n - data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed, (ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR, \"\")\n + )\n - self.assertEqual(str(cm.exception), \"\")\n \n===========changed ref 4===========\n # module: tests.test_h3\n class FakeQuicConnection:\n def __init__(self, configuration):\n + self.closed = None\n self.configuration = configuration\n self.stream_queue = []\n self._events = []\n self._next_stream_bidi = 0 if configuration.is_client else 1\n self._next_stream_uni = 2 if configuration.is_client else 3\n "}}},{"rowIdx":3490,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_request_frame_data_before_headers"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":" <8>: with self.assertRaises(UnexpectedFrame) as cm:\n <9>: h3_server.handle_event(\n h3_server.handle_event(\n<10>: StreamDataReceived(\n StreamDataReceived(\n<11>: stream_id=0,\n<12>: stream_id=0, data=encode_frame(FrameType.DATA, b\"\"), end_stream=False\n data=encode_frame(FrameType.DATA, b\"\"),\n<13>: end_stream=False,\n<14>: )\n<16>: )\n self.assertEqual(\n quic_server.closed,\n (\n ErrorCode.HTTP_UNEXPECTED_FRAME,\n \"DATA frame is not allowed in this state\",\n ),\n )\n self.assertEqual(str(cm.exception), \"DATA frame is not allowed in this state\")\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_data_before_headers(self):\n <0> \"\"\"\n <1> We should not receive DATA before receiving headers.\n <2> \"\"\"\n <3> quic_server = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=False)\n <5> )\n <6> h3_server = H3Connection(quic_server)\n <7> \n <8> with self.assertRaises(UnexpectedFrame) as cm:\n <9> h3_server.handle_event(\n<10> StreamDataReceived(\n<11> stream_id=0,\n<12> data=encode_frame(FrameType.DATA, b\"\"),\n<13> end_stream=False,\n<14> )\n<15> )\n<16> self.assertEqual(str(cm.exception), \"DATA frame is not allowed in this state\")\n<17> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.buffer\n encode_uint_var(value: int) -> bytes\n \n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: tests.test_h3.FakeQuicConnection.__init__\n self.closed = None\n \n at: tests.test_h3.FakeQuicConnection.close\n self.closed = (error_code, reason_phrase)\n \n at: tests.test_h3.H3ConnectionTest.test_handle_qpack_encoder_stream_error\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n + if isinstance(event, StreamDataReceived) and not self._is_done:\n - if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n + try:\n + if stream_id % 4 == 0:\n - if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_request_or_push_data(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n - )\n + elif stream_is_unidirectional(stream_id):\n - elif stream_is_unidirectional(stream_id):\n + return self._receive_stream_data_uni(\n - return self._receive_stream_data_uni(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n + except ProtocolError as exc:\n + self._is_done = True\n + self._quic.close(\n + error_code=exc.error_code, reason_phrase=exc.reason_phrase\n )\n return []\n \n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_bad_headers(self):\n \"\"\"\n We should not receive HEADERS which cannot be decoded.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n - with self.assertRaises(QpackDecompressionFailed) as cm:\n + h3_server.handle_event(\n - h3_server.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n - stream_id=0,\n + stream_id=0, data=encode_frame(FrameType.HEADERS, b\"\"), end_stream=False\n - data=encode_frame(FrameType.HEADERS, b\"\"),\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_server.closed, (ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED, \"\")\n + )\n - self.assertEqual(str(cm.exception), \"\")\n \n===========changed ref 2===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_encoder_stream_error(self):\n \"\"\"\n Receiving garbage on the QPACK encoder stream triggers an exception.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(QpackEncoderStreamError) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=7,\n - stream_id=7,\n + data=encode_uint_var(StreamType.QPACK_ENCODER) + b\"\\x00\",\n - data=encode_uint_var(StreamType.QPACK_ENCODER) + b\"\\x00\",\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed, (ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR, \"\")\n + )\n - self.assertEqual(str(cm.exception), \"\")\n \n===========changed ref 3===========\n # module: tests.test_h3\n class FakeQuicConnection:\n + def close(self, error_code, reason_phrase):\n + self.closed = (error_code, reason_phrase)\n + \n===========changed ref 4===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_decoder_stream_error(self):\n \"\"\"\n Receiving garbage on the QPACK decoder stream triggers an exception.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(QpackDecoderStreamError) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=11,\n - stream_id=11,\n + data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n - data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed, (ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR, \"\")\n + )\n - self.assertEqual(str(cm.exception), \"\")\n \n===========changed ref 5===========\n # module: tests.test_h3\n class FakeQuicConnection:\n def __init__(self, configuration):\n + self.closed = None\n self.configuration = configuration\n self.stream_queue = []\n self._events = []\n self._next_stream_bidi = 0 if configuration.is_client else 1\n self._next_stream_uni = 2 if configuration.is_client else 3\n "}}},{"rowIdx":3491,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_request_frame_headers_after_trailers"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":"<28>: with self.assertRaises(UnexpectedFrame) as cm:\n<29>: h3_server.handle_event(\n h3_server.handle_event(\n<30>: StreamDataReceived(\n StreamDataReceived(\n<31>: stream_id=0,\n<32>: stream_id=0, data=encode_frame(FrameType.HEADERS, b\"\"), end_stream=False\n data=encode_frame(FrameType.HEADERS, b\"\"),\n<33>: end_stream=False,\n<34>: )\n<36>: )\n<37>: quic_server.closed,\n (\n ErrorCode.HTTP_UNEXPECTED_FRAME,\n \"HEADERS frame is not allowed in this state\",\n str(cm.exception), \"HEADERS frame is not allowed in this state\"\n<38>: ),\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_headers_after_trailers(self):\n <0> \"\"\"\n <1> We should not receive HEADERS after receiving trailers.\n <2> \"\"\"\n <3> quic_client = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=True)\n <5> )\n <6> quic_server = FakeQuicConnection(\n <7> configuration=QuicConfiguration(is_client=False)\n <8> )\n <9> \n<10> h3_client = H3Connection(quic_client)\n<11> h3_server = H3Connection(quic_server)\n<12> \n<13> stream_id = quic_client.get_next_available_stream_id()\n<14> h3_client.send_headers(\n<15> stream_id=stream_id,\n<16> headers=[\n<17> (b\":method\", b\"GET\"),\n<18> (b\":scheme\", b\"https\"),\n<19> (b\":authority\", b\"localhost\"),\n<20> (b\":path\", b\"/\"),\n<21> ],\n<22> )\n<23> h3_client.send_headers(\n<24> stream_id=stream_id, headers=[(b\"x-some-trailer\", b\"foo\")], end_stream=True\n<25> )\n<26> h3_transfer(quic_client, h3_server)\n<27> \n<28> with self.assertRaises(UnexpectedFrame) as cm:\n<29> h3_server.handle_event(\n<30> StreamDataReceived(\n<31> stream_id=0,\n<32> data=encode_frame(FrameType.HEADERS, b\"\"),\n<33> end_stream=False,\n<34> )\n<35> )\n<36> self.assertEqual(\n<37> str(cm.exception), \"HEADERS frame is not allowed in this state\"\n<38> )\n<39> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.events\n StreamDataReceived(data: bytes, end_stream: bool, stream_id: int)\n \n at: tests.test_h3\n FakeQuicConnection(configuration)\n \n at: tests.test_h3.FakeQuicConnection.__init__\n self.closed = None\n \n at: tests.test_h3.FakeQuicConnection.close\n self.closed = (error_code, reason_phrase)\n \n at: tests.test_h3.H3ConnectionTest.test_handle_request_frame_bad_headers\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n \n \n===========unchanged ref 1===========\n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n + if isinstance(event, StreamDataReceived) and not self._is_done:\n - if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n + try:\n + if stream_id % 4 == 0:\n - if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_request_or_push_data(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n - )\n + elif stream_is_unidirectional(stream_id):\n - elif stream_is_unidirectional(stream_id):\n + return self._receive_stream_data_uni(\n - return self._receive_stream_data_uni(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n + except ProtocolError as exc:\n + self._is_done = True\n + self._quic.close(\n + error_code=exc.error_code, reason_phrase=exc.reason_phrase\n )\n return []\n \n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_data_before_headers(self):\n \"\"\"\n We should not receive DATA before receiving headers.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n - with self.assertRaises(UnexpectedFrame) as cm:\n + h3_server.handle_event(\n - h3_server.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n - stream_id=0,\n + stream_id=0, data=encode_frame(FrameType.DATA, b\"\"), end_stream=False\n - data=encode_frame(FrameType.DATA, b\"\"),\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_server.closed,\n + (\n + ErrorCode.HTTP_UNEXPECTED_FRAME,\n + \"DATA frame is not allowed in this state\",\n + ),\n + )\n - self.assertEqual(str(cm.exception), \"DATA frame is not allowed in this state\")\n \n===========changed ref 2===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_bad_headers(self):\n \"\"\"\n We should not receive HEADERS which cannot be decoded.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n - with self.assertRaises(QpackDecompressionFailed) as cm:\n + h3_server.handle_event(\n - h3_server.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n - stream_id=0,\n + stream_id=0, data=encode_frame(FrameType.HEADERS, b\"\"), end_stream=False\n - data=encode_frame(FrameType.HEADERS, b\"\"),\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_server.closed, (ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED, \"\")\n + )\n - self.assertEqual(str(cm.exception), \"\")\n \n===========changed ref 3===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_encoder_stream_error(self):\n \"\"\"\n Receiving garbage on the QPACK encoder stream triggers an exception.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(QpackEncoderStreamError) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=7,\n - stream_id=7,\n + data=encode_uint_var(StreamType.QPACK_ENCODER) + b\"\\x00\",\n - data=encode_uint_var(StreamType.QPACK_ENCODER) + b\"\\x00\",\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed, (ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR, \"\")\n + )\n - self.assertEqual(str(cm.exception), \"\")\n \n===========changed ref 4===========\n # module: tests.test_h3\n class FakeQuicConnection:\n + def close(self, error_code, reason_phrase):\n + self.closed = (error_code, reason_phrase)\n + "}}},{"rowIdx":3492,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_request_frame_push_promise_from_client"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":" <8>: with self.assertRaises(UnexpectedFrame) as cm:\n <9>: h3_server.handle_event(\n h3_server.handle_event(\n<10>: StreamDataReceived(\n StreamDataReceived(\n<11>: stream_id=0,\n stream_id=0,\n<12>: data=encode_frame(FrameType.PUSH_PROMISE, b\"\"),\n data=encode_frame(FrameType.PUSH_PROMISE, b\"\"),\n<13>: end_stream=False,\n end_stream=False,\n<14>: )\n<16>: )\n self.assertEqual(\n quic_server.closed,\n (ErrorCode.HTTP_UNEXPECTED_FRAME, \"Clients must not send PUSH_PROMISE\"),\n )\n self.assertEqual(str(cm.exception), \"Clients must not send PUSH_PROMISE\")\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_push_promise_from_client(self):\n <0> \"\"\"\n <1> A server should not receive PUSH_PROMISE on a request stream.\n <2> \"\"\"\n <3> quic_server = FakeQuicConnection(\n <4> configuration=QuicConfiguration(is_client=False)\n <5> )\n <6> h3_server = H3Connection(quic_server)\n <7> \n <8> with self.assertRaises(UnexpectedFrame) as cm:\n <9> h3_server.handle_event(\n<10> StreamDataReceived(\n<11> stream_id=0,\n<12> data=encode_frame(FrameType.PUSH_PROMISE, b\"\"),\n<13> end_stream=False,\n<14> )\n<15> )\n<16> self.assertEqual(str(cm.exception), \"Clients must not send PUSH_PROMISE\")\n<17> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h3.connection\n H3Connection(quic: QuicConnection)\n \n at: aioquic.h3.connection.H3Connection\n handle_event(event: QuicEvent) -> List[H3Event]\n \n send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None\n \n at: tests.test_h3\n h3_transfer(quic_sender, h3_receiver)\n \n at: tests.test_h3.FakeQuicConnection\n get_next_available_stream_id(is_unidirectional=False)\n \n at: tests.test_h3.H3ConnectionTest.test_handle_request_frame_headers_after_trailers\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n \n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n \n h3_client = H3Connection(quic_client)\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def handle_event(self, event: QuicEvent) -> List[H3Event]:\n \"\"\"\n Handle a QUIC event and return a list of HTTP events.\n \n :param event: The QUIC event to handle.\n \"\"\"\n + if isinstance(event, StreamDataReceived) and not self._is_done:\n - if isinstance(event, StreamDataReceived):\n stream_id = event.stream_id\n if stream_id not in self._stream:\n self._stream[stream_id] = H3Stream()\n + try:\n + if stream_id % 4 == 0:\n - if stream_id % 4 == 0:\n + return self._receive_request_or_push_data(\n - return self._receive_request_or_push_data(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n - )\n + elif stream_is_unidirectional(stream_id):\n - elif stream_is_unidirectional(stream_id):\n + return self._receive_stream_data_uni(\n - return self._receive_stream_data_uni(\n + stream_id, event.data, event.end_stream\n - stream_id, event.data, event.end_stream\n + )\n + except ProtocolError as exc:\n + self._is_done = True\n + self._quic.close(\n + error_code=exc.error_code, reason_phrase=exc.reason_phrase\n )\n return []\n \n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_data_before_headers(self):\n \"\"\"\n We should not receive DATA before receiving headers.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n - with self.assertRaises(UnexpectedFrame) as cm:\n + h3_server.handle_event(\n - h3_server.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n - stream_id=0,\n + stream_id=0, data=encode_frame(FrameType.DATA, b\"\"), end_stream=False\n - data=encode_frame(FrameType.DATA, b\"\"),\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_server.closed,\n + (\n + ErrorCode.HTTP_UNEXPECTED_FRAME,\n + \"DATA frame is not allowed in this state\",\n + ),\n + )\n - self.assertEqual(str(cm.exception), \"DATA frame is not allowed in this state\")\n \n===========changed ref 2===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_bad_headers(self):\n \"\"\"\n We should not receive HEADERS which cannot be decoded.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n - with self.assertRaises(QpackDecompressionFailed) as cm:\n + h3_server.handle_event(\n - h3_server.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n - stream_id=0,\n + stream_id=0, data=encode_frame(FrameType.HEADERS, b\"\"), end_stream=False\n - data=encode_frame(FrameType.HEADERS, b\"\"),\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_server.closed, (ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED, \"\")\n + )\n - self.assertEqual(str(cm.exception), \"\")\n \n===========changed ref 3===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_encoder_stream_error(self):\n \"\"\"\n Receiving garbage on the QPACK encoder stream triggers an exception.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(QpackEncoderStreamError) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=7,\n - stream_id=7,\n + data=encode_uint_var(StreamType.QPACK_ENCODER) + b\"\\x00\",\n - data=encode_uint_var(StreamType.QPACK_ENCODER) + b\"\\x00\",\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed, (ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR, \"\")\n + )\n - self.assertEqual(str(cm.exception), \"\")\n \n===========changed ref 4===========\n # module: tests.test_h3\n class FakeQuicConnection:\n + def close(self, error_code, reason_phrase):\n + self.closed = (error_code, reason_phrase)\n + \n===========changed ref 5===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_decoder_stream_error(self):\n \"\"\"\n Receiving garbage on the QPACK decoder stream triggers an exception.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(QpackDecoderStreamError) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=11,\n - stream_id=11,\n + data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n - data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed, (ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR, \"\")\n + )\n - self.assertEqual(str(cm.exception), \"\")\n "}}},{"rowIdx":3493,"cells":{"path":{"kind":"string","value":"tests.test_h3/H3ConnectionTest.test_handle_request_frame_wrong_frame_type"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"ef10cb76ba76a4d6423b00dbfeb3656819e50c8b"},"commit_message":{"kind":"string","value":"[http3] handle protocol errors"},"ground_truth":{"kind":"string","value":" <5>: with self.assertRaises(WrongStream) as cm:\n <6>: h3_server.handle_event(\n h3_server.handle_event(\n <7>: StreamDataReceived(\n StreamDataReceived(\n <8>: stream_id=0,\n stream_id=0,\n <9>: data=encode_frame(FrameType.SETTINGS, b\"\"),\n data=encode_frame(FrameType.SETTINGS, b\"\"),\n<10>: end_stream=False,\n end_stream=False,\n<11>: )\n<13>: )\n self.assertEqual(\n quic_server.closed,\n (ErrorCode.HTTP_WRONG_STREAM, \"Invalid frame type on request stream\"),\n )\n self.assertEqual(str(cm.exception), \"Invalid frame type on request stream\")\n"},"main_code":{"kind":"string","value":" # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_wrong_frame_type(self):\n <0> quic_server = FakeQuicConnection(\n <1> configuration=QuicConfiguration(is_client=False)\n <2> )\n <3> h3_server = H3Connection(quic_server)\n <4> \n <5> with self.assertRaises(WrongStream) as cm:\n <6> h3_server.handle_event(\n <7> StreamDataReceived(\n <8> stream_id=0,\n <9> data=encode_frame(FrameType.SETTINGS, b\"\"),\n<10> end_stream=False,\n<11> )\n<12> )\n<13> self.assertEqual(str(cm.exception), \"Invalid frame type on request stream\")\n<14> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h3.connection\n ErrorCode(x: Union[str, bytes, bytearray], base: int)\n ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n encode_frame(frame_type: int, frame_data: bytes) -> bytes\n \n at: tests.test_h3.FakeQuicConnection.__init__\n self.closed = None\n \n at: tests.test_h3.FakeQuicConnection.close\n self.closed = (error_code, reason_phrase)\n \n at: tests.test_h3.H3ConnectionTest.test_handle_request_frame_headers_after_trailers\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n \n at: unittest.case.TestCase\n assertEqual(first: Any, second: Any, msg: Any=...) -> None\n \n \n===========changed ref 0===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_push_promise_from_client(self):\n \"\"\"\n A server should not receive PUSH_PROMISE on a request stream.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n - with self.assertRaises(UnexpectedFrame) as cm:\n + h3_server.handle_event(\n - h3_server.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=0,\n - stream_id=0,\n + data=encode_frame(FrameType.PUSH_PROMISE, b\"\"),\n - data=encode_frame(FrameType.PUSH_PROMISE, b\"\"),\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_server.closed,\n + (ErrorCode.HTTP_UNEXPECTED_FRAME, \"Clients must not send PUSH_PROMISE\"),\n + )\n - self.assertEqual(str(cm.exception), \"Clients must not send PUSH_PROMISE\")\n \n===========changed ref 1===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_data_before_headers(self):\n \"\"\"\n We should not receive DATA before receiving headers.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n - with self.assertRaises(UnexpectedFrame) as cm:\n + h3_server.handle_event(\n - h3_server.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n - stream_id=0,\n + stream_id=0, data=encode_frame(FrameType.DATA, b\"\"), end_stream=False\n - data=encode_frame(FrameType.DATA, b\"\"),\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_server.closed,\n + (\n + ErrorCode.HTTP_UNEXPECTED_FRAME,\n + \"DATA frame is not allowed in this state\",\n + ),\n + )\n - self.assertEqual(str(cm.exception), \"DATA frame is not allowed in this state\")\n \n===========changed ref 2===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_request_frame_bad_headers(self):\n \"\"\"\n We should not receive HEADERS which cannot be decoded.\n \"\"\"\n quic_server = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=False)\n )\n h3_server = H3Connection(quic_server)\n \n - with self.assertRaises(QpackDecompressionFailed) as cm:\n + h3_server.handle_event(\n - h3_server.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n - stream_id=0,\n + stream_id=0, data=encode_frame(FrameType.HEADERS, b\"\"), end_stream=False\n - data=encode_frame(FrameType.HEADERS, b\"\"),\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_server.closed, (ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED, \"\")\n + )\n - self.assertEqual(str(cm.exception), \"\")\n \n===========changed ref 3===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_encoder_stream_error(self):\n \"\"\"\n Receiving garbage on the QPACK encoder stream triggers an exception.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(QpackEncoderStreamError) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=7,\n - stream_id=7,\n + data=encode_uint_var(StreamType.QPACK_ENCODER) + b\"\\x00\",\n - data=encode_uint_var(StreamType.QPACK_ENCODER) + b\"\\x00\",\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed, (ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR, \"\")\n + )\n - self.assertEqual(str(cm.exception), \"\")\n \n===========changed ref 4===========\n # module: tests.test_h3\n class FakeQuicConnection:\n + def close(self, error_code, reason_phrase):\n + self.closed = (error_code, reason_phrase)\n + \n===========changed ref 5===========\n # module: tests.test_h3\n class H3ConnectionTest(TestCase):\n def test_handle_qpack_decoder_stream_error(self):\n \"\"\"\n Receiving garbage on the QPACK decoder stream triggers an exception.\n \"\"\"\n quic_client = FakeQuicConnection(\n configuration=QuicConfiguration(is_client=True)\n )\n h3_client = H3Connection(quic_client)\n \n - with self.assertRaises(QpackDecoderStreamError) as cm:\n + h3_client.handle_event(\n - h3_client.handle_event(\n + StreamDataReceived(\n - StreamDataReceived(\n + stream_id=11,\n - stream_id=11,\n + data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n - data=encode_uint_var(StreamType.QPACK_DECODER) + b\"\\x00\",\n + end_stream=False,\n - end_stream=False,\n - )\n )\n + )\n + self.assertEqual(\n + quic_client.closed, (ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR, \"\")\n + )\n - self.assertEqual(str(cm.exception), \"\")\n \n===========changed ref 6===========\n # module: tests.test_h3\n class FakeQuicConnection:\n def __init__(self, configuration):\n + self.closed = None\n self.configuration = configuration\n self.stream_queue = []\n self._events = []\n self._next_stream_bidi = 0 if configuration.is_client else 1\n self._next_stream_uni = 2 if configuration.is_client else 3\n "}}},{"rowIdx":3494,"cells":{"path":{"kind":"string","value":"docs.http_client/http_client"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"11951421d2d76d3393f237b8d806c63ffa23a592"},"commit_message":{"kind":"string","value":"[docs] update HTTP client example to include ALPN (fixes: #28)"},"ground_truth":{"kind":"string","value":" <0>: configuration = QuicConfiguration(alpn_protocols=[\"hq-22\"])\n \n async with connect(host, port, configuration=configuration) as connection:\n async with connect(host, port) as connection:\n"},"main_code":{"kind":"string","value":" # module: docs.http_client\n def http_client(host, port):\n <0> async with connect(host, port) as connection:\n <1> reader, writer = await connection.create_stream()\n <2> writer.write(b\"GET /\\r\\n\")\n <3> writer.write_eof()\n <4> \n <5> response = await reader.read()\n <6> sys.stdout.buffer.write(response)\n <7> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.asyncio.client\n connect(host: str, port: int, *, configuration: Optional[QuicConfiguration]=None, create_protocol: Optional[Callable]=QuicConnectionProtocol, session_ticket_handler: Optional[SessionTicketHandler]=None, stream_handler: Optional[QuicStreamHandler]=None) -> AsyncGenerator[QuicConnectionProtocol, None]\n connect(*args, **kwds)\n \n at: aioquic.asyncio.protocol.QuicConnectionProtocol\n create_stream(is_unidirectional: bool=False) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]\n \n at: aioquic.quic.configuration\n QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n ))\n \n at: aioquic.quic.configuration.QuicConfiguration\n alpn_protocols: Optional[List[str]] = None\n \n certificate: Any = None\n \n connection_id_length: int = 8\n \n idle_timeout: float = 60.0\n \n is_client: bool = True\n \n private_key: Any = None\n \n quic_logger: Optional[QuicLogger] = None\n \n secrets_log_file: TextIO = None\n \n server_name: Optional[str] = None\n \n session_ticket: Optional[SessionTicket] = None\n \n supported_versions: List[int] = field(\n default_factory=lambda: [QuicProtocolVersion.DRAFT_22]\n )\n \n "}}},{"rowIdx":3495,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._decode_headers"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"e568f02b492ee76af486b79b1babef6880140564"},"commit_message":{"kind":"string","value":"[http3] de-duplicate some code to process unblocked headers"},"ground_truth":{"kind":"string","value":" <2>: \n This is called with frame_data=None when a stream becomes unblocked.\n <4>: if frame_data is None:\n decoder, headers = self._decoder.resume_header(stream_id)\n else:\n decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n + def _decode_headers(self, stream_id: int, frame_data: Optional[bytes]) -> Headers:\n - def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers:\n <0> \"\"\"\n <1> Decode a HEADERS block and send decoder updates on the decoder stream.\n <2> \"\"\"\n <3> try:\n <4> decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n <5> self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n <6> except pylsqpack.DecompressionFailed as exc:\n <7> raise QpackDecompressionFailed() from exc\n <8> \n <9> return headers\n<10> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h3.connection.H3Connection.__init__\n self._decoder = pylsqpack.Decoder(\n self._max_table_capacity, self._blocked_streams\n )\n \n at: aioquic.h3.events\n Headers = List[Tuple[bytes, bytes]]\n \n "}}},{"rowIdx":3496,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Connection._receive_stream_data_uni"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"e568f02b492ee76af486b79b1babef6880140564"},"commit_message":{"kind":"string","value":"[http3] de-duplicate some code to process unblocked headers"},"ground_truth":{"kind":"string","value":""},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n <0> http_events: List[H3Event] = []\n <1> \n <2> stream = self._stream[stream_id]\n <3> stream.buffer += data\n <4> if stream_ended:\n <5> stream.ended = True\n <6> \n <7> buf = Buffer(data=stream.buffer)\n <8> consumed = 0\n <9> unblocked_streams: Set[int] = set()\n<10> \n<11> while stream.stream_type == StreamType.PUSH or not buf.eof():\n<12> # fetch stream type for unidirectional streams\n<13> if stream.stream_type is None:\n<14> try:\n<15> stream.stream_type = buf.pull_uint_var()\n<16> except BufferReadError:\n<17> break\n<18> consumed = buf.tell()\n<19> \n<20> # check unicity\n<21> if stream.stream_type == StreamType.CONTROL:\n<22> if self._peer_control_stream_id is not None:\n<23> raise StreamCreationError(\"Only one control stream is allowed\")\n<24> self._peer_control_stream_id = stream_id\n<25> elif stream.stream_type == StreamType.QPACK_DECODER:\n<26> if self._peer_decoder_stream_id is not None:\n<27> raise StreamCreationError(\n<28> \"Only one QPACK decoder stream is allowed\"\n<29> )\n<30> self._peer_decoder_stream_id = stream_id\n<31> elif stream.stream_type == StreamType.QPACK_ENCODER:\n<32> if self._peer_encoder_stream_id is not None:\n<33> raise StreamCreationError(\n<34> \"Only one QPACK encoder stream is allowed\"\n<35> )\n<36> self._peer_encoder_stream_id = stream_id\n<37> \n<38> if stream.stream_type == StreamType.CONTROL:\n<39> # fetch next frame\n<40> try:\n<41> frame_type = buf.pull_uint_var"},"context":{"kind":"string","value":"===========below chunk 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 1\n frame_length = buf.pull_uint_var()\n frame_data = buf.pull_bytes(frame_length)\n except BufferReadError:\n break\n consumed = buf.tell()\n \n self._handle_control_frame(frame_type, frame_data)\n elif stream.stream_type == StreamType.PUSH:\n # fetch push id\n if stream.push_id is None:\n try:\n stream.push_id = buf.pull_uint_var()\n except BufferReadError:\n break\n consumed = buf.tell()\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n return self._receive_request_or_push_data(stream_id, b\"\", stream_ended)\n elif stream.stream_type == StreamType.QPACK_DECODER:\n # feed unframed data to decoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n try:\n self._encoder.feed_decoder(data)\n except pylsqpack.DecoderStreamError as exc:\n raise QpackDecoderStreamError() from exc\n elif stream.stream_type == StreamType.QPACK_ENCODER:\n # feed unframed data to encoder\n data = buf.pull_bytes(buf.capacity - buf.tell())\n consumed = buf.tell()\n try:\n unblocked_streams.update(self._decoder.feed_encoder(data))\n except pylsqpack.EncoderStreamError as exc:\n raise QpackEncoderStreamError() from exc\n else:\n # unknown stream type, discard data\n buf.seek(buf.capacity)\n consumed = buf.tell()\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n \n===========below chunk 1===========\n # module: aioquic.h3.connection\n class H3Connection:\n def _receive_stream_data_uni(\n self, stream_id: int, data: bytes, stream_ended: bool\n ) -> List[H3Event]:\n # offset: 2\n = buf.tell()\n \n # remove processed data from buffer\n stream.buffer = stream.buffer[consumed:]\n \n # process unblocked streams\n for stream_id in unblocked_streams:\n stream = self._stream[stream_id]\n \n # decode headers\n decoder, headers = self._decoder.resume_header(stream_id)\n self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n stream.blocked = False\n \n # update state and emit headers\n if stream.headers_state == HeadersState.INITIAL:\n stream.headers_state = HeadersState.AFTER_HEADERS\n else:\n stream.headers_state = HeadersState.AFTER_TRAILERS\n http_events.append(\n HeadersReceived(\n headers=headers,\n stream_id=stream_id,\n stream_ended=stream.ended and not stream.buffer,\n )\n )\n \n # resume processing\n if stream.buffer:\n http_events.extend(\n self._receive_request_or_push_data(stream_id, b\"\", stream.ended)\n )\n \n return http_events\n \n \n===========unchanged ref 0===========\n at: aioquic._buffer\n BufferReadError(*args: object)\n \n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n eof() -> bool\n \n seek(pos: int) -> None\n \n tell() -> int\n \n pull_bytes(length: int) -> bytes\n \n pull_uint_var() -> int\n \n at: aioquic.h3.connection\n FrameType(x: Union[str, bytes, bytearray], base: int)\n FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n \n StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n StreamType(x: Union[str, bytes, bytearray], base: int)\n \n QpackDecoderStreamError(reason_phrase: str=\"\")\n \n QpackEncoderStreamError(reason_phrase: str=\"\")\n \n StreamCreationError(reason_phrase: str=\"\")\n \n at: aioquic.h3.connection.H3Connection\n _handle_control_frame(frame_type: int, frame_data: bytes) -> None\n \n _receive_request_or_push_data(stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event]\n \n at: aioquic.h3.connection.H3Connection.__init__\n self._decoder = pylsqpack.Decoder(\n self._max_table_capacity, self._blocked_streams\n )\n \n self._encoder = pylsqpack.Encoder()\n \n self._stream: Dict[int, H3Stream] = {}\n \n self._peer_control_stream_id: Optional[int] = None\n \n self._peer_decoder_stream_id: Optional[int] = None\n \n self._peer_encoder_stream_id: Optional[int] = None\n \n at: aioquic.h3.connection.H3Connection._receive_request_or_push_data\n http_events: List[H3Event] = []\n \n \n===========unchanged ref 1===========\n stream = self._stream[stream_id]\n \n consumed = buf.tell()\n consumed = 0\n \n at: aioquic.h3.connection.H3Stream.__init__\n self.blocked = False\n \n self.buffer = b\"\"\n \n self.ended = False\n \n self.push_id: Optional[int] = None\n \n self.stream_type: Optional[int] = None\n \n at: aioquic.h3.events\n H3Event()\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n Set = _alias(set, 1, inst=False, name='Set')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n class H3Connection:\n + def _decode_headers(self, stream_id: int, frame_data: Optional[bytes]) -> Headers:\n - def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers:\n \"\"\"\n Decode a HEADERS block and send decoder updates on the decoder stream.\n + \n + This is called with frame_data=None when a stream becomes unblocked.\n \"\"\"\n try:\n + if frame_data is None:\n + decoder, headers = self._decoder.resume_header(stream_id)\n + else:\n + decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n - decoder, headers = self._decoder.feed_header(stream_id, frame_data)\n self._quic.send_stream_data(self._local_decoder_stream_id, decoder)\n except pylsqpack.DecompressionFailed as exc:\n raise QpackDecompressionFailed() from exc\n \n return headers\n "}}},{"rowIdx":3497,"cells":{"path":{"kind":"string","value":"aioquic.quic.connection/QuicConnection._handle_reset_stream_frame"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5a39e632e294f65d5596d4c69d512107890c47ca"},"commit_message":{"kind":"string","value":"[quic] add StreamReset.error_code to report reset cause"},"ground_truth":{"kind":"string","value":"<25>: self._events.append(\n events.StreamReset(error_code=error_code, stream_id=stream_id)\n )\n self._events.append(events.StreamReset(stream_id=stream_id))\n"},"main_code":{"kind":"string","value":" # module: aioquic.quic.connection\n class QuicConnection:\n def _handle_reset_stream_frame(\n self, context: QuicReceiveContext, frame_type: int, buf: Buffer\n ) -> None:\n <0> \"\"\"\n <1> Handle a RESET_STREAM frame.\n <2> \"\"\"\n <3> stream_id = buf.pull_uint_var()\n <4> error_code = buf.pull_uint_var()\n <5> final_size = buf.pull_uint_var()\n <6> \n <7> # log frame\n <8> if self._quic_logger is not None:\n <9> context.quic_logger_frames.append(\n<10> self._quic_logger.encode_reset_stream_frame(\n<11> error_code=error_code, final_size=final_size, stream_id=stream_id\n<12> )\n<13> )\n<14> \n<15> # check stream direction\n<16> self._assert_stream_can_receive(frame_type, stream_id)\n<17> \n<18> self._logger.info(\n<19> \"Stream %d reset by peer (error code %d, final size %d)\",\n<20> stream_id,\n<21> error_code,\n<22> final_size,\n<23> )\n<24> # stream = self._get_or_create_stream(frame_type, stream_id)\n<25> self._events.append(events.StreamReset(stream_id=stream_id))\n<26> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic._buffer\n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic._buffer.Buffer\n pull_uint_var() -> int\n \n at: aioquic.quic.connection\n QuicReceiveContext(epoch: tls.Epoch, host_cid: bytes, network_path: QuicNetworkPath, quic_logger_frames: Optional[List[Any]], time: float)\n \n at: aioquic.quic.connection.QuicConnection\n _assert_stream_can_receive(frame_type: int, stream_id: int) -> None\n \n at: aioquic.quic.connection.QuicConnection.__init__\n self._events: Deque[events.QuicEvent] = deque()\n \n self._quic_logger: Optional[QuicLoggerTrace] = None\n self._quic_logger = configuration.quic_logger.start_trace(\n is_client=configuration.is_client, odcid=logger_connection_id\n )\n \n self._logger = QuicConnectionAdapter(\n logger, {\"id\": dump_cid(logger_connection_id)}\n )\n \n at: aioquic.quic.connection.QuicConnection._close_end\n self._quic_logger = None\n \n at: aioquic.quic.connection.QuicReceiveContext\n epoch: tls.Epoch\n \n host_cid: bytes\n \n network_path: QuicNetworkPath\n \n quic_logger_frames: Optional[List[Any]]\n \n time: float\n \n at: aioquic.quic.logger.QuicLoggerTrace\n encode_reset_stream_frame(error_code: int, final_size: int, stream_id: int) -> Dict\n \n at: collections.deque\n append(x: _T) -> None\n \n at: logging.LoggerAdapter\n logger: Logger\n \n extra: Mapping[str, Any]\n \n \n===========unchanged ref 1===========\n info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None\n \n "}}},{"rowIdx":3498,"cells":{"path":{"kind":"string","value":"tests.test_connection/QuicConnectionTest.test_handle_reset_stream_frame"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"5a39e632e294f65d5596d4c69d512107890c47ca"},"commit_message":{"kind":"string","value":"[quic] add StreamReset.error_code to report reset cause"},"ground_truth":{"kind":"string","value":" <3>: consume_events(client)\n <8>: Buffer(data=binascii.unhexlify(\"000100\")),\n Buffer(data=binascii.unhexlify(\"001100\")),\n"},"main_code":{"kind":"string","value":" # module: tests.test_connection\n class QuicConnectionTest(TestCase):\n def test_handle_reset_stream_frame(self):\n <0> with client_and_server() as (client, server):\n <1> # client creates bidirectional stream 0\n <2> client.send_stream_data(stream_id=0, data=b\"hello\")\n <3> \n <4> # client receives RESET_STREAM\n <5> client._handle_reset_stream_frame(\n <6> client_receive_context(client),\n <7> QuicFrameType.RESET_STREAM,\n <8> Buffer(data=binascii.unhexlify(\"001100\")),\n <9> )\n<10> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic._buffer\n Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None)\n \n at: aioquic.quic.packet\n QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)\n QuicFrameType(x: Union[str, bytes, bytearray], base: int)\n \n at: binascii\n unhexlify(hexstr: _Ascii, /) -> bytes\n \n at: tests.test_connection\n client_receive_context(client, epoch=tls.Epoch.ONE_RTT)\n \n consume_events(connection)\n \n client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_options={}, server_patch=lambda x: None, transport_options={})\n \n \n===========changed ref 0===========\n # module: aioquic.quic.events\n @dataclass\n class StreamReset(QuicEvent):\n \"\"\"\n The StreamReset event is fired when the remote peer resets a stream.\n \"\"\"\n \n + error_code: int\n + \"The error code that triggered the reset.\"\n + \n stream_id: int\n \"The ID of the stream that was reset.\"\n \n===========changed ref 1===========\n # module: aioquic.quic.connection\n class QuicConnection:\n def _handle_reset_stream_frame(\n self, context: QuicReceiveContext, frame_type: int, buf: Buffer\n ) -> None:\n \"\"\"\n Handle a RESET_STREAM frame.\n \"\"\"\n stream_id = buf.pull_uint_var()\n error_code = buf.pull_uint_var()\n final_size = buf.pull_uint_var()\n \n # log frame\n if self._quic_logger is not None:\n context.quic_logger_frames.append(\n self._quic_logger.encode_reset_stream_frame(\n error_code=error_code, final_size=final_size, stream_id=stream_id\n )\n )\n \n # check stream direction\n self._assert_stream_can_receive(frame_type, stream_id)\n \n self._logger.info(\n \"Stream %d reset by peer (error code %d, final size %d)\",\n stream_id,\n error_code,\n final_size,\n )\n # stream = self._get_or_create_stream(frame_type, stream_id)\n + self._events.append(\n + events.StreamReset(error_code=error_code, stream_id=stream_id)\n + )\n - self._events.append(events.StreamReset(stream_id=stream_id))\n "}}},{"rowIdx":3499,"cells":{"path":{"kind":"string","value":"aioquic.h3.connection/H3Stream.__init__"},"type":{"kind":"string","value":"Modified"},"project":{"kind":"string","value":"aiortc~aioquic"},"commit_hash":{"kind":"string","value":"44c20c190cf84f2bacad0299e3848fd2cc2a11b7"},"commit_message":{"kind":"string","value":"[http3] add some initial QLOG support for HTTP/3 events"},"ground_truth":{"kind":"string","value":" <1>: self.blocked_frame_size: Optional[int] = None\n"},"main_code":{"kind":"string","value":" # module: aioquic.h3.connection\n class H3Stream:\n def __init__(self) -> None:\n <0> self.blocked = False\n <1> self.buffer = b\"\"\n <2> self.ended = False\n <3> self.frame_size: Optional[int] = None\n <4> self.frame_type: Optional[int] = None\n <5> self.headers_state: HeadersState = HeadersState.INITIAL\n <6> self.push_id: Optional[int] = None\n <7> self.stream_type: Optional[int] = None\n <8> \n "},"context":{"kind":"string","value":"===========unchanged ref 0===========\n at: aioquic.h3.events\n Headers = List[Tuple[bytes, bytes]]\n \n at: typing\n List = _alias(list, 1, inst=False, name='List')\n \n Dict = _alias(dict, 2, inst=False, name='Dict')\n \n \n===========changed ref 0===========\n # module: aioquic.h3.connection\n + def qlog_encode_data_frame(byte_length: int, stream_id: int) -> Dict:\n + return {\n + \"byte_length\": str(byte_length),\n + \"frame\": {\"frame_type\": \"data\"},\n + \"stream_id\": str(stream_id),\n + }\n + "}}}],"truncated":false,"partial":false},"paginationData":{"pageIndex":34,"numItemsPerPage":100,"numTotalItems":7800,"offset":3400,"length":100}},"jwt":"eyJhbGciOiJFZERTQSJ9.eyJyZWFkIjp0cnVlLCJwZXJtaXNzaW9ucyI6eyJyZXBvLmNvbnRlbnQucmVhZCI6dHJ1ZX0sImlhdCI6MTc1Nzk3NjI1Niwic3ViIjoiL2RhdGFzZXRzL2tyYWFsZmFyL0NvZWRpdG9yLXByb2Nlc3NlZC1kZW1vMiIsImV4cCI6MTc1Nzk3OTg1NiwiaXNzIjoiaHR0cHM6Ly9odWdnaW5nZmFjZS5jbyJ9.IrjRja3MfSoykIngkU2VFJ_uWE6aAxtkz1jNUpm0JJQt_F1Ir8CFrfHRj5DXSRDNmVe86sjLlTJLx2cHjV-iCA","displayUrls":true},"discussionsStats":{"closed":0,"open":1,"total":1},"fullWidth":true,"hasGatedAccess":true,"hasFullAccess":true,"isEmbedded":false,"savedQueries":{"community":[],"user":[]}}">
path
stringlengths
9
117
type
stringclasses
2 values
project
stringclasses
10 values
commit_hash
stringlengths
40
40
commit_message
stringlengths
1
137
ground_truth
stringlengths
0
2.74k
main_code
stringlengths
102
3.37k
context
stringlengths
0
14.7k
aioquic.h3.connection/H3Connection.__init__
Modified
aiortc~aioquic
eb4fc3878387177cf3b52a94f4c63fb9c871cbcf
[http3] add initial support for server push
<8>:<add> <add> self._max_push_id: Optional[int] = 8 if self._is_client else None <add> self._next_push_id: int = 0
# module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): <0> self._max_table_capacity = 0x100 <1> self._blocked_streams = 0x10 <2> <3> self._is_client = quic.configuration.is_client <4> self._quic = quic <5> self._decoder = Decoder(self._max_table_capacity, self._blocked_streams) <6> self._encoder = Encoder() <7> self._stream: Dict[int, H3Stream] = {} <8> <9> self._local_control_stream_id: Optional[int] = None <10> self._local_decoder_stream_id: Optional[int] = None <11> self._local_encoder_stream_id: Optional[int] = None <12> <13> self._peer_control_stream_id: Optional[int] = None <14> self._peer_decoder_stream_id: Optional[int] = None <15> self._peer_encoder_stream_id: Optional[int] = None <16> <17> self._init_connection() <18>
===========unchanged ref 0=========== at: aioquic.h3.connection H3Stream() at: aioquic.quic.configuration.QuicConfiguration alpn_protocols: Optional[List[str]] = None certificate: Any = None connection_id_length: int = 8 idle_timeout: float = 60.0 is_client: bool = True private_key: Any = None quic_logger: Optional[QuicLogger] = None secrets_log_file: TextIO = None server_name: Optional[str] = None session_ticket: Optional[SessionTicket] = None supported_versions: List[int] = field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] ) at: aioquic.quic.connection QuicConnection(*, configuration: QuicConfiguration, logger_connection_id: Optional[bytes]=None, original_connection_id: Optional[bytes]=None, session_ticket_fetcher: Optional[tls.SessionTicketFetcher]=None, session_ticket_handler: Optional[tls.SessionTicketHandler]=None) at: typing Dict = _alias(dict, 2, inst=False, name='Dict') ===========changed ref 0=========== # module: aioquic.h3.connection + def parse_max_push_id(data: bytes) -> int: + buf = Buffer(data=data) + max_push_id = buf.pull_uint_var() + assert buf.eof() + return max_push_id + ===========changed ref 1=========== # module: aioquic.h3.connection class H3Stream: def __init__(self) -> None: self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None + self.push_id: Optional[int] = None self.stream_type: Optional[int] = None ===========changed ref 2=========== # module: aioquic.h3.events + @dataclass + class PushPromiseReceived(HttpEvent): + """ + The PushedStreamReceived event is fired whenever a pushed stream has been + received from the remote peer. + """ + + headers: Headers + "The request headers." + + push_id: int + "The Push ID of the push promise." + + stream_id: int + "The Stream ID of the stream that the push is related to." +
aioquic.h3.connection/H3Connection.handle_event
Modified
aiortc~aioquic
eb4fc3878387177cf3b52a94f4c63fb9c871cbcf
[http3] add initial support for server push
<14>:<add> return self._receive_stream_data_uni( <del> return self._receive_stream_data_uni(stream_id, event.data) <15>:<add> stream_id, event.data, event.end_stream <add> )
# module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[HttpEvent]: <0> """ <1> Handle a QUIC event and return a list of HTTP events. <2> <3> :param event: The QUIC event to handle. <4> """ <5> if isinstance(event, StreamDataReceived): <6> stream_id = event.stream_id <7> if stream_id not in self._stream: <8> self._stream[stream_id] = H3Stream() <9> if stream_id % 4 == 0: <10> return self._receive_stream_data_bidi( <11> stream_id, event.data, event.end_stream <12> ) <13> elif stream_is_unidirectional(stream_id): <14> return self._receive_stream_data_uni(stream_id, event.data) <15> return [] <16>
===========unchanged ref 0=========== at: aioquic.h3.connection.H3Connection _init_connection(self) -> None _init_connection() -> None at: aioquic.h3.connection.H3Connection._init_connection self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL) self._local_encoder_stream_id = self._create_uni_stream( StreamType.QPACK_ENCODER ) self._local_decoder_stream_id = self._create_uni_stream( StreamType.QPACK_DECODER ) at: aioquic.h3.connection.H3Connection._receive_stream_data_uni self._peer_control_stream_id = stream_id self._peer_decoder_stream_id = stream_id self._peer_encoder_stream_id = stream_id at: aioquic.h3.connection.H3Connection.push_promise self._next_push_id += 1 at: aioquic.h3.events HttpEvent() at: aioquic.quic.events QuicEvent() at: typing List = _alias(list, 1, inst=False, name='List') ===========changed ref 0=========== # module: aioquic.h3.connection + def parse_max_push_id(data: bytes) -> int: + buf = Buffer(data=data) + max_push_id = buf.pull_uint_var() + assert buf.eof() + return max_push_id + ===========changed ref 1=========== # module: aioquic.h3.connection class H3Stream: def __init__(self) -> None: self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None + self.push_id: Optional[int] = None self.stream_type: Optional[int] = None ===========changed ref 2=========== # module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client self._quic = quic self._decoder = Decoder(self._max_table_capacity, self._blocked_streams) self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} + + self._max_push_id: Optional[int] = 8 if self._is_client else None + self._next_push_id: int = 0 self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None self._init_connection() ===========changed ref 3=========== # module: aioquic.h3.events + @dataclass + class PushPromiseReceived(HttpEvent): + """ + The PushedStreamReceived event is fired whenever a pushed stream has been + received from the remote peer. + """ + + headers: Headers + "The request headers." + + push_id: int + "The Push ID of the push promise." + + stream_id: int + "The Stream ID of the stream that the push is related to." +
aioquic.h3.connection/H3Connection._handle_control_frame
Modified
aiortc~aioquic
eb4fc3878387177cf3b52a94f4c63fb9c871cbcf
[http3] add initial support for server push
<10>:<add> elif frame_type == FrameType.MAX_PUSH_ID: <add> if self._is_client: <add> raise QuicConnectionError( <add> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, <add> frame_type=None, <add> reason_phrase="Servers must not send MAX_PUSH_ID", <add> ) <add> self._max_push_id = parse_max_push_id(frame_data)
# module: aioquic.h3.connection class H3Connection: def _handle_control_frame(self, frame_type: int, frame_data: bytes) -> None: <0> """ <1> Handle a frame received on the peer's control stream. <2> """ <3> if frame_type == FrameType.SETTINGS: <4> settings = parse_settings(frame_data) <5> encoder = self._encoder.apply_settings( <6> max_table_capacity=settings.get(Setting.QPACK_MAX_TABLE_CAPACITY, 0), <7> blocked_streams=settings.get(Setting.QPACK_BLOCKED_STREAMS, 0), <8> ) <9> self._quic.send_stream_data(self._local_encoder_stream_id, encoder) <10> elif frame_type in ( <11> FrameType.DATA, <12> FrameType.HEADERS, <13> FrameType.PUSH_PROMISE, <14> FrameType.DUPLICATE_PUSH, <15> ): <16> raise QuicConnectionError( <17> error_code=ErrorCode.HTTP_WRONG_STREAM, <18> frame_type=None, <19> reason_phrase="Invalid frame type on control stream", <20> ) <21>
===========unchanged ref 0=========== at: aioquic.h3.connection FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) encode_frame(frame_type: int, frame_data: bytes) -> bytes at: aioquic.h3.connection.H3Connection _encode_headers(stream_id, headers: Headers) -> bytes _encode_headers(self, stream_id, headers: Headers) -> bytes at: aioquic.h3.connection.H3Connection.__init__ self._quic = quic at: aioquic.h3.events Headers = List[Tuple[bytes, bytes]] at: aioquic.quic.connection.QuicConnection send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None ===========changed ref 0=========== # module: aioquic.h3.connection + def parse_max_push_id(data: bytes) -> int: + buf = Buffer(data=data) + max_push_id = buf.pull_uint_var() + assert buf.eof() + return max_push_id + ===========changed ref 1=========== # module: aioquic.h3.connection class H3Stream: def __init__(self) -> None: self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None + self.push_id: Optional[int] = None self.stream_type: Optional[int] = None ===========changed ref 2=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[HttpEvent]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() if stream_id % 4 == 0: return self._receive_stream_data_bidi( stream_id, event.data, event.end_stream ) elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni(stream_id, event.data) + stream_id, event.data, event.end_stream + ) return [] ===========changed ref 3=========== # module: aioquic.h3.connection class H3Connection: + def push_promise(self, stream_id: int, headers: Headers) -> int: + """ + Send a push promise related to the specified stream. + + Returns the stream ID on which headers and data can be sent. + + :param stream_id: The stream ID on which to send the data. + :param headers: The HTTP request headers for this push. + """ + assert not self._is_client, "Only servers may send a push promise." + assert self._max_push_id is not None and self._next_push_id < self._max_push_id + + # send push promise + push_id = self._next_push_id + self._next_push_id += 1 + self._quic.send_stream_data( + stream_id, + encode_frame( + FrameType.PUSH_PROMISE, + encode_uint_var(push_id) + self._encode_headers(stream_id, headers), + ), + ) + + #  create push stream + push_stream_id = self._create_uni_stream(StreamType.PUSH) + self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id)) + + return push_stream_id + ===========changed ref 4=========== # module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client self._quic = quic self._decoder = Decoder(self._max_table_capacity, self._blocked_streams) self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} + + self._max_push_id: Optional[int] = 8 if self._is_client else None + self._next_push_id: int = 0 self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None self._init_connection() ===========changed ref 5=========== # module: aioquic.h3.events + @dataclass + class PushPromiseReceived(HttpEvent): + """ + The PushedStreamReceived event is fired whenever a pushed stream has been + received from the remote peer. + """ + + headers: Headers + "The request headers." + + push_id: int + "The Push ID of the push promise." + + stream_id: int + "The Stream ID of the stream that the push is related to." +
aioquic.h3.connection/H3Connection._init_connection
Modified
aiortc~aioquic
eb4fc3878387177cf3b52a94f4c63fb9c871cbcf
[http3] add initial support for server push
<14>:<add> if self._is_client: <add> self._quic.send_stream_data( <add> self._local_control_stream_id, <add> encode_frame(FrameType.MAX_PUSH_ID, encode_uint_var(self._max_push_id)), <add> )
# module: aioquic.h3.connection class H3Connection: def _init_connection(self) -> None: <0> # send our settings <1> self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL) <2> self._quic.send_stream_data( <3> self._local_control_stream_id, <4> encode_frame( <5> FrameType.SETTINGS, <6> encode_settings( <7> { <8> Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity, <9> Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams, <10> } <11> ), <12> ), <13> ) <14> <15> # create encoder and decoder streams <16> self._local_encoder_stream_id = self._create_uni_stream( <17> StreamType.QPACK_ENCODER <18> ) <19> self._local_decoder_stream_id = self._create_uni_stream( <20> StreamType.QPACK_DECODER <21> ) <22>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection.H3Connection.__init__ self._quic = quic self._decoder = Decoder(self._max_table_capacity, self._blocked_streams) self._encoder = Encoder() self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None at: aioquic.h3.connection.H3Connection._init_connection self._local_encoder_stream_id = self._create_uni_stream( StreamType.QPACK_ENCODER ) self._local_decoder_stream_id = self._create_uni_stream( StreamType.QPACK_DECODER ) at: aioquic.h3.events Headers = List[Tuple[bytes, bytes]] at: aioquic.quic.connection.QuicConnection get_next_available_stream_id(is_unidirectional=False) -> int send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None ===========changed ref 0=========== # module: aioquic.h3.connection + def parse_max_push_id(data: bytes) -> int: + buf = Buffer(data=data) + max_push_id = buf.pull_uint_var() + assert buf.eof() + return max_push_id + ===========changed ref 1=========== # module: aioquic.h3.connection class H3Stream: def __init__(self) -> None: self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None + self.push_id: Optional[int] = None self.stream_type: Optional[int] = None ===========changed ref 2=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[HttpEvent]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() if stream_id % 4 == 0: return self._receive_stream_data_bidi( stream_id, event.data, event.end_stream ) elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni(stream_id, event.data) + stream_id, event.data, event.end_stream + ) return [] ===========changed ref 3=========== # module: aioquic.h3.connection class H3Connection: def _handle_control_frame(self, frame_type: int, frame_data: bytes) -> None: """ Handle a frame received on the peer's control stream. """ if frame_type == FrameType.SETTINGS: settings = parse_settings(frame_data) encoder = self._encoder.apply_settings( max_table_capacity=settings.get(Setting.QPACK_MAX_TABLE_CAPACITY, 0), blocked_streams=settings.get(Setting.QPACK_BLOCKED_STREAMS, 0), ) self._quic.send_stream_data(self._local_encoder_stream_id, encoder) + elif frame_type == FrameType.MAX_PUSH_ID: + if self._is_client: + raise QuicConnectionError( + error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, + frame_type=None, + reason_phrase="Servers must not send MAX_PUSH_ID", + ) + self._max_push_id = parse_max_push_id(frame_data) elif frame_type in ( FrameType.DATA, FrameType.HEADERS, FrameType.PUSH_PROMISE, FrameType.DUPLICATE_PUSH, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on control stream", ) ===========changed ref 4=========== # module: aioquic.h3.connection class H3Connection: + def push_promise(self, stream_id: int, headers: Headers) -> int: + """ + Send a push promise related to the specified stream. + + Returns the stream ID on which headers and data can be sent. + + :param stream_id: The stream ID on which to send the data. + :param headers: The HTTP request headers for this push. + """ + assert not self._is_client, "Only servers may send a push promise." + assert self._max_push_id is not None and self._next_push_id < self._max_push_id + + # send push promise + push_id = self._next_push_id + self._next_push_id += 1 + self._quic.send_stream_data( + stream_id, + encode_frame( + FrameType.PUSH_PROMISE, + encode_uint_var(push_id) + self._encode_headers(stream_id, headers), + ), + ) + + #  create push stream + push_stream_id = self._create_uni_stream(StreamType.PUSH) + self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id)) + + return push_stream_id + ===========changed ref 5=========== # module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client self._quic = quic self._decoder = Decoder(self._max_table_capacity, self._blocked_streams) self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} + + self._max_push_id: Optional[int] = 8 if self._is_client else None + self._next_push_id: int = 0 self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None self._init_connection() ===========changed ref 6=========== # module: aioquic.h3.events + @dataclass + class PushPromiseReceived(HttpEvent): + """ + The PushedStreamReceived event is fired whenever a pushed stream has been + received from the remote peer. + """ + + headers: Headers + "The request headers." + + push_id: int + "The Push ID of the push promise." + + stream_id: int + "The Stream ID of the stream that the push is related to." +
aioquic.h3.connection/H3Connection._receive_stream_data_bidi
Modified
aiortc~aioquic
eb4fc3878387177cf3b52a94f4c63fb9c871cbcf
[http3] add initial support for server push
<14>:<del> stream.frame_size is not None <15>:<add> stream.frame_type == FrameType.DATA <del> and stream.frame_type == FrameType.DATA <16>:<add> and stream.frame_size is not None
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: <0> """ <1> Client-initiated bidirectional streams carry requests and responses. <2> """ <3> http_events: List[HttpEvent] = [] <4> <5> stream = self._stream[stream_id] <6> stream.buffer += data <7> if stream_ended: <8> stream.ended = True <9> if stream.blocked: <10> return http_events <11> <12> # shortcut DATA frame bits <13> if ( <14> stream.frame_size is not None <15> and stream.frame_type == FrameType.DATA <16> and len(stream.buffer) < stream.frame_size <17> ): <18> http_events.append( <19> DataReceived( <20> data=stream.buffer, stream_id=stream_id, stream_ended=False <21> ) <22> ) <23> stream.frame_size -= len(stream.buffer) <24> stream.buffer = b"" <25> return http_events <26> <27> # some peers (e.g. f5) end the stream with no data <28> if stream_ended and not stream.buffer: <29> http_events.append( <30> DataReceived(data=b"", stream_id=stream_id, stream_ended=True) <31> ) <32> return http_events <33> <34> buf = Buffer(data=stream.buffer) <35> consumed = 0 <36> <37> while not buf.eof(): <38> # fetch next frame header <39> if stream.frame_size is None: <40> try: <41> stream.frame_type = buf.pull_uint_var() <42> stream.frame_size = buf.pull_uint_var() <43> except BufferReadError: <44> break <45> consumed = buf.tell() <46> <47> # check how much data is available <48> chunk_size = min(stream.frame_size, buf.capacity - consumed</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: # offset: 1 if ( stream.frame_type == FrameType.HEADERS and chunk_size < stream.frame_size ): break # read available data frame_data = buf.pull_bytes(chunk_size) consumed = buf.tell() # detect end of frame stream.frame_size -= chunk_size if not stream.frame_size: stream.frame_size = None if stream.frame_type == FrameType.DATA and (stream_ended or frame_data): http_events.append( DataReceived( data=frame_data, stream_id=stream_id, stream_ended=stream_ended and buf.eof(), ) ) elif stream.frame_type == FrameType.HEADERS: try: headers = self._decode_headers(stream_id, frame_data) except StreamBlocked: stream.blocked = True break cls = ResponseReceived if self._is_client else RequestReceived http_events.append( cls( headers=headers, stream_id=stream_id, stream_ended=stream_ended and buf.eof(), ) ) elif stream.frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on request stream", ) # remove processed data from buffer stream.buffer = stream.buffer[consumed:] return http_events ===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) Setting(x: Union[str, bytes, bytearray], base: int) Setting(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) encode_frame(frame_type: int, frame_data: bytes) -> bytes encode_settings(settings: Dict[int, int]) -> bytes parse_max_push_id(data: bytes) -> int parse_settings(data: bytes) -> Dict[int, int] at: aioquic.h3.connection.H3Connection _create_uni_stream(stream_type: int) -> int _create_uni_stream(self, stream_type: int) -> int _decode_headers(stream_id: int, frame_data: bytes) -> Headers _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers at: aioquic.h3.connection.H3Connection.__init__ self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client self._quic = quic self._encoder = Encoder() self._max_push_id: Optional[int] = 8 if self._is_client else None self._local_control_stream_id: Optional[int] = None ===========unchanged ref 1=========== self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None at: aioquic.h3.events HttpEvent() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) ResponseReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.h3.events.DataReceived data: bytes stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.ResponseReceived headers: Headers stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.quic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) at: aioquic.quic.connection.QuicConnection send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None at: typing List = _alias(list, 1, inst=False, name='List') at: typing.Mapping get(key: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T] get(key: _KT) -> Optional[_VT_co] ===========changed ref 0=========== # module: aioquic.h3.connection + def parse_max_push_id(data: bytes) -> int: + buf = Buffer(data=data) + max_push_id = buf.pull_uint_var() + assert buf.eof() + return max_push_id + ===========changed ref 1=========== # module: aioquic.h3.connection class H3Stream: def __init__(self) -> None: self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None + self.push_id: Optional[int] = None self.stream_type: Optional[int] = None ===========changed ref 2=========== # module: aioquic.h3.connection class H3Connection: def _init_connection(self) -> None: # send our settings self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL) self._quic.send_stream_data( self._local_control_stream_id, encode_frame( FrameType.SETTINGS, encode_settings( { Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity, Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams, } ), ), ) + if self._is_client: + self._quic.send_stream_data( + self._local_control_stream_id, + encode_frame(FrameType.MAX_PUSH_ID, encode_uint_var(self._max_push_id)), + ) # create encoder and decoder streams self._local_encoder_stream_id = self._create_uni_stream( StreamType.QPACK_ENCODER ) self._local_decoder_stream_id = self._create_uni_stream( StreamType.QPACK_DECODER )
aioquic.h3.connection/H3Connection._receive_stream_data_uni
Modified
aiortc~aioquic
eb4fc3878387177cf3b52a94f4c63fb9c871cbcf
[http3] add initial support for server push
<4>:<add> if stream_ended: <add> stream.ended = True
# module: aioquic.h3.connection class H3Connection: + def _receive_stream_data_uni( + self, stream_id: int, data: bytes, stream_ended: bool + ) -> List[HttpEvent]: - def _receive_stream_data_uni(self, stream_id: int, data: bytes) -> List[HttpEvent]: <0> http_events: List[HttpEvent] = [] <1> <2> stream = self._stream[stream_id] <3> stream.buffer += data <4> <5> buf = Buffer(data=stream.buffer) <6> consumed = 0 <7> unblocked_streams: Set[int] = set() <8> <9> while not buf.eof(): <10> # fetch stream type for unidirectional streams <11> if stream.stream_type is None: <12> try: <13> stream.stream_type = buf.pull_uint_var() <14> except BufferReadError: <15> break <16> consumed = buf.tell() <17> <18> if stream.stream_type == StreamType.CONTROL: <19> assert self._peer_control_stream_id is None <20> self._peer_control_stream_id = stream_id <21> elif stream.stream_type == StreamType.QPACK_DECODER: <22> assert self._peer_decoder_stream_id is None <23> self._peer_decoder_stream_id = stream_id <24> elif stream.stream_type == StreamType.QPACK_ENCODER: <25> assert self._peer_encoder_stream_id is None <26> self._peer_encoder_stream_id = stream_id <27> <28> if stream_id == self._peer_control_stream_id: <29> # fetch next frame <30> try: <31> frame_type = buf.pull_uint_var() <32> frame_length = buf.pull_uint_var() <33> frame_data = buf.pull_bytes(frame_length) <34> except BufferReadError: <35> break <36> consumed = buf.tell() <37> <38> self._handle_control_frame(frame_</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: + def _receive_stream_data_uni( + self, stream_id: int, data: bytes, stream_ended: bool + ) -> List[HttpEvent]: - def _receive_stream_data_uni(self, stream_id: int, data: bytes) -> List[HttpEvent]: # offset: 1 else: # fetch unframed data data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() if stream_id == self._peer_decoder_stream_id: self._encoder.feed_decoder(data) elif stream_id == self._peer_encoder_stream_id: unblocked_streams.update(self._decoder.feed_encoder(data)) # remove processed data from buffer stream.buffer = stream.buffer[consumed:] # process unblocked streams for stream_id in unblocked_streams: stream = self._stream[stream_id] decoder, headers = self._decoder.resume_header(stream_id) stream.blocked = False cls = ResponseReceived if self._is_client else RequestReceived http_events.append( cls( headers=headers, stream_id=stream_id, stream_ended=stream.ended and not stream.buffer, ) ) http_events.extend( self._receive_stream_data_bidi(stream_id, b"", stream.ended) ) return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.h3.connection FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) at: aioquic.h3.connection.H3Connection.__init__ self._stream: Dict[int, H3Stream] = {} at: aioquic.h3.connection.H3Stream.__init__ self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None at: aioquic.h3.events HttpEvent() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: typing List = _alias(list, 1, inst=False, name='List') ===========changed ref 0=========== # module: aioquic.h3.connection + def parse_max_push_id(data: bytes) -> int: + buf = Buffer(data=data) + max_push_id = buf.pull_uint_var() + assert buf.eof() + return max_push_id + ===========changed ref 1=========== # module: aioquic.h3.connection class H3Stream: def __init__(self) -> None: self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None + self.push_id: Optional[int] = None self.stream_type: Optional[int] = None ===========changed ref 2=========== # module: aioquic.h3.connection class H3Connection: + def _handle_push_frame( + self, + frame_type: int, + frame_data: bytes, + push_id: int, + stream_id: int, + stream_ended: bool, + ) -> List[HttpEvent]: + """ + Handle a frame received on a push stream. + """ + http_events: List[HttpEvent] = [] + + if frame_type == FrameType.DATA: + http_events.append( + DataReceived( + data=frame_data, + push_id=push_id, + stream_ended=stream_ended, + stream_id=stream_id, + ) + ) + elif frame_type == FrameType.HEADERS: + headers = self._decode_headers(stream_id, frame_data) + http_events.append( + ResponseReceived( + headers=headers, + push_id=push_id, + stream_id=stream_id, + stream_ended=stream_ended, + ) + ) + elif frame_type in ( + FrameType.PRIORITY, + FrameType.CANCEL_PUSH, + FrameType.SETTINGS, + FrameType.PUSH_PROMISE, + FrameType.GOAWAY, + FrameType.MAX_PUSH_ID, + FrameType.DUPLICATE_PUSH, + ): + raise QuicConnectionError( + error_code=ErrorCode.HTTP_WRONG_STREAM, + frame_type=None, + reason_phrase="Invalid frame type on push stream", + ) + + return http_events + ===========changed ref 3=========== # module: aioquic.h3.connection class H3Connection: def _init_connection(self) -> None: # send our settings self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL) self._quic.send_stream_data( self._local_control_stream_id, encode_frame( FrameType.SETTINGS, encode_settings( { Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity, Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams, } ), ), ) + if self._is_client: + self._quic.send_stream_data( + self._local_control_stream_id, + encode_frame(FrameType.MAX_PUSH_ID, encode_uint_var(self._max_push_id)), + ) # create encoder and decoder streams self._local_encoder_stream_id = self._create_uni_stream( StreamType.QPACK_ENCODER ) self._local_decoder_stream_id = self._create_uni_stream( StreamType.QPACK_DECODER ) ===========changed ref 4=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[HttpEvent]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() if stream_id % 4 == 0: return self._receive_stream_data_bidi( stream_id, event.data, event.end_stream ) elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni(stream_id, event.data) + stream_id, event.data, event.end_stream + ) return []
tests.test_h3/h3_transfer
Modified
aiortc~aioquic
eb4fc3878387177cf3b52a94f4c63fb9c871cbcf
[http3] add initial support for server push
<1>:<add> if hasattr(quic_sender, "stream_queue"): <add> quic_receiver._events.extend(quic_sender.stream_queue) <add> quic_sender.stream_queue.clear() <add> else: <add> transfer(quic_sender, quic_receiver) <del> transfer(quic_sender, quic_receiver)
# module: tests.test_h3 def h3_transfer(quic_sender, h3_receiver): <0> quic_receiver = h3_receiver._quic <1> transfer(quic_sender, quic_receiver) <2> <3> # process QUIC events <4> http_events = [] <5> event = quic_receiver.next_event() <6> while event is not None: <7> http_events.extend(h3_receiver.handle_event(event)) <8> event = quic_receiver.next_event() <9> return http_events <10>
===========unchanged ref 0=========== at: aioquic.h3.events DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) PushPromiseReceived(headers: Headers, push_id: int, stream_id: int) RequestReceived(headers: Headers, stream_id: int, stream_ended: bool) ResponseReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_connection client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_options={}, server_patch=lambda x: None, transport_options={}) transfer(sender, receiver) ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class PushPromiseReceived(HttpEvent): + """ + The PushedStreamReceived event is fired whenever a pushed stream has been + received from the remote peer. + """ + + headers: Headers + "The request headers." + + push_id: int + "The Push ID of the push promise." + + stream_id: int + "The Stream ID of the stream that the push is related to." + ===========changed ref 1=========== # module: aioquic.h3.connection + def parse_max_push_id(data: bytes) -> int: + buf = Buffer(data=data) + max_push_id = buf.pull_uint_var() + assert buf.eof() + return max_push_id + ===========changed ref 2=========== # module: aioquic.h3.connection class H3Stream: def __init__(self) -> None: self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None + self.push_id: Optional[int] = None self.stream_type: Optional[int] = None ===========changed ref 3=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[HttpEvent]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() if stream_id % 4 == 0: return self._receive_stream_data_bidi( stream_id, event.data, event.end_stream ) elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni(stream_id, event.data) + stream_id, event.data, event.end_stream + ) return [] ===========changed ref 4=========== # module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client self._quic = quic self._decoder = Decoder(self._max_table_capacity, self._blocked_streams) self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} + + self._max_push_id: Optional[int] = 8 if self._is_client else None + self._next_push_id: int = 0 self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None self._init_connection() ===========changed ref 5=========== # module: aioquic.h3.connection class H3Connection: def _init_connection(self) -> None: # send our settings self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL) self._quic.send_stream_data( self._local_control_stream_id, encode_frame( FrameType.SETTINGS, encode_settings( { Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity, Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams, } ), ), ) + if self._is_client: + self._quic.send_stream_data( + self._local_control_stream_id, + encode_frame(FrameType.MAX_PUSH_ID, encode_uint_var(self._max_push_id)), + ) # create encoder and decoder streams self._local_encoder_stream_id = self._create_uni_stream( StreamType.QPACK_ENCODER ) self._local_decoder_stream_id = self._create_uni_stream( StreamType.QPACK_DECODER ) ===========changed ref 6=========== # module: aioquic.h3.connection class H3Connection: + def push_promise(self, stream_id: int, headers: Headers) -> int: + """ + Send a push promise related to the specified stream. + + Returns the stream ID on which headers and data can be sent. + + :param stream_id: The stream ID on which to send the data. + :param headers: The HTTP request headers for this push. + """ + assert not self._is_client, "Only servers may send a push promise." + assert self._max_push_id is not None and self._next_push_id < self._max_push_id + + # send push promise + push_id = self._next_push_id + self._next_push_id += 1 + self._quic.send_stream_data( + stream_id, + encode_frame( + FrameType.PUSH_PROMISE, + encode_uint_var(push_id) + self._encode_headers(stream_id, headers), + ), + ) + + #  create push stream + push_stream_id = self._create_uni_stream(StreamType.PUSH) + self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id)) + + return push_stream_id +
tests.test_h3/FakeQuicConnection.__init__
Modified
aiortc~aioquic
eb4fc3878387177cf3b52a94f4c63fb9c871cbcf
[http3] add initial support for server push
<2>:<add> self._events = []
# module: tests.test_h3 class FakeQuicConnection: def __init__(self, configuration): <0> self.configuration = configuration <1> self.stream_queue = [] <2> self._next_stream_bidi = 0 if configuration.is_client else 1 <3> self._next_stream_uni = 2 if configuration.is_client else 3 <4>
===========unchanged ref 0=========== at: aioquic.quic.connection.QuicConnection.__init__ self._events: Deque[events.QuicEvent] = deque() at: collections.deque extend(iterable: Iterable[_T]) -> None at: tests.test_connection transfer(sender, receiver) at: tests.test_h3.FakeQuicConnection.__init__ self.stream_queue = [] at: tests.test_h3.h3_transfer quic_receiver = h3_receiver._quic ===========changed ref 0=========== # module: tests.test_h3 def h3_transfer(quic_sender, h3_receiver): quic_receiver = h3_receiver._quic + if hasattr(quic_sender, "stream_queue"): + quic_receiver._events.extend(quic_sender.stream_queue) + quic_sender.stream_queue.clear() + else: + transfer(quic_sender, quic_receiver) - transfer(quic_sender, quic_receiver) # process QUIC events http_events = [] event = quic_receiver.next_event() while event is not None: http_events.extend(h3_receiver.handle_event(event)) event = quic_receiver.next_event() return http_events ===========changed ref 1=========== # module: aioquic.h3.connection + def parse_max_push_id(data: bytes) -> int: + buf = Buffer(data=data) + max_push_id = buf.pull_uint_var() + assert buf.eof() + return max_push_id + ===========changed ref 2=========== # module: aioquic.h3.connection class H3Stream: def __init__(self) -> None: self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None + self.push_id: Optional[int] = None self.stream_type: Optional[int] = None ===========changed ref 3=========== # module: aioquic.h3.events + @dataclass + class PushPromiseReceived(HttpEvent): + """ + The PushedStreamReceived event is fired whenever a pushed stream has been + received from the remote peer. + """ + + headers: Headers + "The request headers." + + push_id: int + "The Push ID of the push promise." + + stream_id: int + "The Stream ID of the stream that the push is related to." + ===========changed ref 4=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[HttpEvent]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() if stream_id % 4 == 0: return self._receive_stream_data_bidi( stream_id, event.data, event.end_stream ) elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni(stream_id, event.data) + stream_id, event.data, event.end_stream + ) return [] ===========changed ref 5=========== # module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client self._quic = quic self._decoder = Decoder(self._max_table_capacity, self._blocked_streams) self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} + + self._max_push_id: Optional[int] = 8 if self._is_client else None + self._next_push_id: int = 0 self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None self._init_connection() ===========changed ref 6=========== # module: aioquic.h3.connection class H3Connection: def _init_connection(self) -> None: # send our settings self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL) self._quic.send_stream_data( self._local_control_stream_id, encode_frame( FrameType.SETTINGS, encode_settings( { Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity, Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams, } ), ), ) + if self._is_client: + self._quic.send_stream_data( + self._local_control_stream_id, + encode_frame(FrameType.MAX_PUSH_ID, encode_uint_var(self._max_push_id)), + ) # create encoder and decoder streams self._local_encoder_stream_id = self._create_uni_stream( StreamType.QPACK_ENCODER ) self._local_decoder_stream_id = self._create_uni_stream( StreamType.QPACK_DECODER ) ===========changed ref 7=========== # module: aioquic.h3.connection class H3Connection: + def push_promise(self, stream_id: int, headers: Headers) -> int: + """ + Send a push promise related to the specified stream. + + Returns the stream ID on which headers and data can be sent. + + :param stream_id: The stream ID on which to send the data. + :param headers: The HTTP request headers for this push. + """ + assert not self._is_client, "Only servers may send a push promise." + assert self._max_push_id is not None and self._next_push_id < self._max_push_id + + # send push promise + push_id = self._next_push_id + self._next_push_id += 1 + self._quic.send_stream_data( + stream_id, + encode_frame( + FrameType.PUSH_PROMISE, + encode_uint_var(push_id) + self._encode_headers(stream_id, headers), + ), + ) + + #  create push stream + push_stream_id = self._create_uni_stream(StreamType.PUSH) + self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id)) + + return push_stream_id +
tests.test_h3/H3ConnectionTest._make_request
Modified
aiortc~aioquic
eb4fc3878387177cf3b52a94f4c63fb9c871cbcf
[http3] add initial support for server push
# module: tests.test_h3 class H3ConnectionTest(TestCase): def _make_request(self, h3_client, h3_server): <0> quic_client = h3_client._quic <1> quic_server = h3_server._quic <2> <3> # send request <4> stream_id = quic_client.get_next_available_stream_id() <5> h3_client.send_headers( <6> stream_id=stream_id, <7> headers=[ <8> (b":method", b"GET"), <9> (b":scheme", b"https"), <10> (b":authority", b"localhost"), <11> (b":path", b"/"), <12> (b"x-foo", b"client"), <13> ], <14> ) <15> h3_client.send_data(stream_id=stream_id, data=b"", end_stream=True) <16> <17> # receive request <18> events = h3_transfer(quic_client, h3_server) <19> self.assertEqual(len(events), 2) <20> <21> self.assertTrue(isinstance(events[0], RequestReceived)) <22> self.assertEqual( <23> events[0].headers, <24> [ <25> (b":method", b"GET"), <26> (b":scheme", b"https"), <27> (b":authority", b"localhost"), <28> (b":path", b"/"), <29> (b"x-foo", b"client"), <30> ], <31> ) <32> self.assertEqual(events[0].stream_id, stream_id) <33> self.assertEqual(events[0].stream_ended, False) <34> <35> self.assertTrue(isinstance(events[1], DataReceived)) <36> self.assertEqual(events[1].data, b"") <37> self.assertEqual(events[1].stream_id, stream_id) <38> self.assertEqual(events[1].stream_ended, True) <39> <40> # send</s>
===========below chunk 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def _make_request(self, h3_client, h3_server): # offset: 1 h3_server.send_headers( stream_id=stream_id, headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], ) h3_server.send_data( stream_id=stream_id, data=b"<html><body>hello</body></html>", end_stream=True, ) # receive response events = h3_transfer(quic_server, h3_client) self.assertEqual(len(events), 2) self.assertTrue(isinstance(events[0], ResponseReceived)) self.assertEqual( events[0].headers, [ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], ) self.assertEqual(events[0].stream_id, stream_id) self.assertEqual(events[0].stream_ended, False) self.assertTrue(isinstance(events[1], DataReceived)) self.assertEqual(events[1].data, b"<html><body>hello</body></html>") self.assertEqual(events[1].stream_id, stream_id) self.assertEqual(events[1].stream_ended, True) ===========unchanged ref 0=========== at: aioquic.h3.connection.H3Connection send_data(stream_id: int, data: bytes, end_stream: bool) -> None send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.connection.H3Connection.__init__ self._quic = quic at: aioquic.h3.events DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) RequestReceived(headers: Headers, stream_id: int, stream_ended: bool) at: aioquic.quic.connection.QuicConnection get_next_available_stream_id(is_unidirectional=False) -> int at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: aioquic.quic.events.StreamDataReceived data: bytes end_stream: bool stream_id: int at: tests.test_h3 h3_transfer(quic_sender, h3_receiver) at: tests.test_h3.FakeQuicConnection.__init__ self.stream_queue = [] self._events = [] at: tests.test_h3.FakeQuicConnection.get_next_available_stream_id stream_id = self._next_stream_bidi at: unittest.case TestCase(methodName: str=...) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None assertTrue(expr: Any, msg: Any=...) -> None failureException = AssertionError longMessage = True maxDiff = 80*8 _diffThreshold = 2**16 failUnlessEqual = assertEquals = _deprecate(assertEqual) failUnlessEqual = assertEquals = _deprecate(assertEqual) ===========unchanged ref 1=========== failIfEqual = assertNotEquals = _deprecate(assertNotEqual) failIfEqual = assertNotEquals = _deprecate(assertNotEqual) failUnlessAlmostEqual = assertAlmostEquals = _deprecate(assertAlmostEqual) failUnlessAlmostEqual = assertAlmostEquals = _deprecate(assertAlmostEqual) failIfAlmostEqual = assertNotAlmostEquals = _deprecate(assertNotAlmostEqual) failIfAlmostEqual = assertNotAlmostEquals = _deprecate(assertNotAlmostEqual) failUnless = assert_ = _deprecate(assertTrue) failUnless = assert_ = _deprecate(assertTrue) failUnlessRaises = _deprecate(assertRaises) failIf = _deprecate(assertFalse) assertRaisesRegexp = _deprecate(assertRaisesRegex) assertRegexpMatches = _deprecate(assertRegex) assertNotRegexpMatches = _deprecate(assertNotRegex) ===========changed ref 0=========== # module: tests.test_h3 def h3_transfer(quic_sender, h3_receiver): quic_receiver = h3_receiver._quic + if hasattr(quic_sender, "stream_queue"): + quic_receiver._events.extend(quic_sender.stream_queue) + quic_sender.stream_queue.clear() + else: + transfer(quic_sender, quic_receiver) - transfer(quic_sender, quic_receiver) # process QUIC events http_events = [] event = quic_receiver.next_event() while event is not None: http_events.extend(h3_receiver.handle_event(event)) event = quic_receiver.next_event() return http_events ===========changed ref 1=========== # module: tests.test_h3 class FakeQuicConnection: def __init__(self, configuration): self.configuration = configuration self.stream_queue = [] + self._events = [] self._next_stream_bidi = 0 if configuration.is_client else 1 self._next_stream_uni = 2 if configuration.is_client else 3 ===========changed ref 2=========== # module: aioquic.h3.connection + def parse_max_push_id(data: bytes) -> int: + buf = Buffer(data=data) + max_push_id = buf.pull_uint_var() + assert buf.eof() + return max_push_id + ===========changed ref 3=========== # module: aioquic.h3.connection class H3Stream: def __init__(self) -> None: self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None + self.push_id: Optional[int] = None self.stream_type: Optional[int] = None ===========changed ref 4=========== # module: aioquic.h3.events + @dataclass + class PushPromiseReceived(HttpEvent): + """ + The PushedStreamReceived event is fired whenever a pushed stream has been + received from the remote peer. + """ + + headers: Headers + "The request headers." + + push_id: int + "The Push ID of the push promise." + + stream_id: int + "The Stream ID of the stream that the push is related to." +
tests.test_h3/H3ConnectionTest.test_request_headers_only
Modified
aiortc~aioquic
eb4fc3878387177cf3b52a94f4c63fb9c871cbcf
[http3] add initial support for server push
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_headers_only(self): <0> with client_and_server( <1> client_options={"alpn_protocols": ["h3-22"]}, <2> server_options={"alpn_protocols": ["h3-22"]}, <3> ) as (quic_client, quic_server): <4> h3_client = H3Connection(quic_client) <5> h3_server = H3Connection(quic_server) <6> <7> # send request <8> stream_id = quic_client.get_next_available_stream_id() <9> h3_client.send_headers( <10> stream_id=stream_id, <11> headers=[ <12> (b":method", b"HEAD"), <13> (b":scheme", b"https"), <14> (b":authority", b"localhost"), <15> (b":path", b"/"), <16> (b"x-foo", b"client"), <17> ], <18> end_stream=True, <19> ) <20> <21> # receive request <22> events = h3_transfer(quic_client, h3_server) <23> self.assertEqual(len(events), 1) <24> <25> self.assertTrue(isinstance(events[0], RequestReceived)) <26> self.assertEqual( <27> events[0].headers, <28> [ <29> (b":method", b"HEAD"), <30> (b":scheme", b"https"), <31> (b":authority", b"localhost"), <32> (b":path", b"/"), <33> (b"x-foo", b"client"), <34> ], <35> ) <36> self.assertEqual(events[0].stream_id, stream_id) <37> self.assertEqual(events[0].stream_ended, True) <38> <39> # send response <40> h3_server.send_headers( <41> stream_id=stream_id, <42> headers=[ <43> (b</s>
===========below chunk 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_headers_only(self): # offset: 1 (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], end_stream=True, ) # receive response events = h3_transfer(quic_server, h3_client) self.assertEqual(len(events), 1) self.assertTrue(isinstance(events[0], ResponseReceived)) self.assertEqual( events[0].headers, [ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], ) self.assertEqual(events[0].stream_id, stream_id) self.assertEqual(events[0].stream_ended, True) ===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) encode_frame(frame_type: int, frame_data: bytes) -> bytes H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[HttpEvent] _handle_control_frame(frame_type: int, frame_data: bytes) -> None at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.configuration.QuicConfiguration alpn_protocols: Optional[List[str]] = None certificate: Any = None connection_id_length: int = 8 idle_timeout: float = 60.0 is_client: bool = True private_key: Any = None ===========unchanged ref 1=========== quic_logger: Optional[QuicLogger] = None secrets_log_file: TextIO = None server_name: Optional[str] = None session_ticket: Optional[SessionTicket] = None supported_versions: List[int] = field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] ) at: aioquic.quic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_connection client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_options={}, server_patch=lambda x: None, transport_options={}) at: tests.test_h3 FakeQuicConnection(configuration) at: tests.test_h3.H3ConnectionTest _make_request(h3_client, h3_server) _make_request(self, h3_client, h3_server) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E] assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None at: unittest.case._AssertRaisesContext.__exit__ self.exception = exc_value.with_traceback(None) ===========changed ref 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def _make_request(self, h3_client, h3_server): quic_client = h3_client._quic quic_server = h3_server._quic # send request stream_id = quic_client.get_next_available_stream_id() h3_client.send_headers( stream_id=stream_id, headers=[ (b":method", b"GET"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/"), (b"x-foo", b"client"), ], ) h3_client.send_data(stream_id=stream_id, data=b"", end_stream=True) # receive request events = h3_transfer(quic_client, h3_server) self.assertEqual(len(events), 2) self.assertTrue(isinstance(events[0], RequestReceived)) self.assertEqual( events[0].headers, [ (b":method", b"GET"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/"), (b"x-foo", b"client"), ], ) self.assertEqual(events[0].stream_id, stream_id) self.assertEqual(events[0].stream_ended, False) self.assertTrue(isinstance(events[1], DataReceived)) self.assertEqual(events[1].data, b"") self.assertEqual(events[1].stream_id, stream_id) self.assertEqual(events[1].stream_ended, True) # send response h3_server.send_headers( stream_id=stream_id, headers=[ (b":status", b"200"), (</s>
tests.test_h3/H3ConnectionTest.test_request_fragmented_frame
Modified
aiortc~aioquic
eb4fc3878387177cf3b52a94f4c63fb9c871cbcf
[http3] add initial support for server push
<10>:<add> # send request <del> # send headers <22>:<add> h3_client.send_data(stream_id=stream_id, data=b"hello", end_stream=True) <add> <add> # receive request <add> events = h3_transfer(quic_client, h3_server) <del> http_events = [] <23>:<del> for event in quic_client.stream_queue: <24>:<del> http_events.extend(h3_server.handle_event(event)) <25>:<del> quic_client.stream_queue.clear() <27>:<add> events, <del> http_events, <37>:<add> stream_id=stream_id, <del> stream_id=0, <39>:<add> ), <del> ) <40>:<del> ], <41>:<del> ) <42>:<del> <43>:<del> # send body <44>:<del> h3_client.send_data(stream_id=stream_id, data=b"hello", end_stream=True) <45>:<del> http_events = [] <46>:<del> for event in quic
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_fragmented_frame(self): <0> quic_client = FakeQuicConnection( <1> configuration=QuicConfiguration(is_client=True) <2> ) <3> quic_server = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=False) <5> ) <6> <7> h3_client = H3Connection(quic_client) <8> h3_server = H3Connection(quic_server) <9> <10> # send headers <11> stream_id = quic_client.get_next_available_stream_id() <12> h3_client.send_headers( <13> stream_id=stream_id, <14> headers=[ <15> (b":method", b"GET"), <16> (b":scheme", b"https"), <17> (b":authority", b"localhost"), <18> (b":path", b"/"), <19> (b"x-foo", b"client"), <20> ], <21> ) <22> http_events = [] <23> for event in quic_client.stream_queue: <24> http_events.extend(h3_server.handle_event(event)) <25> quic_client.stream_queue.clear() <26> self.assertEqual( <27> http_events, <28> [ <29> RequestReceived( <30> headers=[ <31> (b":method", b"GET"), <32> (b":scheme", b"https"), <33> (b":authority", b"localhost"), <34> (b":path", b"/"), <35> (b"x-foo", b"client"), <36> ], <37> stream_id=0, <38> stream_ended=False, <39> ) <40> ], <41> ) <42> <43> # send body <44> h3_client.send_data(stream_id=stream_id, data=b"hello", end_stream=True) <45> http_events = [] <46> for event in quic</s>
===========below chunk 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_fragmented_frame(self): # offset: 1 http_events.extend(h3_server.handle_event(event)) quic_client.stream_queue.clear() self.assertEqual( http_events, [ DataReceived(data=b"h", stream_id=0, stream_ended=False), DataReceived(data=b"e", stream_id=0, stream_ended=False), DataReceived(data=b"l", stream_id=0, stream_ended=False), DataReceived(data=b"l", stream_id=0, stream_ended=False), DataReceived(data=b"o", stream_id=0, stream_ended=False), DataReceived(data=b"", stream_id=0, stream_ended=True), ], ) ===========unchanged ref 0=========== at: aioquic.h3.connection H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.events RequestReceived(headers: Headers, stream_id: int, stream_ended: bool) ResponseReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: tests.test_h3 h3_transfer(quic_sender, h3_receiver) at: tests.test_h3.H3ConnectionTest.test_request_headers_only h3_client = H3Connection(quic_client) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None assertTrue(expr: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_h3 def h3_transfer(quic_sender, h3_receiver): quic_receiver = h3_receiver._quic + if hasattr(quic_sender, "stream_queue"): + quic_receiver._events.extend(quic_sender.stream_queue) + quic_sender.stream_queue.clear() + else: + transfer(quic_sender, quic_receiver) - transfer(quic_sender, quic_receiver) # process QUIC events http_events = [] event = quic_receiver.next_event() while event is not None: http_events.extend(h3_receiver.handle_event(event)) event = quic_receiver.next_event() return http_events ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): + def test_handle_control_frame_max_push_id_from_server(self): + """ + A client should not receive MAX_PUSH_ID on the control stream. + """ + quic_client = FakeQuicConnection( + configuration=QuicConfiguration(is_client=True) + ) + h3_client = H3Connection(quic_client) + + with self.assertRaises(QuicConnectionError) as cm: + h3_client._handle_control_frame(FrameType.MAX_PUSH_ID, encode_uint_var(0)) + self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME) + ===========changed ref 2=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): + def test_handle_control_frame_headers(self): + """ + We should not receive HEADERS on the control stream. + """ + quic_server = FakeQuicConnection( + configuration=QuicConfiguration(is_client=False) + ) + h3_server = H3Connection(quic_server) + + with self.assertRaises(QuicConnectionError) as cm: + h3_server._handle_control_frame(FrameType.HEADERS, b"") + self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) + ===========changed ref 3=========== # module: tests.test_h3 class FakeQuicConnection: + def next_event(self): + try: + return self._events.pop(0) + except IndexError: + return None + ===========changed ref 4=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): + def test_handle_push_frame_wrong_frame_type(self): + quic_client = FakeQuicConnection( + configuration=QuicConfiguration(is_client=True) + ) + h3_client = H3Connection(quic_client) + + with self.assertRaises(QuicConnectionError) as cm: + h3_client.handle_event( + StreamDataReceived( + stream_id=15, + data=encode_uint_var(StreamType.PUSH) + + encode_uint_var(0) # push ID + + encode_frame(FrameType.SETTINGS, b""), + end_stream=False, + ) + ) + self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) + ===========changed ref 5=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): - def test_handle_control_frame_wrong_frame_type(self): - quic_server = FakeQuicConnection( - configuration=QuicConfiguration(is_client=False) - ) - h3_server = H3Connection(quic_server) - - with self.assertRaises(QuicConnectionError) as cm: - h3_server._handle_control_frame(FrameType.HEADERS, b"") - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) - ===========changed ref 6=========== # module: tests.test_h3 class FakeQuicConnection: def __init__(self, configuration): self.configuration = configuration self.stream_queue = [] + self._events = [] self._next_stream_bidi = 0 if configuration.is_client else 1 self._next_stream_uni = 2 if configuration.is_client else 3
aioquic.h3.connection/H3Connection._receive_stream_data_uni
Modified
aiortc~aioquic
e48f62850cdb0033065dea3657a5dfe7d68e1bf1
[http3] explicity key off stream type for uni streams
<20>:<add> # check unicity <30>:<add> if stream.stream_type == StreamType.CONTROL: <del> if stream_id == self._peer_control_stream_id:
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: <0> http_events: List[HttpEvent] = [] <1> <2> stream = self._stream[stream_id] <3> stream.buffer += data <4> if stream_ended: <5> stream.ended = True <6> <7> buf = Buffer(data=stream.buffer) <8> consumed = 0 <9> unblocked_streams: Set[int] = set() <10> <11> while not buf.eof(): <12> # fetch stream type for unidirectional streams <13> if stream.stream_type is None: <14> try: <15> stream.stream_type = buf.pull_uint_var() <16> except BufferReadError: <17> break <18> consumed = buf.tell() <19> <20> if stream.stream_type == StreamType.CONTROL: <21> assert self._peer_control_stream_id is None <22> self._peer_control_stream_id = stream_id <23> elif stream.stream_type == StreamType.QPACK_DECODER: <24> assert self._peer_decoder_stream_id is None <25> self._peer_decoder_stream_id = stream_id <26> elif stream.stream_type == StreamType.QPACK_ENCODER: <27> assert self._peer_encoder_stream_id is None <28> self._peer_encoder_stream_id = stream_id <29> <30> if stream_id == self._peer_control_stream_id: <31> # fetch next frame <32> try: <33> frame_type = buf.pull_uint_var() <34> frame_length = buf.pull_uint_var() <35> frame_data = buf.pull_bytes(frame_length) <36> except BufferReadError: <37> break <38> consumed = buf.tell() <39> <40> self._handle_control_frame(frame_type, frame_data) <41> elif stream.stream_type == StreamType.</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: # offset: 1 # fetch push id if stream.push_id is None: try: stream.push_id = buf.pull_uint_var() except BufferReadError: break consumed = buf.tell() # fetch next frame try: frame_type = buf.pull_uint_var() frame_length = buf.pull_uint_var() frame_data = buf.pull_bytes(frame_length) except BufferReadError: break consumed = buf.tell() http_events.extend( self._handle_push_frame( frame_type=frame_type, frame_data=frame_data, push_id=stream.push_id, stream_id=stream_id, stream_ended=stream.ended and buf.eof(), ) ) else: # fetch unframed data data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() if stream_id == self._peer_decoder_stream_id: self._encoder.feed_decoder(data) elif stream_id == self._peer_encoder_stream_id: unblocked_streams.update(self._decoder.feed_encoder(data)) # remove processed data from buffer stream.buffer = stream.buffer[consumed:] # process unblocked streams for stream_id in unblocked_streams: stream = self._stream[stream_id] decoder, headers = self._decoder.resume_header(stream_id) stream.blocked = False cls = ResponseReceived if self._is_client else RequestReceived http_events.append( cls( headers=headers, stream_id=stream_id, stream_ended=stream.</s> ===========below chunk 1=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: # offset: 2 <s>append( cls( headers=headers, stream_id=stream_id, stream_ended=stream.ended and not stream.buffer, ) ) http_events.extend( self._receive_stream_data_bidi(stream_id, b"", stream.ended) ) return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.h3.connection StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) at: aioquic.h3.connection.H3Connection _handle_control_frame(frame_type: int, frame_data: bytes) -> None _handle_push_frame(frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[HttpEvent] at: aioquic.h3.connection.H3Connection.__init__ self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None at: aioquic.h3.connection.H3Stream.__init__ self.buffer = b"" self.ended = False self.push_id: Optional[int] = None self.stream_type: Optional[int] = None at: aioquic.h3.events HttpEvent() RequestReceived(headers: Headers, stream_id: int, stream_ended: bool) ResponseReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: typing List = _alias(list, 1, inst=False, name='List') ===========unchanged ref 1=========== Set = _alias(set, 1, inst=False, name='Set')
aioquic.h3.connection/H3Connection._receive_stream_data_bidi
Modified
aiortc~aioquic
8d579b2864f8d3fae34438390ba2efd220e45b4c
[http3] raise an exception if server receives a PUSH_PROMISE
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: <0> """ <1> Client-initiated bidirectional streams carry requests and responses. <2> """ <3> http_events: List[HttpEvent] = [] <4> <5> stream = self._stream[stream_id] <6> stream.buffer += data <7> if stream_ended: <8> stream.ended = True <9> if stream.blocked: <10> return http_events <11> <12> # shortcut DATA frame bits <13> if ( <14> stream.frame_type == FrameType.DATA <15> and stream.frame_size is not None <16> and len(stream.buffer) < stream.frame_size <17> ): <18> http_events.append( <19> DataReceived( <20> data=stream.buffer, stream_id=stream_id, stream_ended=False <21> ) <22> ) <23> stream.frame_size -= len(stream.buffer) <24> stream.buffer = b"" <25> return http_events <26> <27> # some peers (e.g. f5) end the stream with no data <28> if stream_ended and not stream.buffer: <29> http_events.append( <30> DataReceived(data=b"", stream_id=stream_id, stream_ended=True) <31> ) <32> return http_events <33> <34> buf = Buffer(data=stream.buffer) <35> consumed = 0 <36> <37> while not buf.eof(): <38> # fetch next frame header <39> if stream.frame_size is None: <40> try: <41> stream.frame_type = buf.pull_uint_var() <42> stream.frame_size = buf.pull_uint_var() <43> except BufferReadError: <44> break <45> consumed = buf.tell() <46> <47> # check how much data is available <48> chunk_size = min(stream.frame_size, buf.capacity - consumed</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: # offset: 1 if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size: break # read available data frame_data = buf.pull_bytes(chunk_size) consumed = buf.tell() # detect end of frame stream.frame_size -= chunk_size if not stream.frame_size: stream.frame_size = None if stream.frame_type == FrameType.DATA and (stream_ended or frame_data): http_events.append( DataReceived( data=frame_data, stream_id=stream_id, stream_ended=stream_ended and buf.eof(), ) ) elif stream.frame_type == FrameType.HEADERS: try: headers = self._decode_headers(stream_id, frame_data) except StreamBlocked: stream.blocked = True break cls = ResponseReceived if self._is_client else RequestReceived http_events.append( cls( headers=headers, stream_id=stream_id, stream_ended=stream_ended and buf.eof(), ) ) elif stream.frame_type == FrameType.PUSH_PROMISE: frame_buf = Buffer(data=frame_data) push_id = frame_buf.pull_uint_var() headers = self._decode_headers( stream_id, frame_data[frame_buf.tell() :] ) http_events.append( PushPromiseReceived( headers=headers, push_id=push_id, stream_id=stream_id ) ) elif stream.frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.GOAW</s> ===========below chunk 1=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: # offset: 2 <s> FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on request stream", ) # remove processed data from buffer stream.buffer = stream.buffer[consumed:] return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) at: aioquic.h3.connection.H3Connection _decode_headers(stream_id: int, frame_data: bytes) -> Headers at: aioquic.h3.connection.H3Connection.__init__ self._is_client = quic.configuration.is_client self._stream: Dict[int, H3Stream] = {} at: aioquic.h3.connection.H3Stream.__init__ self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None at: aioquic.h3.events HttpEvent() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) PushPromiseReceived(headers: Headers, push_id: int, stream_id: int) RequestReceived(headers: Headers, stream_id: int, stream_ended: bool) ResponseReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.h3.events.DataReceived data: bytes stream_id: int ===========unchanged ref 1=========== stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.RequestReceived headers: Headers stream_id: int stream_ended: bool at: aioquic.h3.events.ResponseReceived headers: Headers stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.quic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) at: typing List = _alias(list, 1, inst=False, name='List')
tests.test_h3/H3ConnectionTest._make_request
Modified
aiortc~aioquic
cbaebd25666112b8771f6511547385a2696f65bb
[tests] refactor http3 tests
<19>:<del> self.assertEqual(len(events), 2) <20>:<del> <21>:<del> self.assertTrue(isinstance(events[0], RequestReceived)) <23>:<add> events, <del> events[0].headers, <25>:<add> RequestReceived( <add> headers=[ <add> (b":method", b"GET"), <del> (b":method", b"GET"), <26>:<add> (b":scheme", b"https"), <del> (b":scheme", b"https"), <27>:<add> (b":authority", b"localhost"), <del> (b":authority", b"localhost"), <28>:<add> (b":path", b"/"), <del> (b":path", b"/"), <29>:<add> (b"x-foo", b"client"), <del> (b"x-foo", b"client"), <30>:<add> ], <add> stream_id=stream_id, <add> stream_ended=False, <add> ), <add> DataReceived(data=b"", stream_id=stream_id, stream_ended=True), <32>:<del> self.assertEqual(events[0].stream_id, stream_id) <33>:<del> self.assertEqual(events[0].stream_ended, False) <34>:<del> <35>:<del> self.assertTrue(isinstance(events[1], DataReceived)) <36>:<del> self.assertEqual(events[1].data, b"") <37>:<del> self.assertEqual(events[1].stream_id, stream_id) <38>:<del> self.assertEqual(events[1].stream_ended, True)
# module: tests.test_h3 class H3ConnectionTest(TestCase): def _make_request(self, h3_client, h3_server): <0> quic_client = h3_client._quic <1> quic_server = h3_server._quic <2> <3> # send request <4> stream_id = quic_client.get_next_available_stream_id() <5> h3_client.send_headers( <6> stream_id=stream_id, <7> headers=[ <8> (b":method", b"GET"), <9> (b":scheme", b"https"), <10> (b":authority", b"localhost"), <11> (b":path", b"/"), <12> (b"x-foo", b"client"), <13> ], <14> ) <15> h3_client.send_data(stream_id=stream_id, data=b"", end_stream=True) <16> <17> # receive request <18> events = h3_transfer(quic_client, h3_server) <19> self.assertEqual(len(events), 2) <20> <21> self.assertTrue(isinstance(events[0], RequestReceived)) <22> self.assertEqual( <23> events[0].headers, <24> [ <25> (b":method", b"GET"), <26> (b":scheme", b"https"), <27> (b":authority", b"localhost"), <28> (b":path", b"/"), <29> (b"x-foo", b"client"), <30> ], <31> ) <32> self.assertEqual(events[0].stream_id, stream_id) <33> self.assertEqual(events[0].stream_ended, False) <34> <35> self.assertTrue(isinstance(events[1], DataReceived)) <36> self.assertEqual(events[1].data, b"") <37> self.assertEqual(events[1].stream_id, stream_id) <38> self.assertEqual(events[1].stream_ended, True) <39> <40> # send</s>
===========below chunk 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def _make_request(self, h3_client, h3_server): # offset: 1 h3_server.send_headers( stream_id=stream_id, headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], ) h3_server.send_data( stream_id=stream_id, data=b"<html><body>hello</body></html>", end_stream=True, ) # receive response events = h3_transfer(quic_server, h3_client) self.assertEqual(len(events), 2) self.assertTrue(isinstance(events[0], ResponseReceived)) self.assertEqual( events[0].headers, [ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], ) self.assertEqual(events[0].push_id, None) self.assertEqual(events[0].stream_id, stream_id) self.assertEqual(events[0].stream_ended, False) self.assertTrue(isinstance(events[1], DataReceived)) self.assertEqual(events[1].data, b"<html><body>hello</body></html>") self.assertEqual(events[1].push_id, None) self.assertEqual(events[1].stream_id, stream_id) self.assertEqual(events[1].stream_ended, True) ===========unchanged ref 0=========== at: aioquic.h3.connection.H3Connection send_data(stream_id: int, data: bytes, end_stream: bool) -> None send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.connection.H3Connection.__init__ self._quic = quic at: aioquic.h3.events DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) RequestReceived(headers: Headers, stream_id: int, stream_ended: bool) ResponseReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.h3.events.DataReceived data: bytes stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.RequestReceived headers: Headers stream_id: int stream_ended: bool at: aioquic.h3.events.ResponseReceived headers: Headers stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.quic.connection.QuicConnection get_next_available_stream_id(is_unidirectional=False) -> int at: tests.test_h3 h3_transfer(quic_sender, h3_receiver) at: tests.test_h3.H3ConnectionTest maxDiff = None at: unittest.case.TestCase failureException: Type[BaseException] longMessage: bool maxDiff: Optional[int] _testMethodName: str _testMethodDoc: str assertEqual(first: Any, second: Any, msg: Any=...) -> None
tests.test_h3/H3ConnectionTest.test_request_headers_only
Modified
aiortc~aioquic
cbaebd25666112b8771f6511547385a2696f65bb
[tests] refactor http3 tests
<23>:<del> self.assertEqual(len(events), 1) <24>:<del> <25>:<del> self.assertTrue(isinstance(events[0], RequestReceived)) <27>:<add> events, <del> events[0].headers, <29>:<add> RequestReceived( <add> headers=[ <add> (b":method", b"HEAD"), <del> (b":method", b"HEAD"), <30>:<add> (b":scheme", b"https"), <del> (b":scheme", b"https"), <31>:<add> (b":authority", b"localhost"), <del> (b":authority", b"localhost"), <32>:<add> (b":path", b"/"), <del> (b":path", b"/"), <33>:<add> (b"x-foo", b"client"), <del> (b"x-foo", b"client"), <34>:<add> ], <add> stream_id=stream_id, <add> stream_ended=True, <add> ) <36>:<del> self.assertEqual(events[0].stream_id, stream_id) <37>:<del> self.assertEqual(events[0].stream_ended, True)
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_headers_only(self): <0> with client_and_server( <1> client_options={"alpn_protocols": ["h3-22"]}, <2> server_options={"alpn_protocols": ["h3-22"]}, <3> ) as (quic_client, quic_server): <4> h3_client = H3Connection(quic_client) <5> h3_server = H3Connection(quic_server) <6> <7> # send request <8> stream_id = quic_client.get_next_available_stream_id() <9> h3_client.send_headers( <10> stream_id=stream_id, <11> headers=[ <12> (b":method", b"HEAD"), <13> (b":scheme", b"https"), <14> (b":authority", b"localhost"), <15> (b":path", b"/"), <16> (b"x-foo", b"client"), <17> ], <18> end_stream=True, <19> ) <20> <21> # receive request <22> events = h3_transfer(quic_client, h3_server) <23> self.assertEqual(len(events), 1) <24> <25> self.assertTrue(isinstance(events[0], RequestReceived)) <26> self.assertEqual( <27> events[0].headers, <28> [ <29> (b":method", b"HEAD"), <30> (b":scheme", b"https"), <31> (b":authority", b"localhost"), <32> (b":path", b"/"), <33> (b"x-foo", b"client"), <34> ], <35> ) <36> self.assertEqual(events[0].stream_id, stream_id) <37> self.assertEqual(events[0].stream_ended, True) <38> <39> # send response <40> h3_server.send_headers( <41> stream_id=stream_id, <42> headers=[ <43> (b</s>
===========below chunk 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_headers_only(self): # offset: 1 (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], end_stream=True, ) # receive response events = h3_transfer(quic_server, h3_client) self.assertEqual(len(events), 1) self.assertTrue(isinstance(events[0], ResponseReceived)) self.assertEqual( events[0].headers, [ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], ) self.assertEqual(events[0].push_id, None) self.assertEqual(events[0].stream_id, stream_id) self.assertEqual(events[0].stream_ended, True) ===========unchanged ref 0=========== at: aioquic.h3.connection H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.events RequestReceived(headers: Headers, stream_id: int, stream_ended: bool) ResponseReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: tests.test_h3 h3_transfer(quic_sender, h3_receiver) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None assertTrue(expr: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def _make_request(self, h3_client, h3_server): quic_client = h3_client._quic quic_server = h3_server._quic # send request stream_id = quic_client.get_next_available_stream_id() h3_client.send_headers( stream_id=stream_id, headers=[ (b":method", b"GET"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/"), (b"x-foo", b"client"), ], ) h3_client.send_data(stream_id=stream_id, data=b"", end_stream=True) # receive request events = h3_transfer(quic_client, h3_server) - self.assertEqual(len(events), 2) - - self.assertTrue(isinstance(events[0], RequestReceived)) self.assertEqual( + events, - events[0].headers, [ + RequestReceived( + headers=[ + (b":method", b"GET"), - (b":method", b"GET"), + (b":scheme", b"https"), - (b":scheme", b"https"), + (b":authority", b"localhost"), - (b":authority", b"localhost"), + (b":path", b"/"), - (b":path", b"/"), + (b"x-foo", b"client"), - (b"x-foo", b"client"), + ], + stream_id=stream_id, + stream_ended=False, + ), + DataReceived(data=b"", stream_id=stream_id, stream_ended=True), ], ) - self.assert</s> ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def _make_request(self, h3_client, h3_server): # offset: 1 <s>b"", stream_id=stream_id, stream_ended=True), ], ) - self.assertEqual(events[0].stream_id, stream_id) - self.assertEqual(events[0].stream_ended, False) - - self.assertTrue(isinstance(events[1], DataReceived)) - self.assertEqual(events[1].data, b"") - self.assertEqual(events[1].stream_id, stream_id) - self.assertEqual(events[1].stream_ended, True) # send response h3_server.send_headers( stream_id=stream_id, headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], ) h3_server.send_data( stream_id=stream_id, data=b"<html><body>hello</body></html>", end_stream=True, ) # receive response events = h3_transfer(quic_server, h3_client) - self.assertEqual(len(events), 2) - - self.assertTrue(isinstance(events[0], ResponseReceived)) self.assertEqual( + events, - events[0].headers, [ + ResponseReceived( + headers=[ + (b":status", b"200"), - (b":status", b"200"), + (b"content-type", b"text/html; charset=utf-8"), - (b"content-type", b"text/html; charset</s> ===========changed ref 2=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def _make_request(self, h3_client, h3_server): # offset: 2 <s>-8"), + (b"x-foo", b"server"), - (b"x-foo", b"server"), + ], + stream_id=stream_id, + stream_ended=False, + ), + DataReceived( + data=b"<html><body>hello</body></html>", + stream_id=stream_id, + stream_ended=True, + ), ], ) - self.assertEqual(events[0].push_id, None) - self.assertEqual(events[0].stream_id, stream_id) - self.assertEqual(events[0].stream_ended, False) - self.assertTrue(isinstance(events[1], DataReceived)) - self.assertEqual(events[1].data, b"<html><body>hello</body></html>") - self.assertEqual(events[1].push_id, None) - self.assertEqual(events[1].stream_id, stream_id) - self.assertEqual(events[1].stream_ended, True) -
aioquic.h0.connection/H0Connection.handle_event
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
<7>:<add> HeadersReceived( <del> ResponseReceived( <14>:<add> HeadersReceived( <del> RequestReceived(
# module: aioquic.h0.connection class H0Connection: def handle_event(self, event: QuicEvent) -> List[HttpEvent]: <0> http_events: List[HttpEvent] = [] <1> <2> if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0: <3> data = event.data <4> if not self._headers_received.get(event.stream_id, False): <5> if self._is_client: <6> http_events.append( <7> ResponseReceived( <8> headers=[], stream_ended=False, stream_id=event.stream_id <9> ) <10> ) <11> else: <12> method, path = data.rstrip().split(b" ", 1) <13> http_events.append( <14> RequestReceived( <15> headers=[(b":method", method), (b":path", path)], <16> stream_ended=False, <17> stream_id=event.stream_id, <18> ) <19> ) <20> data = b"" <21> self._headers_received[event.stream_id] = True <22> <23> http_events.append( <24> DataReceived( <25> data=data, stream_ended=event.end_stream, stream_id=event.stream_id <26> ) <27> ) <28> <29> return http_events <30>
===========unchanged ref 0=========== at: aioquic.h0.connection.H0Connection.__init__ self._headers_received: Dict[int, bool] = {} self._is_client = quic.configuration.is_client self._quic = quic at: aioquic.h0.connection.H0Connection.handle_event http_events: List[HttpEvent] = [] at: aioquic.h3.events Headers = List[Tuple[bytes, bytes]] DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.h3.events.DataReceived data: bytes stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.HeadersReceived headers: Headers stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.quic.connection.QuicConnection send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 1=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 2=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - ===========changed ref 3=========== # module: aioquic.h3.events - @dataclass - class ResponseReceived(HttpEvent): - """ - The ResponseReceived event is fired whenever response headers are received. - """ - - headers: Headers - "The response headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - - push_id: Optional[int] = None - "The Push ID or `None` if this is not a push." -
tests.test_h0/H0ConnectionTest.test_connect
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
<24>:<add> self.assertTrue(isinstance(events[0], HeadersReceived)) <del> self.assertTrue(isinstance(events[0], RequestReceived))
# module: tests.test_h0 class H0ConnectionTest(TestCase): def test_connect(self): <0> with client_and_server( <1> client_options={"alpn_protocols": ["hq-22"]}, <2> server_options={"alpn_protocols": ["hq-22"]}, <3> ) as (quic_client, quic_server): <4> h0_client = H0Connection(quic_client) <5> h0_server = H0Connection(quic_server) <6> <7> # send request <8> stream_id = quic_client.get_next_available_stream_id() <9> h0_client.send_headers( <10> stream_id=stream_id, <11> headers=[ <12> (b":method", b"GET"), <13> (b":scheme", b"https"), <14> (b":authority", b"localhost"), <15> (b":path", b"/"), <16> ], <17> ) <18> h0_client.send_data(stream_id=stream_id, data=b"", end_stream=True) <19> <20> # receive request <21> events = h0_transfer(quic_client, h0_server) <22> self.assertEqual(len(events), 2) <23> <24> self.assertTrue(isinstance(events[0], RequestReceived)) <25> self.assertEqual( <26> events[0].headers, [(b":method", b"GET"), (b":path", b"/")] <27> ) <28> self.assertEqual(events[0].stream_id, stream_id) <29> self.assertEqual(events[0].stream_ended, False) <30> <31> self.assertTrue(isinstance(events[1], DataReceived)) <32> self.assertEqual(events[1].data, b"") <33> self.assertEqual(events[1].stream_id, stream_id) <34> self.assertEqual(events[1].stream_ended, True) <35> <36> # send response <37> h0_server.send_</s>
===========below chunk 0=========== # module: tests.test_h0 class H0ConnectionTest(TestCase): def test_connect(self): # offset: 1 stream_id=stream_id, headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), ], ) h0_server.send_data( stream_id=stream_id, data=b"<html><body>hello</body></html>", end_stream=True, ) # receive response events = h0_transfer(quic_server, h0_client) self.assertEqual(len(events), 2) self.assertTrue(isinstance(events[0], ResponseReceived)) self.assertEqual(events[0].headers, []) self.assertEqual(events[0].stream_id, stream_id) self.assertEqual(events[0].stream_ended, False) self.assertTrue(isinstance(events[1], DataReceived)) self.assertEqual(events[1].data, b"<html><body>hello</body></html>") self.assertEqual(events[1].stream_id, stream_id) self.assertEqual(events[1].stream_ended, True) ===========unchanged ref 0=========== at: aioquic.h0.connection H0Connection(quic: QuicConnection) at: aioquic.h0.connection.H0Connection send_data(stream_id: int, data: bytes, end_stream: bool) -> None send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.events DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: tests.test_connection client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_options={}, server_patch=lambda x: None, transport_options={}) at: tests.test_h0 h0_transfer(quic_sender, h0_receiver) at: unittest.case.TestCase failureException: Type[BaseException] longMessage: bool maxDiff: Optional[int] _testMethodName: str _testMethodDoc: str assertEqual(first: Any, second: Any, msg: Any=...) -> None assertTrue(expr: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 1=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 2=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - ===========changed ref 3=========== # module: aioquic.h3.events - @dataclass - class ResponseReceived(HttpEvent): - """ - The ResponseReceived event is fired whenever response headers are received. - """ - - headers: Headers - "The response headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - - push_id: Optional[int] = None - "The Push ID or `None` if this is not a push." - ===========changed ref 4=========== # module: aioquic.h0.connection class H0Connection: def handle_event(self, event: QuicEvent) -> List[HttpEvent]: http_events: List[HttpEvent] = [] if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0: data = event.data if not self._headers_received.get(event.stream_id, False): if self._is_client: http_events.append( + HeadersReceived( - ResponseReceived( headers=[], stream_ended=False, stream_id=event.stream_id ) ) else: method, path = data.rstrip().split(b" ", 1) http_events.append( + HeadersReceived( - RequestReceived( headers=[(b":method", method), (b":path", path)], stream_ended=False, stream_id=event.stream_id, ) ) data = b"" self._headers_received[event.stream_id] = True http_events.append( DataReceived( data=data, stream_ended=event.end_stream, stream_id=event.stream_id ) ) return http_events
tests.test_h0/H0ConnectionTest.test_headers_only
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
<24>:<add> self.assertTrue(isinstance(events[0], HeadersReceived)) <del> self.assertTrue(isinstance(events[0], RequestReceived))
# module: tests.test_h0 class H0ConnectionTest(TestCase): def test_headers_only(self): <0> with client_and_server( <1> client_options={"alpn_protocols": ["hq-22"]}, <2> server_options={"alpn_protocols": ["hq-22"]}, <3> ) as (quic_client, quic_server): <4> h0_client = H0Connection(quic_client) <5> h0_server = H0Connection(quic_server) <6> <7> # send request <8> stream_id = quic_client.get_next_available_stream_id() <9> h0_client.send_headers( <10> stream_id=stream_id, <11> headers=[ <12> (b":method", b"HEAD"), <13> (b":scheme", b"https"), <14> (b":authority", b"localhost"), <15> (b":path", b"/"), <16> ], <17> end_stream=True, <18> ) <19> <20> # receive request <21> events = h0_transfer(quic_client, h0_server) <22> self.assertEqual(len(events), 2) <23> <24> self.assertTrue(isinstance(events[0], RequestReceived)) <25> self.assertEqual( <26> events[0].headers, [(b":method", b"HEAD"), (b":path", b"/")] <27> ) <28> self.assertEqual(events[0].stream_id, stream_id) <29> self.assertEqual(events[0].stream_ended, False) <30> <31> self.assertTrue(isinstance(events[1], DataReceived)) <32> self.assertEqual(events[1].data, b"") <33> self.assertEqual(events[1].stream_id, stream_id) <34> self.assertEqual(events[1].stream_ended, True) <35> <36> # send response <37> h0_server.send_headers( <38> stream_id=stream_id, <39> headers=[ <40> </s>
===========below chunk 0=========== # module: tests.test_h0 class H0ConnectionTest(TestCase): def test_headers_only(self): # offset: 1 (b"content-type", b"text/html; charset=utf-8"), ], end_stream=True, ) # receive response events = h0_transfer(quic_server, h0_client) self.assertEqual(len(events), 2) self.assertTrue(isinstance(events[0], ResponseReceived)) self.assertEqual(events[0].headers, []) self.assertEqual(events[0].stream_id, stream_id) self.assertEqual(events[0].stream_ended, False) self.assertTrue(isinstance(events[1], DataReceived)) self.assertEqual(events[1].data, b"") self.assertEqual(events[1].stream_id, stream_id) self.assertEqual(events[1].stream_ended, True) ===========unchanged ref 0=========== at: aioquic.h0.connection H0Connection(quic: QuicConnection) at: aioquic.h0.connection.H0Connection send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.events DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: tests.test_connection client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_options={}, server_patch=lambda x: None, transport_options={}) at: tests.test_h0 h0_transfer(quic_sender, h0_receiver) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None assertTrue(expr: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 1=========== # module: tests.test_h0 class H0ConnectionTest(TestCase): def test_connect(self): with client_and_server( client_options={"alpn_protocols": ["hq-22"]}, server_options={"alpn_protocols": ["hq-22"]}, ) as (quic_client, quic_server): h0_client = H0Connection(quic_client) h0_server = H0Connection(quic_server) # send request stream_id = quic_client.get_next_available_stream_id() h0_client.send_headers( stream_id=stream_id, headers=[ (b":method", b"GET"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/"), ], ) h0_client.send_data(stream_id=stream_id, data=b"", end_stream=True) # receive request events = h0_transfer(quic_client, h0_server) self.assertEqual(len(events), 2) + self.assertTrue(isinstance(events[0], HeadersReceived)) - self.assertTrue(isinstance(events[0], RequestReceived)) self.assertEqual( events[0].headers, [(b":method", b"GET"), (b":path", b"/")] ) self.assertEqual(events[0].stream_id, stream_id) self.assertEqual(events[0].stream_ended, False) self.assertTrue(isinstance(events[1], DataReceived)) self.assertEqual(events[1].data, b"") self.assertEqual(events[1].stream_id, stream_id) self.assertEqual(events[1].stream_ended, True) # send response h0_server.send_headers( stream_id=stream_id, headers=[ (</s> ===========changed ref 2=========== # module: tests.test_h0 class H0ConnectionTest(TestCase): def test_connect(self): # offset: 1 <s> send response h0_server.send_headers( stream_id=stream_id, headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), ], ) h0_server.send_data( stream_id=stream_id, data=b"<html><body>hello</body></html>", end_stream=True, ) # receive response events = h0_transfer(quic_server, h0_client) self.assertEqual(len(events), 2) + self.assertTrue(isinstance(events[0], HeadersReceived)) - self.assertTrue(isinstance(events[0], ResponseReceived)) self.assertEqual(events[0].headers, []) self.assertEqual(events[0].stream_id, stream_id) self.assertEqual(events[0].stream_ended, False) self.assertTrue(isinstance(events[1], DataReceived)) self.assertEqual(events[1].data, b"<html><body>hello</body></html>") self.assertEqual(events[1].stream_id, stream_id) self.assertEqual(events[1].stream_ended, True) ===========changed ref 3=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 4=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - ===========changed ref 5=========== # module: aioquic.h3.events - @dataclass - class ResponseReceived(HttpEvent): - """ - The ResponseReceived event is fired whenever response headers are received. - """ - - headers: Headers - "The response headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - - push_id: Optional[int] = None - "The Push ID or `None` if this is not a push." -
aioquic.h3.connection/H3Connection._handle_push_frame
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
<17>:<add> HeadersReceived( <del> ResponseReceived(
# module: aioquic.h3.connection class H3Connection: def _handle_push_frame( self, frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool, ) -> List[HttpEvent]: <0> """ <1> Handle a frame received on a push stream. <2> """ <3> http_events: List[HttpEvent] = [] <4> <5> if frame_type == FrameType.DATA: <6> http_events.append( <7> DataReceived( <8> data=frame_data, <9> push_id=push_id, <10> stream_ended=stream_ended, <11> stream_id=stream_id, <12> ) <13> ) <14> elif frame_type == FrameType.HEADERS: <15> headers = self._decode_headers(stream_id, frame_data) <16> http_events.append( <17> ResponseReceived( <18> headers=headers, <19> push_id=push_id, <20> stream_id=stream_id, <21> stream_ended=stream_ended, <22> ) <23> ) <24> elif frame_type in ( <25> FrameType.PRIORITY, <26> FrameType.CANCEL_PUSH, <27> FrameType.SETTINGS, <28> FrameType.PUSH_PROMISE, <29> FrameType.GOAWAY, <30> FrameType.MAX_PUSH_ID, <31> FrameType.DUPLICATE_PUSH, <32> ): <33> raise QuicConnectionError( <34> error_code=ErrorCode.HTTP_WRONG_STREAM, <35> frame_type=None, <36> reason_phrase="Invalid frame type on push stream", <37> ) <38> <39> return http_events <40>
===========unchanged ref 0=========== at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) at: aioquic.h3.connection.H3Connection _decode_headers(stream_id: int, frame_data: bytes) -> Headers at: aioquic.h3.events HttpEvent() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.h3.events.DataReceived data: bytes stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.HeadersReceived headers: Headers stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.quic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) at: typing List = _alias(list, 1, inst=False, name='List') ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 1=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 2=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - ===========changed ref 3=========== # module: aioquic.h3.events - @dataclass - class ResponseReceived(HttpEvent): - """ - The ResponseReceived event is fired whenever response headers are received. - """ - - headers: Headers - "The response headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - - push_id: Optional[int] = None - "The Push ID or `None` if this is not a push." - ===========changed ref 4=========== # module: aioquic.h0.connection class H0Connection: def handle_event(self, event: QuicEvent) -> List[HttpEvent]: http_events: List[HttpEvent] = [] if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0: data = event.data if not self._headers_received.get(event.stream_id, False): if self._is_client: http_events.append( + HeadersReceived( - ResponseReceived( headers=[], stream_ended=False, stream_id=event.stream_id ) ) else: method, path = data.rstrip().split(b" ", 1) http_events.append( + HeadersReceived( - RequestReceived( headers=[(b":method", method), (b":path", path)], stream_ended=False, stream_id=event.stream_id, ) ) data = b"" self._headers_received[event.stream_id] = True http_events.append( DataReceived( data=data, stream_ended=event.end_stream, stream_id=event.stream_id ) ) return http_events ===========changed ref 5=========== # module: tests.test_h0 class H0ConnectionTest(TestCase): def test_headers_only(self): with client_and_server( client_options={"alpn_protocols": ["hq-22"]}, server_options={"alpn_protocols": ["hq-22"]}, ) as (quic_client, quic_server): h0_client = H0Connection(quic_client) h0_server = H0Connection(quic_server) # send request stream_id = quic_client.get_next_available_stream_id() h0_client.send_headers( stream_id=stream_id, headers=[ (b":method", b"HEAD"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/"), ], end_stream=True, ) # receive request events = h0_transfer(quic_client, h0_server) self.assertEqual(len(events), 2) + self.assertTrue(isinstance(events[0], HeadersReceived)) - self.assertTrue(isinstance(events[0], RequestReceived)) self.assertEqual( events[0].headers, [(b":method", b"HEAD"), (b":path", b"/")] ) self.assertEqual(events[0].stream_id, stream_id) self.assertEqual(events[0].stream_ended, False) self.assertTrue(isinstance(events[1], DataReceived)) self.assertEqual(events[1].data, b"") self.assertEqual(events[1].stream_id, stream_id) self.assertEqual(events[1].stream_ended, True) # send response h0_server.send_headers( stream_id=stream_id, headers=[ (b":status", b"200"), (b"content-type", b"</s> ===========changed ref 6=========== # module: tests.test_h0 class H0ConnectionTest(TestCase): def test_headers_only(self): # offset: 1 <s>_id, headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), ], end_stream=True, ) # receive response events = h0_transfer(quic_server, h0_client) self.assertEqual(len(events), 2) + self.assertTrue(isinstance(events[0], HeadersReceived)) - self.assertTrue(isinstance(events[0], ResponseReceived)) self.assertEqual(events[0].headers, []) self.assertEqual(events[0].stream_id, stream_id) self.assertEqual(events[0].stream_ended, False) self.assertTrue(isinstance(events[1], DataReceived)) self.assertEqual(events[1].data, b"") self.assertEqual(events[1].stream_id, stream_id) self.assertEqual(events[1].stream_ended, True)
aioquic.h3.connection/H3Connection._receive_stream_data_bidi
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: <0> """ <1> Client-initiated bidirectional streams carry requests and responses. <2> """ <3> http_events: List[HttpEvent] = [] <4> <5> stream = self._stream[stream_id] <6> stream.buffer += data <7> if stream_ended: <8> stream.ended = True <9> if stream.blocked: <10> return http_events <11> <12> # shortcut DATA frame bits <13> if ( <14> stream.frame_type == FrameType.DATA <15> and stream.frame_size is not None <16> and len(stream.buffer) < stream.frame_size <17> ): <18> http_events.append( <19> DataReceived( <20> data=stream.buffer, stream_id=stream_id, stream_ended=False <21> ) <22> ) <23> stream.frame_size -= len(stream.buffer) <24> stream.buffer = b"" <25> return http_events <26> <27> # some peers (e.g. f5) end the stream with no data <28> if stream_ended and not stream.buffer: <29> http_events.append( <30> DataReceived(data=b"", stream_id=stream_id, stream_ended=True) <31> ) <32> return http_events <33> <34> buf = Buffer(data=stream.buffer) <35> consumed = 0 <36> <37> while not buf.eof(): <38> # fetch next frame header <39> if stream.frame_size is None: <40> try: <41> stream.frame_type = buf.pull_uint_var() <42> stream.frame_size = buf.pull_uint_var() <43> except BufferReadError: <44> break <45> consumed = buf.tell() <46> <47> # check how much data is available <48> chunk_size = min(stream.frame_size, buf.capacity - consumed</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: # offset: 1 if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size: break # read available data frame_data = buf.pull_bytes(chunk_size) consumed = buf.tell() # detect end of frame stream.frame_size -= chunk_size if not stream.frame_size: stream.frame_size = None if stream.frame_type == FrameType.DATA and (stream_ended or frame_data): http_events.append( DataReceived( data=frame_data, stream_id=stream_id, stream_ended=stream_ended and buf.eof(), ) ) elif stream.frame_type == FrameType.HEADERS: try: headers = self._decode_headers(stream_id, frame_data) except StreamBlocked: stream.blocked = True break cls = ResponseReceived if self._is_client else RequestReceived http_events.append( cls( headers=headers, stream_id=stream_id, stream_ended=stream_ended and buf.eof(), ) ) elif stream.frame_type == FrameType.PUSH_PROMISE: if not self._is_client: raise QuicConnectionError( error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, frame_type=None, reason_phrase="Clients must not send PUSH_PROMISE", ) frame_buf = Buffer(data=frame_data) push_id = frame_buf.pull_uint_var() headers = self._decode_headers( stream_id, frame_data[frame_buf.tell() :] ) http_events.append( PushPromiseReceived( headers=headers, push_</s> ===========below chunk 1=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: # offset: 2 <s>tell() :] ) http_events.append( PushPromiseReceived( headers=headers, push_id=push_id, stream_id=stream_id ) ) elif stream.frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on request stream", ) # remove processed data from buffer stream.buffer = stream.buffer[consumed:] return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) at: aioquic.h3.connection.H3Connection _decode_headers(stream_id: int, frame_data: bytes) -> Headers at: aioquic.h3.connection.H3Connection.__init__ self._is_client = quic.configuration.is_client self._stream: Dict[int, H3Stream] = {} at: aioquic.h3.connection.H3Stream.__init__ self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None at: aioquic.h3.events HttpEvent() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) PushPromiseReceived(headers: Headers, push_id: int, stream_id: int) at: aioquic.quic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) ===========unchanged ref 1=========== at: typing List = _alias(list, 1, inst=False, name='List') ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 1=========== # module: aioquic.h3.connection class H3Connection: def _handle_push_frame( self, frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool, ) -> List[HttpEvent]: """ Handle a frame received on a push stream. """ http_events: List[HttpEvent] = [] if frame_type == FrameType.DATA: http_events.append( DataReceived( data=frame_data, push_id=push_id, stream_ended=stream_ended, stream_id=stream_id, ) ) elif frame_type == FrameType.HEADERS: headers = self._decode_headers(stream_id, frame_data) http_events.append( + HeadersReceived( - ResponseReceived( headers=headers, push_id=push_id, stream_id=stream_id, stream_ended=stream_ended, ) ) elif frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.PUSH_PROMISE, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, FrameType.DUPLICATE_PUSH, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on push stream", ) return http_events ===========changed ref 2=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 3=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." -
aioquic.h3.connection/H3Connection._receive_stream_data_uni
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: <0> http_events: List[HttpEvent] = [] <1> <2> stream = self._stream[stream_id] <3> stream.buffer += data <4> if stream_ended: <5> stream.ended = True <6> <7> buf = Buffer(data=stream.buffer) <8> consumed = 0 <9> unblocked_streams: Set[int] = set() <10> <11> while not buf.eof(): <12> # fetch stream type for unidirectional streams <13> if stream.stream_type is None: <14> try: <15> stream.stream_type = buf.pull_uint_var() <16> except BufferReadError: <17> break <18> consumed = buf.tell() <19> <20> # check unicity <21> if stream.stream_type == StreamType.CONTROL: <22> assert self._peer_control_stream_id is None <23> self._peer_control_stream_id = stream_id <24> elif stream.stream_type == StreamType.QPACK_DECODER: <25> assert self._peer_decoder_stream_id is None <26> self._peer_decoder_stream_id = stream_id <27> elif stream.stream_type == StreamType.QPACK_ENCODER: <28> assert self._peer_encoder_stream_id is None <29> self._peer_encoder_stream_id = stream_id <30> <31> if stream.stream_type == StreamType.CONTROL: <32> # fetch next frame <33> try: <34> frame_type = buf.pull_uint_var() <35> frame_length = buf.pull_uint_var() <36> frame_data = buf.pull_bytes(frame_length) <37> except BufferReadError: <38> break <39> consumed = buf.tell() <40> <41> self._handle_control_frame(frame_type, frame_data) <42> elif stream.stream_</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: # offset: 1 # fetch push id if stream.push_id is None: try: stream.push_id = buf.pull_uint_var() except BufferReadError: break consumed = buf.tell() # fetch next frame try: frame_type = buf.pull_uint_var() frame_length = buf.pull_uint_var() frame_data = buf.pull_bytes(frame_length) except BufferReadError: break consumed = buf.tell() http_events.extend( self._handle_push_frame( frame_type=frame_type, frame_data=frame_data, push_id=stream.push_id, stream_id=stream_id, stream_ended=stream.ended and buf.eof(), ) ) elif stream.stream_type == StreamType.QPACK_DECODER: # feed unframed data to decoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() self._encoder.feed_decoder(data) elif stream.stream_type == StreamType.QPACK_ENCODER: # feed unframed data to encoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() unblocked_streams.update(self._decoder.feed_encoder(data)) # remove processed data from buffer stream.buffer = stream.buffer[consumed:] # process unblocked streams for stream_id in unblocked_streams: stream = self._stream[stream_id] decoder, headers = self._decoder.resume_header(stream_id) stream.blocked = False cls = ResponseReceived if self._is_client</s> ===========below chunk 1=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: # offset: 2 <s>._decoder.resume_header(stream_id) stream.blocked = False cls = ResponseReceived if self._is_client else RequestReceived http_events.append( cls( headers=headers, stream_id=stream_id, stream_ended=stream.ended and not stream.buffer, ) ) http_events.extend( self._receive_stream_data_bidi(stream_id, b"", stream.ended) ) return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.h3.connection StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) at: aioquic.h3.connection.H3Connection _handle_control_frame(frame_type: int, frame_data: bytes) -> None _handle_push_frame(frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[HttpEvent] at: aioquic.h3.connection.H3Connection.__init__ self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None at: aioquic.h3.events HttpEvent() HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: typing List = _alias(list, 1, inst=False, name='List') Set = _alias(set, 1, inst=False, name='Set') ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def _handle_push_frame( self, frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool, ) -> List[HttpEvent]: """ Handle a frame received on a push stream. """ http_events: List[HttpEvent] = [] if frame_type == FrameType.DATA: http_events.append( DataReceived( data=frame_data, push_id=push_id, stream_ended=stream_ended, stream_id=stream_id, ) ) elif frame_type == FrameType.HEADERS: headers = self._decode_headers(stream_id, frame_data) http_events.append( + HeadersReceived( - ResponseReceived( headers=headers, push_id=push_id, stream_id=stream_id, stream_ended=stream_ended, ) ) elif frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.PUSH_PROMISE, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, FrameType.DUPLICATE_PUSH, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on push stream", ) return http_events ===========changed ref 1=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." +
examples.interop/test_http_0
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
<14>:<add> if events and isinstance(events[0], HeadersReceived): <del> if events and isinstance(events[0], ResponseReceived):
# module: examples.interop def test_http_0(server: Server, configuration: QuicConfiguration): <0> if server.path is None: <1> return <2> <3> configuration.alpn_protocols = ["hq-22"] <4> async with connect( <5> server.host, <6> server.port, <7> configuration=configuration, <8> create_protocol=HttpClient, <9> ) as protocol: <10> protocol = cast(HttpClient, protocol) <11> <12> # perform HTTP request <13> events = await protocol.get(server.host, server.path) <14> if events and isinstance(events[0], ResponseReceived): <15> server.result |= Result.D <16>
===========unchanged ref 0=========== at: aioquic.asyncio.client connect(host: str, port: int, *, configuration: Optional[QuicConfiguration]=None, create_protocol: Optional[Callable]=QuicConnectionProtocol, session_ticket_handler: Optional[SessionTicketHandler]=None, stream_handler: Optional[QuicStreamHandler]=None) -> AsyncGenerator[QuicConnectionProtocol, None] connect(*args, **kwds) at: aioquic.h3.events HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.configuration.QuicConfiguration alpn_protocols: Optional[List[str]] = None certificate: Any = None connection_id_length: int = 8 idle_timeout: float = 60.0 is_client: bool = True private_key: Any = None quic_logger: Optional[QuicLogger] = None secrets_log_file: TextIO = None server_name: Optional[str] = None session_ticket: Optional[SessionTicket] = None supported_versions: List[int] = field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] ) at: examples.interop Result() ===========unchanged ref 1=========== Server(name: str, host: str, port: int=4433, http3: bool=True, retry_port: Optional[int]=4434, path: str="/", result: Result=field(default_factory=lambda: Result(0))) at: examples.interop.Server name: str host: str port: int = 4433 http3: bool = True retry_port: Optional[int] = 4434 path: str = "/" result: Result = field(default_factory=lambda: Result(0)) at: http3_client HttpClient(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None, /, *, quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None) at: http3_client.HttpClient get(authority: str, path: str) -> Deque[HttpEvent] at: typing cast(typ: Type[_T], val: Any) -> _T cast(typ: str, val: Any) -> Any cast(typ: object, val: Any) -> Any ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 1=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 2=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - ===========changed ref 3=========== # module: aioquic.h3.events - @dataclass - class ResponseReceived(HttpEvent): - """ - The ResponseReceived event is fired whenever response headers are received. - """ - - headers: Headers - "The response headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - - push_id: Optional[int] = None - "The Push ID or `None` if this is not a push." - ===========changed ref 4=========== # module: aioquic.h0.connection class H0Connection: def handle_event(self, event: QuicEvent) -> List[HttpEvent]: http_events: List[HttpEvent] = [] if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0: data = event.data if not self._headers_received.get(event.stream_id, False): if self._is_client: http_events.append( + HeadersReceived( - ResponseReceived( headers=[], stream_ended=False, stream_id=event.stream_id ) ) else: method, path = data.rstrip().split(b" ", 1) http_events.append( + HeadersReceived( - RequestReceived( headers=[(b":method", method), (b":path", path)], stream_ended=False, stream_id=event.stream_id, ) ) data = b"" self._headers_received[event.stream_id] = True http_events.append( DataReceived( data=data, stream_ended=event.end_stream, stream_id=event.stream_id ) ) return http_events ===========changed ref 5=========== # module: aioquic.h3.connection class H3Connection: def _handle_push_frame( self, frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool, ) -> List[HttpEvent]: """ Handle a frame received on a push stream. """ http_events: List[HttpEvent] = [] if frame_type == FrameType.DATA: http_events.append( DataReceived( data=frame_data, push_id=push_id, stream_ended=stream_ended, stream_id=stream_id, ) ) elif frame_type == FrameType.HEADERS: headers = self._decode_headers(stream_id, frame_data) http_events.append( + HeadersReceived( - ResponseReceived( headers=headers, push_id=push_id, stream_id=stream_id, stream_ended=stream_ended, ) ) elif frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.PUSH_PROMISE, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, FrameType.DUPLICATE_PUSH, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on push stream", ) return http_events
examples.interop/test_http_3
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
<14>:<add> if events and isinstance(events[0], HeadersReceived): <del> if events and isinstance(events[0], ResponseReceived):
# module: examples.interop def test_http_3(server: Server, configuration: QuicConfiguration): <0> if server.path is None: <1> return <2> <3> configuration.alpn_protocols = ["h3-22"] <4> async with connect( <5> server.host, <6> server.port, <7> configuration=configuration, <8> create_protocol=HttpClient, <9> ) as protocol: <10> protocol = cast(HttpClient, protocol) <11> <12> # perform HTTP request <13> events = await protocol.get(server.host, server.path) <14> if events and isinstance(events[0], ResponseReceived): <15> server.result |= Result.D <16> server.result |= Result.three <17>
===========unchanged ref 0=========== at: aioquic.asyncio.client connect(host: str, port: int, *, configuration: Optional[QuicConfiguration]=None, create_protocol: Optional[Callable]=QuicConnectionProtocol, session_ticket_handler: Optional[SessionTicketHandler]=None, stream_handler: Optional[QuicStreamHandler]=None) -> AsyncGenerator[QuicConnectionProtocol, None] connect(*args, **kwds) at: aioquic.h3.events HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.configuration.QuicConfiguration alpn_protocols: Optional[List[str]] = None at: examples.interop Result() Server(name: str, host: str, port: int=4433, http3: bool=True, retry_port: Optional[int]=4434, path: str="/", result: Result=field(default_factory=lambda: Result(0))) at: examples.interop.Server host: str port: int = 4433 path: str = "/" result: Result = field(default_factory=lambda: Result(0)) at: http3_client HttpClient(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None, /, *, quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None) ===========unchanged ref 1=========== at: http3_client.HttpClient get(authority: str, path: str) -> Deque[HttpEvent] at: typing cast(typ: Type[_T], val: Any) -> _T cast(typ: str, val: Any) -> Any cast(typ: object, val: Any) -> Any ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 1=========== # module: examples.interop def test_http_0(server: Server, configuration: QuicConfiguration): if server.path is None: return configuration.alpn_protocols = ["hq-22"] async with connect( server.host, server.port, configuration=configuration, create_protocol=HttpClient, ) as protocol: protocol = cast(HttpClient, protocol) # perform HTTP request events = await protocol.get(server.host, server.path) + if events and isinstance(events[0], HeadersReceived): - if events and isinstance(events[0], ResponseReceived): server.result |= Result.D ===========changed ref 2=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 3=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - ===========changed ref 4=========== # module: aioquic.h3.events - @dataclass - class ResponseReceived(HttpEvent): - """ - The ResponseReceived event is fired whenever response headers are received. - """ - - headers: Headers - "The response headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - - push_id: Optional[int] = None - "The Push ID or `None` if this is not a push." - ===========changed ref 5=========== # module: aioquic.h0.connection class H0Connection: def handle_event(self, event: QuicEvent) -> List[HttpEvent]: http_events: List[HttpEvent] = [] if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0: data = event.data if not self._headers_received.get(event.stream_id, False): if self._is_client: http_events.append( + HeadersReceived( - ResponseReceived( headers=[], stream_ended=False, stream_id=event.stream_id ) ) else: method, path = data.rstrip().split(b" ", 1) http_events.append( + HeadersReceived( - RequestReceived( headers=[(b":method", method), (b":path", path)], stream_ended=False, stream_id=event.stream_id, ) ) data = b"" self._headers_received[event.stream_id] = True http_events.append( DataReceived( data=data, stream_ended=event.end_stream, stream_id=event.stream_id ) ) return http_events ===========changed ref 6=========== # module: aioquic.h3.connection class H3Connection: def _handle_push_frame( self, frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool, ) -> List[HttpEvent]: """ Handle a frame received on a push stream. """ http_events: List[HttpEvent] = [] if frame_type == FrameType.DATA: http_events.append( DataReceived( data=frame_data, push_id=push_id, stream_ended=stream_ended, stream_id=stream_id, ) ) elif frame_type == FrameType.HEADERS: headers = self._decode_headers(stream_id, frame_data) http_events.append( + HeadersReceived( - ResponseReceived( headers=headers, push_id=push_id, stream_id=stream_id, stream_ended=stream_ended, ) ) elif frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.PUSH_PROMISE, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, FrameType.DUPLICATE_PUSH, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on push stream", ) return http_events
examples.http3_client/WebSocket.http_event_received
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
<0>:<add> if isinstance(event, HeadersReceived): <del> if isinstance(event, ResponseReceived):
# module: examples.http3_client class WebSocket: def http_event_received(self, event: HttpEvent): <0> if isinstance(event, ResponseReceived): <1> for header, value in event.headers: <2> if header == b"sec-websocket-protocol": <3> self.subprotocol = value.decode("utf8") <4> elif isinstance(event, DataReceived): <5> self.websocket.receive_data(event.data) <6> <7> for ws_event in self.websocket.events(): <8> self.websocket_event_received(ws_event) <9>
===========unchanged ref 0=========== at: aioquic.h3.events HttpEvent() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: examples.http3_client.WebSocket websocket_event_received(event: wsproto.events.Event) -> None at: examples.http3_client.WebSocket.__init__ self.subprotocol: Optional[str] = None self.websocket = wsproto.Connection(wsproto.ConnectionType.CLIENT) ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 1=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 2=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - ===========changed ref 3=========== # module: aioquic.h3.events - @dataclass - class ResponseReceived(HttpEvent): - """ - The ResponseReceived event is fired whenever response headers are received. - """ - - headers: Headers - "The response headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - - push_id: Optional[int] = None - "The Push ID or `None` if this is not a push." - ===========changed ref 4=========== # module: examples.interop def test_http_0(server: Server, configuration: QuicConfiguration): if server.path is None: return configuration.alpn_protocols = ["hq-22"] async with connect( server.host, server.port, configuration=configuration, create_protocol=HttpClient, ) as protocol: protocol = cast(HttpClient, protocol) # perform HTTP request events = await protocol.get(server.host, server.path) + if events and isinstance(events[0], HeadersReceived): - if events and isinstance(events[0], ResponseReceived): server.result |= Result.D ===========changed ref 5=========== # module: examples.interop def test_http_3(server: Server, configuration: QuicConfiguration): if server.path is None: return configuration.alpn_protocols = ["h3-22"] async with connect( server.host, server.port, configuration=configuration, create_protocol=HttpClient, ) as protocol: protocol = cast(HttpClient, protocol) # perform HTTP request events = await protocol.get(server.host, server.path) + if events and isinstance(events[0], HeadersReceived): - if events and isinstance(events[0], ResponseReceived): server.result |= Result.D server.result |= Result.three ===========changed ref 6=========== # module: aioquic.h0.connection class H0Connection: def handle_event(self, event: QuicEvent) -> List[HttpEvent]: http_events: List[HttpEvent] = [] if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0: data = event.data if not self._headers_received.get(event.stream_id, False): if self._is_client: http_events.append( + HeadersReceived( - ResponseReceived( headers=[], stream_ended=False, stream_id=event.stream_id ) ) else: method, path = data.rstrip().split(b" ", 1) http_events.append( + HeadersReceived( - RequestReceived( headers=[(b":method", method), (b":path", path)], stream_ended=False, stream_id=event.stream_id, ) ) data = b"" self._headers_received[event.stream_id] = True http_events.append( DataReceived( data=data, stream_ended=event.end_stream, stream_id=event.stream_id ) ) return http_events ===========changed ref 7=========== # module: aioquic.h3.connection class H3Connection: def _handle_push_frame( self, frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool, ) -> List[HttpEvent]: """ Handle a frame received on a push stream. """ http_events: List[HttpEvent] = [] if frame_type == FrameType.DATA: http_events.append( DataReceived( data=frame_data, push_id=push_id, stream_ended=stream_ended, stream_id=stream_id, ) ) elif frame_type == FrameType.HEADERS: headers = self._decode_headers(stream_id, frame_data) http_events.append( + HeadersReceived( - ResponseReceived( headers=headers, push_id=push_id, stream_id=stream_id, stream_ended=stream_ended, ) ) elif frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.PUSH_PROMISE, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, FrameType.DUPLICATE_PUSH, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on push stream", ) return http_events
examples.http3_client/HttpClient.http_event_received
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
<0>:<add> if isinstance(event, (HeadersReceived, DataReceived)): <del> if isinstance(event, (ResponseReceived, DataReceived)):
# module: examples.http3_client class HttpClient(QuicConnectionProtocol): def http_event_received(self, event: HttpEvent): <0> if isinstance(event, (ResponseReceived, DataReceived)): <1> stream_id = event.stream_id <2> if stream_id in self._request_events: <3> # http <4> self._request_events[event.stream_id].append(event) <5> if event.stream_ended: <6> request_waiter = self._request_waiter.pop(stream_id) <7> request_waiter.set_result(self._request_events.pop(stream_id)) <8> <9> elif stream_id in self._websockets: <10> # websocket <11> websocket = self._websockets[stream_id] <12> websocket.http_event_received(event) <13> <14> else: <15> # push <16> print(event) <17>
===========unchanged ref 0=========== at: _asyncio.Future set_result(result, /) at: aioquic.h3.events HttpEvent() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: asyncio.futures.Future _state = _PENDING _result = None _exception = None _loop = None _source_traceback = None _cancel_message = None _cancelled_exc = None _asyncio_future_blocking = False __log_traceback = False __class_getitem__ = classmethod(GenericAlias) set_result(result: _T, /) -> None __iter__ = __await__ # make compatible with 'yield from'. at: collections.deque append(x: _T) -> None at: examples.http3_client.HttpClient.__init__ self._request_events: Dict[int, Deque[HttpEvent]] = {} self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {} self._websockets: Dict[int, WebSocket] = {} at: examples.http3_client.WebSocket http_event_received(event: HttpEvent) http_event_received(self, event: HttpEvent) at: typing.MutableMapping pop(key: _KT) -> _VT pop(key: _KT, default: Union[_VT, _T]=...) -> Union[_VT, _T] ===========changed ref 0=========== # module: examples.http3_client class WebSocket: def http_event_received(self, event: HttpEvent): + if isinstance(event, HeadersReceived): - if isinstance(event, ResponseReceived): for header, value in event.headers: if header == b"sec-websocket-protocol": self.subprotocol = value.decode("utf8") elif isinstance(event, DataReceived): self.websocket.receive_data(event.data) for ws_event in self.websocket.events(): self.websocket_event_received(ws_event) ===========changed ref 1=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 2=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 3=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - ===========changed ref 4=========== # module: aioquic.h3.events - @dataclass - class ResponseReceived(HttpEvent): - """ - The ResponseReceived event is fired whenever response headers are received. - """ - - headers: Headers - "The response headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - - push_id: Optional[int] = None - "The Push ID or `None` if this is not a push." - ===========changed ref 5=========== # module: examples.interop def test_http_0(server: Server, configuration: QuicConfiguration): if server.path is None: return configuration.alpn_protocols = ["hq-22"] async with connect( server.host, server.port, configuration=configuration, create_protocol=HttpClient, ) as protocol: protocol = cast(HttpClient, protocol) # perform HTTP request events = await protocol.get(server.host, server.path) + if events and isinstance(events[0], HeadersReceived): - if events and isinstance(events[0], ResponseReceived): server.result |= Result.D ===========changed ref 6=========== # module: examples.interop def test_http_3(server: Server, configuration: QuicConfiguration): if server.path is None: return configuration.alpn_protocols = ["h3-22"] async with connect( server.host, server.port, configuration=configuration, create_protocol=HttpClient, ) as protocol: protocol = cast(HttpClient, protocol) # perform HTTP request events = await protocol.get(server.host, server.path) + if events and isinstance(events[0], HeadersReceived): - if events and isinstance(events[0], ResponseReceived): server.result |= Result.D server.result |= Result.three ===========changed ref 7=========== # module: aioquic.h0.connection class H0Connection: def handle_event(self, event: QuicEvent) -> List[HttpEvent]: http_events: List[HttpEvent] = [] if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0: data = event.data if not self._headers_received.get(event.stream_id, False): if self._is_client: http_events.append( + HeadersReceived( - ResponseReceived( headers=[], stream_ended=False, stream_id=event.stream_id ) ) else: method, path = data.rstrip().split(b" ", 1) http_events.append( + HeadersReceived( - RequestReceived( headers=[(b":method", method), (b":path", path)], stream_ended=False, stream_id=event.stream_id, ) ) data = b"" self._headers_received[event.stream_id] = True http_events.append( DataReceived( data=data, stream_ended=event.end_stream, stream_id=event.stream_id ) ) return http_events
examples.http3_client/run
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
# module: examples.http3_client def run(configuration: QuicConfiguration, url: str) -> None: <0> # parse URL <1> parsed = urlparse(url) <2> assert parsed.scheme in ( <3> "https", <4> "wss", <5> ), "Only https:// or wss:// URLs are supported." <6> if ":" in parsed.netloc: <7> host, port_str = parsed.netloc.split(":") <8> port = int(port_str) <9> else: <10> host = parsed.netloc <11> port = 443 <12> <13> path = parsed.path <14> if parsed.query: <15> path += "?" + parsed.query <16> <17> async with connect( <18> host, <19> port, <20> configuration=configuration, <21> create_protocol=HttpClient, <22> session_ticket_handler=save_session_ticket, <23> ) as client: <24> client = cast(HttpClient, client) <25> <26> if parsed.scheme == "wss": <27> ws = await client.websocket( <28> parsed.netloc, path, subprotocols=["chat", "superchat"] <29> ) <30> <31> # send some messages and receive reply <32> for i in range(2): <33> message = "Hello {}, WebSocket!".format(i) <34> print("> " + message) <35> await ws.send(message) <36> <37> message = await ws.recv() <38> print("< " + message) <39> <40> await ws.close() <41> else: <42> # perform request <43> start = time.time() <44> http_events = await client.get(parsed.netloc, path) <45> elapsed = time.time() - start <46> <47> # print speed <48> octets = 0 <49> for http_event in http_events: <50> if isinstance(http_event, DataReceived): <51> octets += len(http_event.data) <52> logger.info( <53> "Received %d bytes in %.1f s (%.3f Mbps)" <54> % (octets,</s>
===========below chunk 0=========== # module: examples.http3_client def run(configuration: QuicConfiguration, url: str) -> None: # offset: 1 ) # print response for http_event in http_events: if isinstance(http_event, ResponseReceived): headers = b"" for k, v in http_event.headers: headers += k + b": " + v + b"\r\n" if headers: sys.stderr.buffer.write(headers + b"\r\n") sys.stderr.buffer.flush() elif isinstance(http_event, DataReceived): sys.stdout.buffer.write(http_event.data) sys.stdout.buffer.flush() ===========unchanged ref 0=========== at: aioquic.asyncio.client connect(host: str, port: int, *, configuration: Optional[QuicConfiguration]=None, create_protocol: Optional[Callable]=QuicConnectionProtocol, session_ticket_handler: Optional[SessionTicketHandler]=None, stream_handler: Optional[QuicStreamHandler]=None) -> AsyncGenerator[QuicConnectionProtocol, None] connect(*args, **kwds) at: aioquic.h3.events DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: examples.http3_client logger = logging.getLogger("client") HttpClient(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None, /, *, quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None) save_session_ticket(ticket) at: examples.http3_client.HttpClient get(authority: str, path: str) -> Deque[HttpEvent] websocket(authority: str, path: str, subprotocols: List[str]=[]) -> WebSocket at: examples.http3_client.WebSocket close(code=1000, reason="") -> None recv() -> str send(message: str) ===========unchanged ref 1=========== at: logging.Logger info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None at: sys stdout: TextIO stderr: TextIO at: time time() -> float at: typing cast(typ: Type[_T], val: Any) -> _T cast(typ: str, val: Any) -> Any cast(typ: object, val: Any) -> Any at: typing.BinaryIO __slots__ = () write(s: AnyStr) -> int at: typing.IO __slots__ = () flush() -> None at: typing.TextIO __slots__ = () at: urllib.parse urlparse(url: str, scheme: Optional[str]=..., allow_fragments: bool=...) -> ParseResult urlparse(url: Optional[bytes], scheme: Optional[bytes]=..., allow_fragments: bool=...) -> ParseResultBytes ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 1=========== # module: examples.http3_client class HttpClient(QuicConnectionProtocol): def http_event_received(self, event: HttpEvent): + if isinstance(event, (HeadersReceived, DataReceived)): - if isinstance(event, (ResponseReceived, DataReceived)): stream_id = event.stream_id if stream_id in self._request_events: # http self._request_events[event.stream_id].append(event) if event.stream_ended: request_waiter = self._request_waiter.pop(stream_id) request_waiter.set_result(self._request_events.pop(stream_id)) elif stream_id in self._websockets: # websocket websocket = self._websockets[stream_id] websocket.http_event_received(event) else: # push print(event) ===========changed ref 2=========== # module: examples.http3_client class WebSocket: def http_event_received(self, event: HttpEvent): + if isinstance(event, HeadersReceived): - if isinstance(event, ResponseReceived): for header, value in event.headers: if header == b"sec-websocket-protocol": self.subprotocol = value.decode("utf8") elif isinstance(event, DataReceived): self.websocket.receive_data(event.data) for ws_event in self.websocket.events(): self.websocket_event_received(ws_event) ===========changed ref 3=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 4=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - ===========changed ref 5=========== # module: aioquic.h3.events - @dataclass - class ResponseReceived(HttpEvent): - """ - The ResponseReceived event is fired whenever response headers are received. - """ - - headers: Headers - "The response headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - - push_id: Optional[int] = None - "The Push ID or `None` if this is not a push." - ===========changed ref 6=========== # module: examples.interop def test_http_0(server: Server, configuration: QuicConfiguration): if server.path is None: return configuration.alpn_protocols = ["hq-22"] async with connect( server.host, server.port, configuration=configuration, create_protocol=HttpClient, ) as protocol: protocol = cast(HttpClient, protocol) # perform HTTP request events = await protocol.get(server.host, server.path) + if events and isinstance(events[0], HeadersReceived): - if events and isinstance(events[0], ResponseReceived): server.result |= Result.D
tests.test_h3/H3ConnectionTest._make_request
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
<22>:<add> HeadersReceived( <del> RequestReceived(
# module: tests.test_h3 class H3ConnectionTest(TestCase): def _make_request(self, h3_client, h3_server): <0> quic_client = h3_client._quic <1> quic_server = h3_server._quic <2> <3> # send request <4> stream_id = quic_client.get_next_available_stream_id() <5> h3_client.send_headers( <6> stream_id=stream_id, <7> headers=[ <8> (b":method", b"GET"), <9> (b":scheme", b"https"), <10> (b":authority", b"localhost"), <11> (b":path", b"/"), <12> (b"x-foo", b"client"), <13> ], <14> ) <15> h3_client.send_data(stream_id=stream_id, data=b"", end_stream=True) <16> <17> # receive request <18> events = h3_transfer(quic_client, h3_server) <19> self.assertEqual( <20> events, <21> [ <22> RequestReceived( <23> headers=[ <24> (b":method", b"GET"), <25> (b":scheme", b"https"), <26> (b":authority", b"localhost"), <27> (b":path", b"/"), <28> (b"x-foo", b"client"), <29> ], <30> stream_id=stream_id, <31> stream_ended=False, <32> ), <33> DataReceived(data=b"", stream_id=stream_id, stream_ended=True), <34> ], <35> ) <36> <37> # send response <38> h3_server.send_headers( <39> stream_id=stream_id, <40> headers=[ <41> (b":status", b"200"), <42> (b"content-type", b"text/html; charset=utf-8"), <43> (b"x-foo", b"server"), <44> ],</s>
===========below chunk 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def _make_request(self, h3_client, h3_server): # offset: 1 h3_server.send_data( stream_id=stream_id, data=b"<html><body>hello</body></html>", end_stream=True, ) # receive response events = h3_transfer(quic_server, h3_client) self.assertEqual( events, [ ResponseReceived( headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], stream_id=stream_id, stream_ended=False, ), DataReceived( data=b"<html><body>hello</body></html>", stream_id=stream_id, stream_ended=True, ), ], ) ===========unchanged ref 0=========== at: aioquic.h3.connection.H3Connection send_data(stream_id: int, data: bytes, end_stream: bool) -> None send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.events DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.h3.events.DataReceived data: bytes stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.HeadersReceived headers: Headers stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.quic.connection.QuicConnection get_next_available_stream_id(is_unidirectional=False) -> int at: tests.test_h3 h3_transfer(quic_sender, h3_receiver) at: tests.test_h3.H3ConnectionTest maxDiff = None at: tests.test_h3.H3ConnectionTest._make_request quic_client = h3_client._quic quic_server = h3_server._quic at: unittest.case.TestCase failureException: Type[BaseException] longMessage: bool maxDiff: Optional[int] _testMethodName: str _testMethodDoc: str assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 1=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 2=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - ===========changed ref 3=========== # module: examples.http3_client class WebSocket: def http_event_received(self, event: HttpEvent): + if isinstance(event, HeadersReceived): - if isinstance(event, ResponseReceived): for header, value in event.headers: if header == b"sec-websocket-protocol": self.subprotocol = value.decode("utf8") elif isinstance(event, DataReceived): self.websocket.receive_data(event.data) for ws_event in self.websocket.events(): self.websocket_event_received(ws_event) ===========changed ref 4=========== # module: aioquic.h3.events - @dataclass - class ResponseReceived(HttpEvent): - """ - The ResponseReceived event is fired whenever response headers are received. - """ - - headers: Headers - "The response headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - - push_id: Optional[int] = None - "The Push ID or `None` if this is not a push." - ===========changed ref 5=========== # module: examples.interop def test_http_0(server: Server, configuration: QuicConfiguration): if server.path is None: return configuration.alpn_protocols = ["hq-22"] async with connect( server.host, server.port, configuration=configuration, create_protocol=HttpClient, ) as protocol: protocol = cast(HttpClient, protocol) # perform HTTP request events = await protocol.get(server.host, server.path) + if events and isinstance(events[0], HeadersReceived): - if events and isinstance(events[0], ResponseReceived): server.result |= Result.D ===========changed ref 6=========== # module: examples.interop def test_http_3(server: Server, configuration: QuicConfiguration): if server.path is None: return configuration.alpn_protocols = ["h3-22"] async with connect( server.host, server.port, configuration=configuration, create_protocol=HttpClient, ) as protocol: protocol = cast(HttpClient, protocol) # perform HTTP request events = await protocol.get(server.host, server.path) + if events and isinstance(events[0], HeadersReceived): - if events and isinstance(events[0], ResponseReceived): server.result |= Result.D server.result |= Result.three ===========changed ref 7=========== # module: examples.http3_client class HttpClient(QuicConnectionProtocol): def http_event_received(self, event: HttpEvent): + if isinstance(event, (HeadersReceived, DataReceived)): - if isinstance(event, (ResponseReceived, DataReceived)): stream_id = event.stream_id if stream_id in self._request_events: # http self._request_events[event.stream_id].append(event) if event.stream_ended: request_waiter = self._request_waiter.pop(stream_id) request_waiter.set_result(self._request_events.pop(stream_id)) elif stream_id in self._websockets: # websocket websocket = self._websockets[stream_id] websocket.http_event_received(event) else: # push print(event)
tests.test_h3/H3ConnectionTest.test_request_headers_only
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
<26>:<add> HeadersReceived( <del> RequestReceived(
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_headers_only(self): <0> with client_and_server( <1> client_options={"alpn_protocols": ["h3-22"]}, <2> server_options={"alpn_protocols": ["h3-22"]}, <3> ) as (quic_client, quic_server): <4> h3_client = H3Connection(quic_client) <5> h3_server = H3Connection(quic_server) <6> <7> # send request <8> stream_id = quic_client.get_next_available_stream_id() <9> h3_client.send_headers( <10> stream_id=stream_id, <11> headers=[ <12> (b":method", b"HEAD"), <13> (b":scheme", b"https"), <14> (b":authority", b"localhost"), <15> (b":path", b"/"), <16> (b"x-foo", b"client"), <17> ], <18> end_stream=True, <19> ) <20> <21> # receive request <22> events = h3_transfer(quic_client, h3_server) <23> self.assertEqual( <24> events, <25> [ <26> RequestReceived( <27> headers=[ <28> (b":method", b"HEAD"), <29> (b":scheme", b"https"), <30> (b":authority", b"localhost"), <31> (b":path", b"/"), <32> (b"x-foo", b"client"), <33> ], <34> stream_id=stream_id, <35> stream_ended=True, <36> ) <37> ], <38> ) <39> <40> # send response <41> h3_server.send_headers( <42> stream_id=stream_id, <43> headers=[ <44> (b":status", b"200"), <45> (b"content-type", b"text/html; charset=utf-8"), <46> (b</s>
===========below chunk 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_headers_only(self): # offset: 1 ], end_stream=True, ) # receive response events = h3_transfer(quic_server, h3_client) self.assertEqual(len(events), 1) self.assertTrue( events, [ ResponseReceived( headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], stream_id=stream_id, stream_ended=True, ) ], ) ===========unchanged ref 0=========== at: aioquic.h3.connection H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.events HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.configuration.QuicConfiguration alpn_protocols: Optional[List[str]] = None certificate: Any = None connection_id_length: int = 8 idle_timeout: float = 60.0 is_client: bool = True private_key: Any = None quic_logger: Optional[QuicLogger] = None secrets_log_file: TextIO = None server_name: Optional[str] = None session_ticket: Optional[SessionTicket] = None supported_versions: List[int] = field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] ) at: tests.test_h3 h3_transfer(quic_sender, h3_receiver) FakeQuicConnection(configuration) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========unchanged ref 1=========== assertTrue(expr: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def _make_request(self, h3_client, h3_server): quic_client = h3_client._quic quic_server = h3_server._quic # send request stream_id = quic_client.get_next_available_stream_id() h3_client.send_headers( stream_id=stream_id, headers=[ (b":method", b"GET"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/"), (b"x-foo", b"client"), ], ) h3_client.send_data(stream_id=stream_id, data=b"", end_stream=True) # receive request events = h3_transfer(quic_client, h3_server) self.assertEqual( events, [ + HeadersReceived( - RequestReceived( headers=[ (b":method", b"GET"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/"), (b"x-foo", b"client"), ], stream_id=stream_id, stream_ended=False, ), DataReceived(data=b"", stream_id=stream_id, stream_ended=True), ], ) # send response h3_server.send_headers( stream_id=stream_id, headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], ) h3_server.send_data( stream_id=stream_id, data=b"<html><body>hello</body</s> ===========changed ref 2=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def _make_request(self, h3_client, h3_server): # offset: 1 <s>server.send_data( stream_id=stream_id, data=b"<html><body>hello</body></html>", end_stream=True, ) # receive response events = h3_transfer(quic_server, h3_client) self.assertEqual( events, [ + HeadersReceived( - ResponseReceived( headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], stream_id=stream_id, stream_ended=False, ), DataReceived( data=b"<html><body>hello</body></html>", stream_id=stream_id, stream_ended=True, ), ], ) ===========changed ref 3=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 4=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - ===========changed ref 5=========== # module: examples.http3_client class WebSocket: def http_event_received(self, event: HttpEvent): + if isinstance(event, HeadersReceived): - if isinstance(event, ResponseReceived): for header, value in event.headers: if header == b"sec-websocket-protocol": self.subprotocol = value.decode("utf8") elif isinstance(event, DataReceived): self.websocket.receive_data(event.data) for ws_event in self.websocket.events(): self.websocket_event_received(ws_event)
tests.test_h3/H3ConnectionTest.test_request_fragmented_frame
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
<29>:<add> HeadersReceived( <del> RequestReceived(
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_fragmented_frame(self): <0> quic_client = FakeQuicConnection( <1> configuration=QuicConfiguration(is_client=True) <2> ) <3> quic_server = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=False) <5> ) <6> <7> h3_client = H3Connection(quic_client) <8> h3_server = H3Connection(quic_server) <9> <10> # send request <11> stream_id = quic_client.get_next_available_stream_id() <12> h3_client.send_headers( <13> stream_id=stream_id, <14> headers=[ <15> (b":method", b"GET"), <16> (b":scheme", b"https"), <17> (b":authority", b"localhost"), <18> (b":path", b"/"), <19> (b"x-foo", b"client"), <20> ], <21> ) <22> h3_client.send_data(stream_id=stream_id, data=b"hello", end_stream=True) <23> <24> # receive request <25> events = h3_transfer(quic_client, h3_server) <26> self.assertEqual( <27> events, <28> [ <29> RequestReceived( <30> headers=[ <31> (b":method", b"GET"), <32> (b":scheme", b"https"), <33> (b":authority", b"localhost"), <34> (b":path", b"/"), <35> (b"x-foo", b"client"), <36> ], <37> stream_id=stream_id, <38> stream_ended=False, <39> ), <40> DataReceived(data=b"h", stream_id=0, stream_ended=False), <41> DataReceived(data=b"e", stream_id=0, stream_ended=False), <42> DataReceived(data=b"l", stream</s>
===========below chunk 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_fragmented_frame(self): # offset: 1 DataReceived(data=b"l", stream_id=0, stream_ended=False), DataReceived(data=b"o", stream_id=0, stream_ended=False), DataReceived(data=b"", stream_id=0, stream_ended=True), ], ) # send push promise push_stream_id = h3_server.push_promise( stream_id=stream_id, headers=[ (b":method", b"GET"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/app.txt"), ], ) self.assertEqual(push_stream_id, 15) # send response h3_server.send_headers( stream_id=stream_id, headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), ], end_stream=False, ) h3_server.send_data(stream_id=stream_id, data=b"html", end_stream=True) #  fulfill push promise h3_server.send_headers( stream_id=push_stream_id, headers=[(b":status", b"200"), (b"content-type", b"text/plain")], end_stream=False, ) h3_server.send_data(stream_id=push_stream_id, data=b"text", end_stream=True) # receive push promise / reponse events = h3_transfer(quic_server, h3_client) self.assertEqual( events, [ PushPromiseReceived( headers=[ (b":method", b"GET"), (b":</s> ===========below chunk 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_fragmented_frame(self): # offset: 2 <s> [ PushPromiseReceived( headers=[ (b":method", b"GET"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/app.txt"), ], push_id=0, stream_id=stream_id, ), ResponseReceived( headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), ], stream_id=0, stream_ended=False, ), DataReceived(data=b"h", stream_id=0, stream_ended=False), DataReceived(data=b"t", stream_id=0, stream_ended=False), DataReceived(data=b"m", stream_id=0, stream_ended=False), DataReceived(data=b"l", stream_id=0, stream_ended=False), DataReceived(data=b"", stream_id=0, stream_ended=True), ResponseReceived( headers=[(b":status", b"200"), (b"content-type", b"text/plain")], stream_id=15, stream_ended=False, push_id=0, ), DataReceived(data=b"text", stream_id=15, stream_ended=False, push_id=0), ], ) ===========unchanged ref 0=========== at: aioquic.h3.connection H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection push_promise(stream_id: int, headers: Headers) -> int send_data(stream_id: int, data: bytes, end_stream: bool) -> None send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.events DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) PushPromiseReceived(headers: Headers, push_id: int, stream_id: int) at: aioquic.h3.events.PushPromiseReceived headers: Headers push_id: int stream_id: int at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: tests.test_connection client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_options={}, server_patch=lambda x: None, transport_options={}) at: tests.test_h3 h3_transfer(quic_sender, h3_receiver) ===========unchanged ref 1=========== at: tests.test_h3.FakeQuicConnection get_next_available_stream_id(is_unidirectional=False) at: tests.test_h3.H3ConnectionTest.test_request_fragmented_frame quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." +
tests.test_h3/H3ConnectionTest.test_blocked_stream
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_blocked_stream(self): <0> quic_client = FakeQuicConnection( <1> configuration=QuicConfiguration(is_client=True) <2> ) <3> h3_client = H3Connection(quic_client) <4> <5> h3_client.handle_event( <6> StreamDataReceived( <7> stream_id=3, <8> data=binascii.unhexlify( <9> "0004170150000680020000074064091040bcc0000000faceb00c" <10> ), <11> end_stream=False, <12> ) <13> ) <14> h3_client.handle_event( <15> StreamDataReceived(stream_id=7, data=b"\x02", end_stream=False) <16> ) <17> h3_client.handle_event( <18> StreamDataReceived(stream_id=11, data=b"\x03", end_stream=False) <19> ) <20> h3_client.handle_event( <21> StreamDataReceived( <22> stream_id=0, data=binascii.unhexlify("01040280d910"), end_stream=False <23> ) <24> ) <25> h3_client.handle_event( <26> StreamDataReceived( <27> stream_id=0, <28> data=binascii.unhexlify( <29> "00408d796f752072656163686564206d766673742e6e65742c20726561636820" <30> "746865202f6563686f20656e64706f696e7420666f7220616e206563686f2072" <31> "6573706f6e7365207175657279202f3c6e756d6265723e20656e64706f696e74" <32> "7320666f722061207661726961626c6520736</s>
===========below chunk 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_blocked_stream(self): # offset: 1 "6974682072616e646f6d206279746573" ), end_stream=True, ) ) self.assertEqual( h3_client.handle_event( StreamDataReceived( stream_id=7, data=binascii.unhexlify( "3fe101c696d07abe941094cb6d0a08017d403971966e32ca98b46f" ), end_stream=False, ) ), [ ResponseReceived( headers=[ (b":status", b"200"), (b"date", b"Mon, 22 Jul 2019 06:33:33 GMT"), ], stream_id=0, stream_ended=False, ), DataReceived( data=( b"you reached mvfst.net, reach the /echo endpoint for an " b"echo response query /<number> endpoints for a variable " b"size response with random bytes" ), stream_id=0, stream_ended=True, ), ], ) ===========unchanged ref 0=========== at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[HttpEvent] at: aioquic.h3.events DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: aioquic.quic.events.StreamDataReceived data: bytes end_stream: bool stream_id: int at: binascii unhexlify(hexstr: _Ascii, /) -> bytes at: tests.test_connection client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_options={}, server_patch=lambda x: None, transport_options={}) at: tests.test_h3.H3ConnectionTest.test_blocked_stream h3_client = H3Connection(quic_client) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_headers_only(self): with client_and_server( client_options={"alpn_protocols": ["h3-22"]}, server_options={"alpn_protocols": ["h3-22"]}, ) as (quic_client, quic_server): h3_client = H3Connection(quic_client) h3_server = H3Connection(quic_server) # send request stream_id = quic_client.get_next_available_stream_id() h3_client.send_headers( stream_id=stream_id, headers=[ (b":method", b"HEAD"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/"), (b"x-foo", b"client"), ], end_stream=True, ) # receive request events = h3_transfer(quic_client, h3_server) self.assertEqual( events, [ + HeadersReceived( - RequestReceived( headers=[ (b":method", b"HEAD"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/"), (b"x-foo", b"client"), ], stream_id=stream_id, stream_ended=True, ) ], ) # send response h3_server.send_headers( stream_id=stream_id, headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], end_stream=True, ) # receive response events = h3_transfer(</s> ===========changed ref 2=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_headers_only(self): # offset: 1 <s> ], end_stream=True, ) # receive response events = h3_transfer(quic_server, h3_client) self.assertEqual(len(events), 1) self.assertTrue( events, [ + HeadersReceived( - ResponseReceived( headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], stream_id=stream_id, stream_ended=True, ) ], ) ===========changed ref 3=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 4=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - ===========changed ref 5=========== # module: examples.http3_client class WebSocket: def http_event_received(self, event: HttpEvent): + if isinstance(event, HeadersReceived): - if isinstance(event, ResponseReceived): for header, value in event.headers: if header == b"sec-websocket-protocol": self.subprotocol = value.decode("utf8") elif isinstance(event, DataReceived): self.websocket.receive_data(event.data) for ws_event in self.websocket.events(): self.websocket_event_received(ws_event) ===========changed ref 6=========== # module: aioquic.h3.events - @dataclass - class ResponseReceived(HttpEvent): - """ - The ResponseReceived event is fired whenever response headers are received. - """ - - headers: Headers - "The response headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - - push_id: Optional[int] = None - "The Push ID or `None` if this is not a push." -
examples.http3_server/HttpServerProtocol.http_event_received
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
<0>:<add> if isinstance(event, HeadersReceived) and event.stream_id not in self._handlers: <del> if isinstance(event, RequestReceived) and event.stream_id not in self._handlers:
# module: examples.http3_server class HttpServerProtocol(QuicConnectionProtocol): def http_event_received(self, event: HttpEvent) -> None: <0> if isinstance(event, RequestReceived) and event.stream_id not in self._handlers: <1> headers = [] <2> http_version = "0.9" if isinstance(self._http, H0Connection) else "3" <3> raw_path = b"" <4> method = "" <5> protocol = None <6> for header, value in event.headers: <7> if header == b":authority": <8> headers.append((b"host", value)) <9> elif header == b":method": <10> method = value.decode("utf8") <11> elif header == b":path": <12> raw_path = value <13> elif header == b":protocol": <14> protocol = value.decode("utf8") <15> elif header and not header.startswith(b":"): <16> headers.append((header, value)) <17> <18> if b"?" in raw_path: <19> path_bytes, query_string = raw_path.split(b"?", maxsplit=1) <20> else: <21> path_bytes, query_string = raw_path, b"" <22> path = path_bytes.decode("utf8") <23> <24> handler: Handler <25> if method == "CONNECT" and protocol == "websocket": <26> subprotocols: List[str] = [] <27> for header, value in event.headers: <28> if header == b"sec-websocket-protocol": <29> subprotocols = [ <30> x.strip() for x in value.decode("utf8").split(",") <31> ] <32> scope = { <33> "headers": headers, <34> "http_version": http_version, <35> "method": method, <36> "path": path, <37> "query_string": query_string, <38> "raw_path": raw_path, <39> "root_path": "", <40> "scheme": "wss", <41> "subprotocols": subprotocols, <42> "type": "websocket",</s>
===========below chunk 0=========== # module: examples.http3_server class HttpServerProtocol(QuicConnectionProtocol): def http_event_received(self, event: HttpEvent) -> None: # offset: 1 handler = WebSocketHandler( connection=self._http, scope=scope, stream_id=event.stream_id, transmit=self.transmit, ) else: scope = { "headers": headers, "http_version": http_version, "method": method, "path": path, "query_string": query_string, "raw_path": raw_path, "root_path": "", "scheme": "https", "type": "http", } handler = HttpRequestHandler( connection=self._http, scope=scope, stream_ended=event.stream_ended, stream_id=event.stream_id, transmit=self.transmit, ) self._handlers[event.stream_id] = handler asyncio.ensure_future(handler.run_asgi(application)) elif isinstance(event, DataReceived) and event.stream_id in self._handlers: handler = self._handlers[event.stream_id] handler.http_event_received(event) ===========unchanged ref 0=========== at: aioquic.asyncio.protocol.QuicConnectionProtocol transmit() -> None at: aioquic.h0.connection H0Connection(quic: QuicConnection) at: aioquic.h3.events HttpEvent() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: asyncio.tasks ensure_future(coro_or_future: _FutureT[_T], *, loop: Optional[AbstractEventLoop]=...) -> Future[_T] at: examples.http3_server HttpRequestHandler(*, connection: HttpConnection, scope: Dict, stream_ended: bool, stream_id: int, transmit: Callable[[], None]) WebSocketHandler(*, connection: HttpConnection, scope: Dict, stream_id: int, transmit: Callable[[], None]) Handler = Union[HttpRequestHandler, WebSocketHandler] application = getattr(module, attr_str) at: examples.http3_server.HttpServerProtocol.__init__ self._handlers: Dict[int, Handler] = {} self._http: Optional[HttpConnection] = None at: examples.http3_server.HttpServerProtocol.quic_event_received self._http = H3Connection(self._quic) self._http = H0Connection(self._quic) at: typing List = _alias(list, 1, inst=False, name='List') ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 1=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 2=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - ===========changed ref 3=========== # module: examples.http3_client class WebSocket: def http_event_received(self, event: HttpEvent): + if isinstance(event, HeadersReceived): - if isinstance(event, ResponseReceived): for header, value in event.headers: if header == b"sec-websocket-protocol": self.subprotocol = value.decode("utf8") elif isinstance(event, DataReceived): self.websocket.receive_data(event.data) for ws_event in self.websocket.events(): self.websocket_event_received(ws_event) ===========changed ref 4=========== # module: aioquic.h3.events - @dataclass - class ResponseReceived(HttpEvent): - """ - The ResponseReceived event is fired whenever response headers are received. - """ - - headers: Headers - "The response headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - - push_id: Optional[int] = None - "The Push ID or `None` if this is not a push." - ===========changed ref 5=========== # module: examples.interop def test_http_0(server: Server, configuration: QuicConfiguration): if server.path is None: return configuration.alpn_protocols = ["hq-22"] async with connect( server.host, server.port, configuration=configuration, create_protocol=HttpClient, ) as protocol: protocol = cast(HttpClient, protocol) # perform HTTP request events = await protocol.get(server.host, server.path) + if events and isinstance(events[0], HeadersReceived): - if events and isinstance(events[0], ResponseReceived): server.result |= Result.D ===========changed ref 6=========== # module: examples.interop def test_http_3(server: Server, configuration: QuicConfiguration): if server.path is None: return configuration.alpn_protocols = ["h3-22"] async with connect( server.host, server.port, configuration=configuration, create_protocol=HttpClient, ) as protocol: protocol = cast(HttpClient, protocol) # perform HTTP request events = await protocol.get(server.host, server.path) + if events and isinstance(events[0], HeadersReceived): - if events and isinstance(events[0], ResponseReceived): server.result |= Result.D server.result |= Result.three ===========changed ref 7=========== # module: examples.http3_client class HttpClient(QuicConnectionProtocol): def http_event_received(self, event: HttpEvent): + if isinstance(event, (HeadersReceived, DataReceived)): - if isinstance(event, (ResponseReceived, DataReceived)): stream_id = event.stream_id if stream_id in self._request_events: # http self._request_events[event.stream_id].append(event) if event.stream_ended: request_waiter = self._request_waiter.pop(stream_id) request_waiter.set_result(self._request_events.pop(stream_id)) elif stream_id in self._websockets: # websocket websocket = self._websockets[stream_id] websocket.http_event_received(event) else: # push print(event)
examples.httpx_client/H3Dispatcher.send
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
<31>:<add> if isinstance(event, HeadersReceived): <del> if isinstance(event, ResponseReceived):
# module: examples.httpx_client class H3Dispatcher(QuicConnectionProtocol, AsyncDispatcher): def send( self, request: AsyncRequest, verify: VerifyTypes = None, cert: CertTypes = None, timeout: TimeoutTypes = None, ) -> AsyncResponse: <0> stream_id = self._quic.get_next_available_stream_id() <1> <2> # prepare request <3> self._http.send_headers( <4> stream_id=stream_id, <5> headers=[ <6> (b":method", request.method.encode("utf8")), <7> (b":scheme", request.url.scheme.encode("utf8")), <8> (b":authority", str(request.url.authority).encode("utf8")), <9> (b":path", request.url.full_path.encode("utf8")), <10> ] <11> + [ <12> (k.encode("utf8"), v.encode("utf8")) <13> for (k, v) in request.headers.items() <14> if k not in ("connection", "host") <15> ], <16> ) <17> self._http.send_data(stream_id=stream_id, data=request.content, end_stream=True) <18> <19> # transmit request <20> waiter = self._loop.create_future() <21> self._request_events[stream_id] = deque() <22> self._request_waiter[stream_id] = waiter <23> self.transmit() <24> <25> # process response <26> events = await asyncio.shield(waiter) <27> content = b"" <28> headers = [] <29> status_code = None <30> for event in events: <31> if isinstance(event, ResponseReceived): <32> for header, value in event.headers: <33> if header == b":status": <34> status_code = int(value.decode("ascii")) <35> elif header[0:1] != b":": <36> headers.append((header.decode("utf8"), value.decode("utf8"))) <37> elif</s>
===========below chunk 0=========== # module: examples.httpx_client class H3Dispatcher(QuicConnectionProtocol, AsyncDispatcher): def send( self, request: AsyncRequest, verify: VerifyTypes = None, cert: CertTypes = None, timeout: TimeoutTypes = None, ) -> AsyncResponse: # offset: 1 content += event.data return AsyncResponse( status_code=status_code, protocol="HTTP/3", headers=headers, content=content, # on_close=on_close, request=request, ) ===========unchanged ref 0=========== at: aioquic.asyncio.protocol.QuicConnectionProtocol transmit() -> None at: aioquic.asyncio.protocol.QuicConnectionProtocol.__init__ self._loop = loop self._quic = quic at: aioquic.h3.connection.H3Connection send_data(stream_id: int, data: bytes, end_stream: bool) -> None send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.events DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.quic.connection.QuicConnection get_next_available_stream_id(is_unidirectional=False) -> int at: asyncio.events.AbstractEventLoop create_future() -> Future[Any] at: asyncio.tasks shield(arg: _FutureT[_T], *, loop: Optional[AbstractEventLoop]=...) -> Future[_T] at: collections deque(iterable: Iterable[_T]=..., maxlen: Optional[int]=...) at: examples.httpx_client.H3Dispatcher.__init__ self._http = H3Connection(self._quic) self._request_events: Dict[int, Deque[HttpEvent]] = {} self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {} ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 1=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 2=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - ===========changed ref 3=========== # module: examples.http3_client class WebSocket: def http_event_received(self, event: HttpEvent): + if isinstance(event, HeadersReceived): - if isinstance(event, ResponseReceived): for header, value in event.headers: if header == b"sec-websocket-protocol": self.subprotocol = value.decode("utf8") elif isinstance(event, DataReceived): self.websocket.receive_data(event.data) for ws_event in self.websocket.events(): self.websocket_event_received(ws_event) ===========changed ref 4=========== # module: aioquic.h3.events - @dataclass - class ResponseReceived(HttpEvent): - """ - The ResponseReceived event is fired whenever response headers are received. - """ - - headers: Headers - "The response headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - - push_id: Optional[int] = None - "The Push ID or `None` if this is not a push." - ===========changed ref 5=========== # module: examples.interop def test_http_0(server: Server, configuration: QuicConfiguration): if server.path is None: return configuration.alpn_protocols = ["hq-22"] async with connect( server.host, server.port, configuration=configuration, create_protocol=HttpClient, ) as protocol: protocol = cast(HttpClient, protocol) # perform HTTP request events = await protocol.get(server.host, server.path) + if events and isinstance(events[0], HeadersReceived): - if events and isinstance(events[0], ResponseReceived): server.result |= Result.D ===========changed ref 6=========== # module: examples.interop def test_http_3(server: Server, configuration: QuicConfiguration): if server.path is None: return configuration.alpn_protocols = ["h3-22"] async with connect( server.host, server.port, configuration=configuration, create_protocol=HttpClient, ) as protocol: protocol = cast(HttpClient, protocol) # perform HTTP request events = await protocol.get(server.host, server.path) + if events and isinstance(events[0], HeadersReceived): - if events and isinstance(events[0], ResponseReceived): server.result |= Result.D server.result |= Result.three ===========changed ref 7=========== # module: examples.http3_client class HttpClient(QuicConnectionProtocol): def http_event_received(self, event: HttpEvent): + if isinstance(event, (HeadersReceived, DataReceived)): - if isinstance(event, (ResponseReceived, DataReceived)): stream_id = event.stream_id if stream_id in self._request_events: # http self._request_events[event.stream_id].append(event) if event.stream_ended: request_waiter = self._request_waiter.pop(stream_id) request_waiter.set_result(self._request_events.pop(stream_id)) elif stream_id in self._websockets: # websocket websocket = self._websockets[stream_id] websocket.http_event_received(event) else: # push print(event)
examples.httpx_client/H3Dispatcher.http_event_received
Modified
aiortc~aioquic
5d57a3b2d5ad10ee0132d6a6fef3ec69e0ea78a3
[http3] merge RequestReceived and ResponseReceived into HeadersReceived
<0>:<add> if isinstance(event, (HeadersReceived, DataReceived)): <del> if isinstance(event, (ResponseReceived, DataReceived)):
# module: examples.httpx_client class H3Dispatcher(QuicConnectionProtocol, AsyncDispatcher): def http_event_received(self, event: HttpEvent): <0> if isinstance(event, (ResponseReceived, DataReceived)): <1> stream_id = event.stream_id <2> if stream_id in self._request_events: <3> self._request_events[event.stream_id].append(event) <4> if event.stream_ended: <5> request_waiter = self._request_waiter.pop(stream_id) <6> request_waiter.set_result(self._request_events.pop(stream_id)) <7>
===========unchanged ref 0=========== at: _asyncio.Future set_result(result, /) at: aioquic.h3.events HttpEvent() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: asyncio.futures.Future _state = _PENDING _result = None _exception = None _loop = None _source_traceback = None _cancel_message = None _cancelled_exc = None _asyncio_future_blocking = False __log_traceback = False __class_getitem__ = classmethod(GenericAlias) set_result(result: _T, /) -> None __iter__ = __await__ # make compatible with 'yield from'. at: collections.deque append(x: _T) -> None at: examples.httpx_client.H3Dispatcher.__init__ self._request_events: Dict[int, Deque[HttpEvent]] = {} self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {} at: typing.MutableMapping pop(key: _KT) -> _VT pop(key: _KT, default: Union[_VT, _T]=...) -> Union[_VT, _T] ===========changed ref 0=========== # module: aioquic.h3.events + @dataclass + class HeadersReceived(HttpEvent): + """ + The HeadersReceived event is fired whenever headers are received. + """ + + headers: Headers + "The headers." + + stream_id: int + "The ID of the stream the headers were received for." + + stream_ended: bool + "Whether the STREAM frame had the FIN bit set." + + push_id: Optional[int] = None + "The Push ID or `None` if this is not a push." + ===========changed ref 1=========== # module: examples.httpx_client class H3Dispatcher(QuicConnectionProtocol, AsyncDispatcher): def send( self, request: AsyncRequest, verify: VerifyTypes = None, cert: CertTypes = None, timeout: TimeoutTypes = None, ) -> AsyncResponse: stream_id = self._quic.get_next_available_stream_id() # prepare request self._http.send_headers( stream_id=stream_id, headers=[ (b":method", request.method.encode("utf8")), (b":scheme", request.url.scheme.encode("utf8")), (b":authority", str(request.url.authority).encode("utf8")), (b":path", request.url.full_path.encode("utf8")), ] + [ (k.encode("utf8"), v.encode("utf8")) for (k, v) in request.headers.items() if k not in ("connection", "host") ], ) self._http.send_data(stream_id=stream_id, data=request.content, end_stream=True) # transmit request waiter = self._loop.create_future() self._request_events[stream_id] = deque() self._request_waiter[stream_id] = waiter self.transmit() # process response events = await asyncio.shield(waiter) content = b"" headers = [] status_code = None for event in events: + if isinstance(event, HeadersReceived): - if isinstance(event, ResponseReceived): for header, value in event.headers: if header == b":status": status_code = int(value.decode("ascii")) elif header[0:1] != b":": headers.append((header.decode("utf8"), value.decode("utf8"))) elif isinstance(event, DataReceived): content += event.data return AsyncResponse( status_code</s> ===========changed ref 2=========== # module: examples.httpx_client class H3Dispatcher(QuicConnectionProtocol, AsyncDispatcher): def send( self, request: AsyncRequest, verify: VerifyTypes = None, cert: CertTypes = None, timeout: TimeoutTypes = None, ) -> AsyncResponse: # offset: 1 <s>))) elif isinstance(event, DataReceived): content += event.data return AsyncResponse( status_code=status_code, protocol="HTTP/3", headers=headers, content=content, # on_close=on_close, request=request, ) ===========changed ref 3=========== # module: aioquic.h3.events + # backwards compatibility + RequestReceived = ResponseReceived = HeadersReceived ===========changed ref 4=========== # module: aioquic.h3.events - @dataclass - class RequestReceived(HttpEvent): - """ - The RequestReceived event is fired whenever request headers are received. - """ - - headers: Headers - "The request headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - ===========changed ref 5=========== # module: examples.http3_client class WebSocket: def http_event_received(self, event: HttpEvent): + if isinstance(event, HeadersReceived): - if isinstance(event, ResponseReceived): for header, value in event.headers: if header == b"sec-websocket-protocol": self.subprotocol = value.decode("utf8") elif isinstance(event, DataReceived): self.websocket.receive_data(event.data) for ws_event in self.websocket.events(): self.websocket_event_received(ws_event) ===========changed ref 6=========== # module: aioquic.h3.events - @dataclass - class ResponseReceived(HttpEvent): - """ - The ResponseReceived event is fired whenever response headers are received. - """ - - headers: Headers - "The response headers." - - stream_id: int - "The ID of the stream the headers were received for." - - stream_ended: bool - "Whether the STREAM frame had the FIN bit set." - - push_id: Optional[int] = None - "The Push ID or `None` if this is not a push." - ===========changed ref 7=========== # module: examples.interop def test_http_0(server: Server, configuration: QuicConfiguration): if server.path is None: return configuration.alpn_protocols = ["hq-22"] async with connect( server.host, server.port, configuration=configuration, create_protocol=HttpClient, ) as protocol: protocol = cast(HttpClient, protocol) # perform HTTP request events = await protocol.get(server.host, server.path) + if events and isinstance(events[0], HeadersReceived): - if events and isinstance(events[0], ResponseReceived): server.result |= Result.D ===========changed ref 8=========== # module: examples.interop def test_http_3(server: Server, configuration: QuicConfiguration): if server.path is None: return configuration.alpn_protocols = ["h3-22"] async with connect( server.host, server.port, configuration=configuration, create_protocol=HttpClient, ) as protocol: protocol = cast(HttpClient, protocol) # perform HTTP request events = await protocol.get(server.host, server.path) + if events and isinstance(events[0], HeadersReceived): - if events and isinstance(events[0], ResponseReceived): server.result |= Result.D server.result |= Result.three
tests.test_h3/H3ConnectionTest.test_request_fragmented_frame
Modified
aiortc~aioquic
993790505b6e9913903a1c5190eb2a43f917d408
[http3] rename `push_promise` to `send_push_promise`
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_fragmented_frame(self): <0> quic_client = FakeQuicConnection( <1> configuration=QuicConfiguration(is_client=True) <2> ) <3> quic_server = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=False) <5> ) <6> <7> h3_client = H3Connection(quic_client) <8> h3_server = H3Connection(quic_server) <9> <10> # send request <11> stream_id = quic_client.get_next_available_stream_id() <12> h3_client.send_headers( <13> stream_id=stream_id, <14> headers=[ <15> (b":method", b"GET"), <16> (b":scheme", b"https"), <17> (b":authority", b"localhost"), <18> (b":path", b"/"), <19> (b"x-foo", b"client"), <20> ], <21> ) <22> h3_client.send_data(stream_id=stream_id, data=b"hello", end_stream=True) <23> <24> # receive request <25> events = h3_transfer(quic_client, h3_server) <26> self.assertEqual( <27> events, <28> [ <29> HeadersReceived( <30> headers=[ <31> (b":method", b"GET"), <32> (b":scheme", b"https"), <33> (b":authority", b"localhost"), <34> (b":path", b"/"), <35> (b"x-foo", b"client"), <36> ], <37> stream_id=stream_id, <38> stream_ended=False, <39> ), <40> DataReceived(data=b"h", stream_id=0, stream_ended=False), <41> DataReceived(data=b"e", stream_id=0, stream_ended=False), <42> DataReceived(data=b"l", stream</s>
===========below chunk 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_fragmented_frame(self): # offset: 1 DataReceived(data=b"l", stream_id=0, stream_ended=False), DataReceived(data=b"o", stream_id=0, stream_ended=False), DataReceived(data=b"", stream_id=0, stream_ended=True), ], ) # send push promise push_stream_id = h3_server.push_promise( stream_id=stream_id, headers=[ (b":method", b"GET"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/app.txt"), ], ) self.assertEqual(push_stream_id, 15) # send response h3_server.send_headers( stream_id=stream_id, headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), ], end_stream=False, ) h3_server.send_data(stream_id=stream_id, data=b"html", end_stream=True) #  fulfill push promise h3_server.send_headers( stream_id=push_stream_id, headers=[(b":status", b"200"), (b"content-type", b"text/plain")], end_stream=False, ) h3_server.send_data(stream_id=push_stream_id, data=b"text", end_stream=True) # receive push promise / reponse events = h3_transfer(quic_server, h3_client) self.assertEqual( events, [ PushPromiseReceived( headers=[ (b":method", b"GET"), (b":</s> ===========below chunk 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_fragmented_frame(self): # offset: 2 <s> [ PushPromiseReceived( headers=[ (b":method", b"GET"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/app.txt"), ], push_id=0, stream_id=stream_id, ), HeadersReceived( headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), ], stream_id=0, stream_ended=False, ), DataReceived(data=b"h", stream_id=0, stream_ended=False), DataReceived(data=b"t", stream_id=0, stream_ended=False), DataReceived(data=b"m", stream_id=0, stream_ended=False), DataReceived(data=b"l", stream_id=0, stream_ended=False), DataReceived(data=b"", stream_id=0, stream_ended=True), HeadersReceived( headers=[(b":status", b"200"), (b"content-type", b"text/plain")], stream_id=15, stream_ended=False, push_id=0, ), DataReceived(data=b"text", stream_id=15, stream_ended=False, push_id=0), ], ) ===========unchanged ref 0=========== at: aioquic.h3.connection H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection send_push_promise(stream_id: int, headers: Headers) -> int send_data(stream_id: int, data: bytes, end_stream: bool) -> None send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.events DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) PushPromiseReceived(headers: Headers, push_id: int, stream_id: int) at: aioquic.h3.events.DataReceived data: bytes stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.HeadersReceived headers: Headers stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.PushPromiseReceived headers: Headers push_id: int stream_id: int at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) ===========unchanged ref 1=========== at: aioquic.quic.configuration.QuicConfiguration alpn_protocols: Optional[List[str]] = None certificate: Any = None connection_id_length: int = 8 idle_timeout: float = 60.0 is_client: bool = True private_key: Any = None quic_logger: Optional[QuicLogger] = None secrets_log_file: TextIO = None server_name: Optional[str] = None session_ticket: Optional[SessionTicket] = None supported_versions: List[int] = field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] ) at: tests.test_h3 h3_transfer(quic_sender, h3_receiver) FakeQuicConnection(configuration) at: tests.test_h3.FakeQuicConnection get_next_available_stream_id(is_unidirectional=False) at: tests.test_h3.H3ConnectionTest maxDiff = None at: unittest.case.TestCase failureException: Type[BaseException] longMessage: bool maxDiff: Optional[int] _testMethodName: str _testMethodDoc: str assertEqual(first: Any, second: Any, msg: Any=...) -> None
aioquic.h3.connection/H3Connection._receive_stream_data_uni
Modified
aiortc~aioquic
e6ec053e4c5be31b8f91b425fc60a562a8d3a912
[http3] avoid endless loop for unknown uni stream types
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: <0> http_events: List[HttpEvent] = [] <1> <2> stream = self._stream[stream_id] <3> stream.buffer += data <4> if stream_ended: <5> stream.ended = True <6> <7> buf = Buffer(data=stream.buffer) <8> consumed = 0 <9> unblocked_streams: Set[int] = set() <10> <11> while not buf.eof(): <12> # fetch stream type for unidirectional streams <13> if stream.stream_type is None: <14> try: <15> stream.stream_type = buf.pull_uint_var() <16> except BufferReadError: <17> break <18> consumed = buf.tell() <19> <20> # check unicity <21> if stream.stream_type == StreamType.CONTROL: <22> assert self._peer_control_stream_id is None <23> self._peer_control_stream_id = stream_id <24> elif stream.stream_type == StreamType.QPACK_DECODER: <25> assert self._peer_decoder_stream_id is None <26> self._peer_decoder_stream_id = stream_id <27> elif stream.stream_type == StreamType.QPACK_ENCODER: <28> assert self._peer_encoder_stream_id is None <29> self._peer_encoder_stream_id = stream_id <30> <31> if stream.stream_type == StreamType.CONTROL: <32> # fetch next frame <33> try: <34> frame_type = buf.pull_uint_var() <35> frame_length = buf.pull_uint_var() <36> frame_data = buf.pull_bytes(frame_length) <37> except BufferReadError: <38> break <39> consumed = buf.tell() <40> <41> self._handle_control_frame(frame_type, frame_data) <42> elif stream.stream_</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: # offset: 1 # fetch push id if stream.push_id is None: try: stream.push_id = buf.pull_uint_var() except BufferReadError: break consumed = buf.tell() # fetch next frame try: frame_type = buf.pull_uint_var() frame_length = buf.pull_uint_var() frame_data = buf.pull_bytes(frame_length) except BufferReadError: break consumed = buf.tell() http_events.extend( self._handle_push_frame( frame_type=frame_type, frame_data=frame_data, push_id=stream.push_id, stream_id=stream_id, stream_ended=stream.ended and buf.eof(), ) ) elif stream.stream_type == StreamType.QPACK_DECODER: # feed unframed data to decoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() self._encoder.feed_decoder(data) elif stream.stream_type == StreamType.QPACK_ENCODER: # feed unframed data to encoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() unblocked_streams.update(self._decoder.feed_encoder(data)) # remove processed data from buffer stream.buffer = stream.buffer[consumed:] # process unblocked streams for stream_id in unblocked_streams: stream = self._stream[stream_id] decoder, headers = self._decoder.resume_header(stream_id) stream.blocked = False http_events.append( HeadersReceived</s> ===========below chunk 1=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[HttpEvent]: # offset: 2 <s>._decoder.resume_header(stream_id) stream.blocked = False http_events.append( HeadersReceived( headers=headers, stream_id=stream_id, stream_ended=stream.ended and not stream.buffer, ) ) http_events.extend( self._receive_stream_data_bidi(stream_id, b"", stream.ended) ) return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.h3.connection StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) at: aioquic.h3.connection.H3Connection _handle_control_frame(frame_type: int, frame_data: bytes) -> None _handle_push_frame(frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[HttpEvent] at: aioquic.h3.connection.H3Connection.__init__ self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None at: aioquic.h3.connection.H3Stream.__init__ self.buffer = b"" self.ended = False self.push_id: Optional[int] = None self.stream_type: Optional[int] = None at: aioquic.h3.events HttpEvent() HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: typing List = _alias(list, 1, inst=False, name='List') Set = _alias(set, 1, inst=False, name='Set')
aioquic.h3.connection/H3Connection.send_push_promise
Modified
aiortc~aioquic
1a83d7684ff29a526b9c961402070d82a0f60009
[examples] add ASGI bindings for server push
<9>:<add> if self._max_push_id is None or self._next_push_id >= self._max_push_id: <del> assert self._max_push_id is not None and self._next_push_id < self._max_push_id <10>:<add> raise NoAvailablePushIDError
# module: aioquic.h3.connection class H3Connection: def send_push_promise(self, stream_id: int, headers: Headers) -> int: <0> """ <1> Send a push promise related to the specified stream. <2> <3> Returns the stream ID on which headers and data can be sent. <4> <5> :param stream_id: The stream ID on which to send the data. <6> :param headers: The HTTP request headers for this push. <7> """ <8> assert not self._is_client, "Only servers may send a push promise." <9> assert self._max_push_id is not None and self._next_push_id < self._max_push_id <10> <11> # send push promise <12> push_id = self._next_push_id <13> self._next_push_id += 1 <14> self._quic.send_stream_data( <15> stream_id, <16> encode_frame( <17> FrameType.PUSH_PROMISE, <18> encode_uint_var(push_id) + self._encode_headers(stream_id, headers), <19> ), <20> ) <21> <22> #  create push stream <23> push_stream_id = self._create_uni_stream(StreamType.PUSH) <24> self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id)) <25> <26> return push_stream_id <27>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) encode_frame(frame_type: int, frame_data: bytes) -> bytes at: aioquic.h3.connection.H3Connection _create_uni_stream(stream_type: int) -> int _encode_headers(stream_id, headers: Headers) -> bytes at: aioquic.h3.connection.H3Connection.__init__ self._is_client = quic.configuration.is_client self._quic = quic self._max_push_id: Optional[int] = 8 if self._is_client else None self._next_push_id: int = 0 at: aioquic.h3.connection.H3Connection._handle_control_frame self._max_push_id = parse_max_push_id(frame_data) at: aioquic.h3.events Headers = List[Tuple[bytes, bytes]] at: aioquic.h3.exceptions NoAvailablePushIDError(*args: object) at: aioquic.quic.connection.QuicConnection send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None ===========changed ref 0=========== + # module: aioquic.h3.exceptions + class NoAvailablePushIDError(H3Error): + """ + There are no available push IDs left. + """ + ===========changed ref 1=========== + # module: aioquic.h3.exceptions + + ===========changed ref 2=========== + # module: aioquic.h3.exceptions + class H3Error(Exception): + """ + Base class for HTTP/3 exceptions. + """ +
aioquic.h3.connection/H3Connection._init_connection
Modified
aiortc~aioquic
1a83d7684ff29a526b9c961402070d82a0f60009
[examples] add ASGI bindings for server push
<14>:<add> if self._is_client and self._max_push_id is not None: <del> if self._is_client:
# module: aioquic.h3.connection class H3Connection: def _init_connection(self) -> None: <0> # send our settings <1> self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL) <2> self._quic.send_stream_data( <3> self._local_control_stream_id, <4> encode_frame( <5> FrameType.SETTINGS, <6> encode_settings( <7> { <8> Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity, <9> Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams, <10> } <11> ), <12> ), <13> ) <14> if self._is_client: <15> self._quic.send_stream_data( <16> self._local_control_stream_id, <17> encode_frame(FrameType.MAX_PUSH_ID, encode_uint_var(self._max_push_id)), <18> ) <19> <20> # create encoder and decoder streams <21> self._local_encoder_stream_id = self._create_uni_stream( <22> StreamType.QPACK_ENCODER <23> ) <24> self._local_decoder_stream_id = self._create_uni_stream( <25> StreamType.QPACK_DECODER <26> ) <27>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) Setting(x: Union[str, bytes, bytearray], base: int) Setting(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) encode_frame(frame_type: int, frame_data: bytes) -> bytes encode_settings(settings: Dict[int, int]) -> bytes at: aioquic.h3.connection.H3Connection _create_uni_stream(stream_type: int) -> int at: aioquic.h3.connection.H3Connection.__init__ self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client self._quic = quic self._max_push_id: Optional[int] = 8 if self._is_client else None self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None at: aioquic.h3.connection.H3Connection._handle_control_frame self._max_push_id = parse_max_push_id(frame_data) at: aioquic.h3.connection.H3Connection._handle_push_frame http_events: List[HttpEvent] = [] ===========unchanged ref 1=========== at: aioquic.quic.connection.QuicConnection send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def send_push_promise(self, stream_id: int, headers: Headers) -> int: """ Send a push promise related to the specified stream. Returns the stream ID on which headers and data can be sent. :param stream_id: The stream ID on which to send the data. :param headers: The HTTP request headers for this push. """ assert not self._is_client, "Only servers may send a push promise." + if self._max_push_id is None or self._next_push_id >= self._max_push_id: - assert self._max_push_id is not None and self._next_push_id < self._max_push_id + raise NoAvailablePushIDError # send push promise push_id = self._next_push_id self._next_push_id += 1 self._quic.send_stream_data( stream_id, encode_frame( FrameType.PUSH_PROMISE, encode_uint_var(push_id) + self._encode_headers(stream_id, headers), ), ) #  create push stream push_stream_id = self._create_uni_stream(StreamType.PUSH) self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id)) return push_stream_id ===========changed ref 1=========== + # module: aioquic.h3.exceptions + + ===========changed ref 2=========== + # module: aioquic.h3.exceptions + class NoAvailablePushIDError(H3Error): + """ + There are no available push IDs left. + """ + ===========changed ref 3=========== + # module: aioquic.h3.exceptions + class H3Error(Exception): + """ + Base class for HTTP/3 exceptions. + """ +
examples.demo/homepage
Modified
aiortc~aioquic
1a83d7684ff29a526b9c961402070d82a0f60009
[examples] add ASGI bindings for server push
<3>:<add> await request.send_push_promise("/style.css")
# module: examples.demo @app.route("/") async def homepage(request): <0> """ <1> Simple homepage. <2> """ <3> return templates.TemplateResponse("index.html", {"request": request}) <4>
===========unchanged ref 0=========== at: examples.demo app = Starlette() ===========changed ref 0=========== + # module: aioquic.h3.exceptions + + ===========changed ref 1=========== + # module: aioquic.h3.exceptions + class NoAvailablePushIDError(H3Error): + """ + There are no available push IDs left. + """ + ===========changed ref 2=========== + # module: aioquic.h3.exceptions + class H3Error(Exception): + """ + Base class for HTTP/3 exceptions. + """ + ===========changed ref 3=========== # module: aioquic.h3.connection class H3Connection: def _init_connection(self) -> None: # send our settings self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL) self._quic.send_stream_data( self._local_control_stream_id, encode_frame( FrameType.SETTINGS, encode_settings( { Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity, Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams, } ), ), ) + if self._is_client and self._max_push_id is not None: - if self._is_client: self._quic.send_stream_data( self._local_control_stream_id, encode_frame(FrameType.MAX_PUSH_ID, encode_uint_var(self._max_push_id)), ) # create encoder and decoder streams self._local_encoder_stream_id = self._create_uni_stream( StreamType.QPACK_ENCODER ) self._local_decoder_stream_id = self._create_uni_stream( StreamType.QPACK_DECODER ) ===========changed ref 4=========== # module: aioquic.h3.connection class H3Connection: def send_push_promise(self, stream_id: int, headers: Headers) -> int: """ Send a push promise related to the specified stream. Returns the stream ID on which headers and data can be sent. :param stream_id: The stream ID on which to send the data. :param headers: The HTTP request headers for this push. """ assert not self._is_client, "Only servers may send a push promise." + if self._max_push_id is None or self._next_push_id >= self._max_push_id: - assert self._max_push_id is not None and self._next_push_id < self._max_push_id + raise NoAvailablePushIDError # send push promise push_id = self._next_push_id self._next_push_id += 1 self._quic.send_stream_data( stream_id, encode_frame( FrameType.PUSH_PROMISE, encode_uint_var(push_id) + self._encode_headers(stream_id, headers), ), ) #  create push stream push_stream_id = self._create_uni_stream(StreamType.PUSH) self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id)) return push_stream_id
examples.http3_server/HttpRequestHandler.__init__
Modified
aiortc~aioquic
1a83d7684ff29a526b9c961402070d82a0f60009
[examples] add ASGI bindings for server push
<0>:<add> self.authority = authority <1>:<add> self.protocol = protocol
# module: examples.http3_server class HttpRequestHandler: def __init__( self, *, + authority: bytes, connection: HttpConnection, + protocol: QuicConnectionProtocol, scope: Dict, stream_ended: bool, stream_id: int, transmit: Callable[[], None], ): <0> self.connection = connection <1> self.queue: asyncio.Queue[Dict] = asyncio.Queue() <2> self.scope = scope <3> self.stream_id = stream_id <4> self.transmit = transmit <5> <6> if stream_ended: <7> self.queue.put_nowait({"type": "http.request"}) <8>
===========unchanged ref 0=========== at: aioquic.asyncio.protocol QuicConnectionProtocol(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None) at: asyncio.queues Queue(maxsize: int=..., *, loop: Optional[AbstractEventLoop]=...) at: examples.http3_server HttpConnection = Union[H0Connection, H3Connection] at: typing Callable = _CallableType(collections.abc.Callable, 2) Dict = _alias(dict, 2, inst=False, name='Dict') ===========changed ref 0=========== + # module: aioquic.h3.exceptions + + ===========changed ref 1=========== + # module: aioquic.h3.exceptions + class NoAvailablePushIDError(H3Error): + """ + There are no available push IDs left. + """ + ===========changed ref 2=========== + # module: aioquic.h3.exceptions + class H3Error(Exception): + """ + Base class for HTTP/3 exceptions. + """ + ===========changed ref 3=========== # module: examples.demo @app.route("/") async def homepage(request): """ Simple homepage. """ + await request.send_push_promise("/style.css") return templates.TemplateResponse("index.html", {"request": request}) ===========changed ref 4=========== # module: aioquic.h3.connection class H3Connection: def _init_connection(self) -> None: # send our settings self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL) self._quic.send_stream_data( self._local_control_stream_id, encode_frame( FrameType.SETTINGS, encode_settings( { Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity, Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams, } ), ), ) + if self._is_client and self._max_push_id is not None: - if self._is_client: self._quic.send_stream_data( self._local_control_stream_id, encode_frame(FrameType.MAX_PUSH_ID, encode_uint_var(self._max_push_id)), ) # create encoder and decoder streams self._local_encoder_stream_id = self._create_uni_stream( StreamType.QPACK_ENCODER ) self._local_decoder_stream_id = self._create_uni_stream( StreamType.QPACK_DECODER ) ===========changed ref 5=========== # module: aioquic.h3.connection class H3Connection: def send_push_promise(self, stream_id: int, headers: Headers) -> int: """ Send a push promise related to the specified stream. Returns the stream ID on which headers and data can be sent. :param stream_id: The stream ID on which to send the data. :param headers: The HTTP request headers for this push. """ assert not self._is_client, "Only servers may send a push promise." + if self._max_push_id is None or self._next_push_id >= self._max_push_id: - assert self._max_push_id is not None and self._next_push_id < self._max_push_id + raise NoAvailablePushIDError # send push promise push_id = self._next_push_id self._next_push_id += 1 self._quic.send_stream_data( stream_id, encode_frame( FrameType.PUSH_PROMISE, encode_uint_var(push_id) + self._encode_headers(stream_id, headers), ), ) #  create push stream push_stream_id = self._create_uni_stream(StreamType.PUSH) self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id)) return push_stream_id ===========changed ref 6=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): + def test_request_with_server_push_max_push_id(self): + with client_and_server( + client_options={"alpn_protocols": ["h3-22"]}, + server_options={"alpn_protocols": ["h3-22"]}, + ) as (quic_client, quic_server): + h3_client = H3Connection(quic_client) + h3_server = H3Connection(quic_server) + + # send request + stream_id = quic_client.get_next_available_stream_id() + h3_client.send_headers( + stream_id=stream_id, + headers=[ + (b":method", b"GET"), + (b":scheme", b"https"), + (b":authority", b"localhost"), + (b":path", b"/"), + ], + end_stream=True, + ) + + # receive request + events = h3_transfer(quic_client, h3_server) + self.assertEqual( + events, + [ + HeadersReceived( + headers=[ + (b":method", b"GET"), + (b":scheme", b"https"), + (b":authority", b"localhost"), + (b":path", b"/"), + ], + stream_id=stream_id, + stream_ended=True, + ) + ], + ) + + # send push promises + for i in range(0, 8): + h3_server.send_push_promise( + stream_id=stream_id, + headers=[ + (b":method", b"GET"), + (b":scheme", b"https"), + (b":authority", b"localhost"), + (b":path",</s> ===========changed ref 7=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): + def test_request_with_server_push_max_push_id(self): # offset: 1 <s>b":scheme", b"https"), + (b":authority", b"localhost"), + (b":path", "/{}.css".format(i).encode("ascii")), + ], + ) + + # send one too many + with self.assertRaises(NoAvailablePushIDError): + h3_server.send_push_promise( + stream_id=stream_id, + headers=[ + (b":method", b"GET"), + (b":scheme", b"https"), + (b":authority", b"localhost"), + (b":path", b"/8.css"), + ], + ) +
examples.http3_server/HttpRequestHandler.send
Modified
aiortc~aioquic
1a83d7684ff29a526b9c961402070d82a0f60009
[examples] add ASGI bindings for server push
<16>:<add> elif message["type"] == "http.response.push" and isinstance( <add> self.connection, H3Connection <add> ): <add> request_headers = [ <add> (b":method", b"GET"), <add> (b":scheme", b"https"), <add> (b":authority", self.authority), <add> (b":path", message["path"].encode("utf8")), <add> ] + [(k, v) for k, v in message["headers"]] <add> <add> # send push promise <add> try: <add> push_stream_id = self.connection.send_push_promise( <add> stream_id=self.stream_id, headers=request_headers <add> ) <add> except NoAvailablePushIDError: <add> return <add> <add> # fake request <add> self.protocol.http_event_received( <add> HeadersReceived( <add> headers=request_headers, stream_ended=True, stream_id=push_stream_id
# module: examples.http3_server class HttpRequestHandler: def send(self, message: Dict): <0> if message["type"] == "http.response.start": <1> self.connection.send_headers( <2> stream_id=self.stream_id, <3> headers=[ <4> (b":status", str(message["status"]).encode("ascii")), <5> (b"server", b"aioquic"), <6> (b"date", formatdate(time.time(), usegmt=True).encode()), <7> ] <8> + [(k, v) for k, v in message["headers"]], <9> ) <10> elif message["type"] == "http.response.body": <11> self.connection.send_data( <12> stream_id=self.stream_id, <13> data=message.get("body", b""), <14> end_stream=not message.get("more_body", False), <15> ) <16> self.transmit() <17>
===========unchanged ref 0=========== at: aioquic.h0.connection.H0Connection send_data(stream_id: int, data: bytes, end_stream: bool) -> None send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.connection.H3Connection send_data(stream_id: int, data: bytes, end_stream: bool) -> None send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: asyncio.queues.Queue __class_getitem__ = classmethod(GenericAlias) get() -> _T at: email.utils formatdate(timeval: Optional[float]=..., localtime: bool=..., usegmt: bool=...) -> str at: examples.http3_server application = getattr(module, attr_str) at: examples.http3_server.HttpRequestHandler.__init__ self.connection = connection self.queue: asyncio.Queue[Dict] = asyncio.Queue() self.scope = scope self.stream_id = stream_id at: time time() -> float at: typing Dict = _alias(dict, 2, inst=False, name='Dict') ===========changed ref 0=========== # module: examples.http3_server class HttpRequestHandler: def __init__( self, *, + authority: bytes, connection: HttpConnection, + protocol: QuicConnectionProtocol, scope: Dict, stream_ended: bool, stream_id: int, transmit: Callable[[], None], ): + self.authority = authority self.connection = connection + self.protocol = protocol self.queue: asyncio.Queue[Dict] = asyncio.Queue() self.scope = scope self.stream_id = stream_id self.transmit = transmit if stream_ended: self.queue.put_nowait({"type": "http.request"}) ===========changed ref 1=========== + # module: aioquic.h3.exceptions + + ===========changed ref 2=========== + # module: aioquic.h3.exceptions + class NoAvailablePushIDError(H3Error): + """ + There are no available push IDs left. + """ + ===========changed ref 3=========== + # module: aioquic.h3.exceptions + class H3Error(Exception): + """ + Base class for HTTP/3 exceptions. + """ + ===========changed ref 4=========== # module: examples.demo @app.route("/") async def homepage(request): """ Simple homepage. """ + await request.send_push_promise("/style.css") return templates.TemplateResponse("index.html", {"request": request}) ===========changed ref 5=========== # module: aioquic.h3.connection class H3Connection: def _init_connection(self) -> None: # send our settings self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL) self._quic.send_stream_data( self._local_control_stream_id, encode_frame( FrameType.SETTINGS, encode_settings( { Setting.QPACK_MAX_TABLE_CAPACITY: self._max_table_capacity, Setting.QPACK_BLOCKED_STREAMS: self._blocked_streams, } ), ), ) + if self._is_client and self._max_push_id is not None: - if self._is_client: self._quic.send_stream_data( self._local_control_stream_id, encode_frame(FrameType.MAX_PUSH_ID, encode_uint_var(self._max_push_id)), ) # create encoder and decoder streams self._local_encoder_stream_id = self._create_uni_stream( StreamType.QPACK_ENCODER ) self._local_decoder_stream_id = self._create_uni_stream( StreamType.QPACK_DECODER ) ===========changed ref 6=========== # module: aioquic.h3.connection class H3Connection: def send_push_promise(self, stream_id: int, headers: Headers) -> int: """ Send a push promise related to the specified stream. Returns the stream ID on which headers and data can be sent. :param stream_id: The stream ID on which to send the data. :param headers: The HTTP request headers for this push. """ assert not self._is_client, "Only servers may send a push promise." + if self._max_push_id is None or self._next_push_id >= self._max_push_id: - assert self._max_push_id is not None and self._next_push_id < self._max_push_id + raise NoAvailablePushIDError # send push promise push_id = self._next_push_id self._next_push_id += 1 self._quic.send_stream_data( stream_id, encode_frame( FrameType.PUSH_PROMISE, encode_uint_var(push_id) + self._encode_headers(stream_id, headers), ), ) #  create push stream push_stream_id = self._create_uni_stream(StreamType.PUSH) self._quic.send_stream_data(push_stream_id, encode_uint_var(push_id)) return push_stream_id ===========changed ref 7=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): + def test_request_with_server_push_max_push_id(self): + with client_and_server( + client_options={"alpn_protocols": ["h3-22"]}, + server_options={"alpn_protocols": ["h3-22"]}, + ) as (quic_client, quic_server): + h3_client = H3Connection(quic_client) + h3_server = H3Connection(quic_server) + + # send request + stream_id = quic_client.get_next_available_stream_id() + h3_client.send_headers( + stream_id=stream_id, + headers=[ + (b":method", b"GET"), + (b":scheme", b"https"), + (b":authority", b"localhost"), + (b":path", b"/"), + ], + end_stream=True, + ) + + # receive request + events = h3_transfer(quic_client, h3_server) + self.assertEqual( + events, + [ + HeadersReceived( + headers=[ + (b":method", b"GET"), + (b":scheme", b"https"), + (b":authority", b"localhost"), + (b":path", b"/"), + ], + stream_id=stream_id, + stream_ended=True, + ) + ], + ) + + # send push promises + for i in range(0, 8): + h3_server.send_push_promise( + stream_id=stream_id, + headers=[ + (b":method", b"GET"), + (b":scheme", b"https"), + (b":authority", b"localhost"), + (b":path",</s>
examples.http3_server/HttpServerProtocol.http_event_received
Modified
aiortc~aioquic
1a83d7684ff29a526b9c961402070d82a0f60009
[examples] add ASGI bindings for server push
<1>:<add> authority = None <8>:<add> authority = value
# module: examples.http3_server class HttpServerProtocol(QuicConnectionProtocol): def http_event_received(self, event: HttpEvent) -> None: <0> if isinstance(event, HeadersReceived) and event.stream_id not in self._handlers: <1> headers = [] <2> http_version = "0.9" if isinstance(self._http, H0Connection) else "3" <3> raw_path = b"" <4> method = "" <5> protocol = None <6> for header, value in event.headers: <7> if header == b":authority": <8> headers.append((b"host", value)) <9> elif header == b":method": <10> method = value.decode("utf8") <11> elif header == b":path": <12> raw_path = value <13> elif header == b":protocol": <14> protocol = value.decode("utf8") <15> elif header and not header.startswith(b":"): <16> headers.append((header, value)) <17> <18> if b"?" in raw_path: <19> path_bytes, query_string = raw_path.split(b"?", maxsplit=1) <20> else: <21> path_bytes, query_string = raw_path, b"" <22> path = path_bytes.decode("utf8") <23> <24> handler: Handler <25> if method == "CONNECT" and protocol == "websocket": <26> subprotocols: List[str] = [] <27> for header, value in event.headers: <28> if header == b"sec-websocket-protocol": <29> subprotocols = [ <30> x.strip() for x in value.decode("utf8").split(",") <31> ] <32> scope = { <33> "headers": headers, <34> "http_version": http_version, <35> "method": method, <36> "path": path, <37> "query_string": query_string, <38> "raw_path": raw_path, <39> "root_path": "", <40> "scheme": "wss", <41> "subprotocols": subprotocols, <42> "type": "websocket",</s>
===========below chunk 0=========== # module: examples.http3_server class HttpServerProtocol(QuicConnectionProtocol): def http_event_received(self, event: HttpEvent) -> None: # offset: 1 handler = WebSocketHandler( connection=self._http, scope=scope, stream_id=event.stream_id, transmit=self.transmit, ) else: scope = { "headers": headers, "http_version": http_version, "method": method, "path": path, "query_string": query_string, "raw_path": raw_path, "root_path": "", "scheme": "https", "type": "http", } handler = HttpRequestHandler( connection=self._http, scope=scope, stream_ended=event.stream_ended, stream_id=event.stream_id, transmit=self.transmit, ) self._handlers[event.stream_id] = handler asyncio.ensure_future(handler.run_asgi(application)) elif isinstance(event, DataReceived) and event.stream_id in self._handlers: handler = self._handlers[event.stream_id] handler.http_event_received(event) ===========unchanged ref 0=========== at: aioquic.asyncio.protocol QuicConnectionProtocol(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None) at: aioquic.asyncio.protocol.QuicConnectionProtocol __init__(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None) __init__(self, quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None) at: aioquic.h0.connection H0Connection(quic: QuicConnection) at: aioquic.h0.connection.H0Connection send_data(stream_id: int, data: bytes, end_stream: bool) -> None at: aioquic.h3.connection.H3Connection send_data(stream_id: int, data: bytes, end_stream: bool) -> None at: aioquic.h3.events HttpEvent() HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: examples.http3_server HttpConnection = Union[H0Connection, H3Connection] HttpRequestHandler(*, authority: bytes, connection: HttpConnection, protocol: QuicConnectionProtocol, scope: Dict, stream_ended: bool, stream_id: int, transmit: Callable[[], None]) WebSocketHandler(*, connection: HttpConnection, scope: Dict, stream_id: int, transmit: Callable[[], None]) at: examples.http3_server.HttpServerProtocol.quic_event_received self._http = H3Connection(self._quic) self._http = H0Connection(self._quic) at: examples.http3_server.WebSocketHandler.__init__ self.closed = False self.connection = connection self.stream_id = stream_id self.transmit = transmit self.websocket: Optional[wsproto.Connection] = None ===========unchanged ref 1=========== at: examples.http3_server.WebSocketHandler.send self.websocket = wsproto.Connection(wsproto.ConnectionType.SERVER) at: typing List = _alias(list, 1, inst=False, name='List') Dict = _alias(dict, 2, inst=False, name='Dict') at: typing.Mapping get(key: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T] get(key: _KT) -> Optional[_VT_co] ===========changed ref 0=========== # module: examples.http3_server class HttpRequestHandler: def __init__( self, *, + authority: bytes, connection: HttpConnection, + protocol: QuicConnectionProtocol, scope: Dict, stream_ended: bool, stream_id: int, transmit: Callable[[], None], ): + self.authority = authority self.connection = connection + self.protocol = protocol self.queue: asyncio.Queue[Dict] = asyncio.Queue() self.scope = scope self.stream_id = stream_id self.transmit = transmit if stream_ended: self.queue.put_nowait({"type": "http.request"}) ===========changed ref 1=========== # module: examples.http3_server class HttpRequestHandler: def send(self, message: Dict): if message["type"] == "http.response.start": self.connection.send_headers( stream_id=self.stream_id, headers=[ (b":status", str(message["status"]).encode("ascii")), (b"server", b"aioquic"), (b"date", formatdate(time.time(), usegmt=True).encode()), ] + [(k, v) for k, v in message["headers"]], ) elif message["type"] == "http.response.body": self.connection.send_data( stream_id=self.stream_id, data=message.get("body", b""), end_stream=not message.get("more_body", False), ) + elif message["type"] == "http.response.push" and isinstance( + self.connection, H3Connection + ): + request_headers = [ + (b":method", b"GET"), + (b":scheme", b"https"), + (b":authority", self.authority), + (b":path", message["path"].encode("utf8")), + ] + [(k, v) for k, v in message["headers"]] + + # send push promise + try: + push_stream_id = self.connection.send_push_promise( + stream_id=self.stream_id, headers=request_headers + ) + except NoAvailablePushIDError: + return + + # fake request + self.protocol.http_event_received( + HeadersReceived( + headers=request_headers, stream_ended=True, stream_id=push_stream_id + ) + ) self.transmit() ===========changed ref 2=========== + # module: aioquic.h3.exceptions + + ===========changed ref 3=========== + # module: aioquic.h3.exceptions + class NoAvailablePushIDError(H3Error): + """ + There are no available push IDs left. + """ + ===========changed ref 4=========== + # module: aioquic.h3.exceptions + class H3Error(Exception): + """ + Base class for HTTP/3 exceptions. + """ + ===========changed ref 5=========== # module: examples.demo @app.route("/") async def homepage(request): """ Simple homepage. """ + await request.send_push_promise("/style.css") return templates.TemplateResponse("index.html", {"request": request})
aioquic.h0.connection/H0Connection.handle_event
Modified
aiortc~aioquic
d290ebea69fdddd2d4afb594a8a312fa5f95d71f
[h3] rename HttpEvent to H3Event
<0>:<add> http_events: List[H3Event] = [] <del> http_events: List[HttpEvent] = []
# module: aioquic.h0.connection class H0Connection: + def handle_event(self, event: QuicEvent) -> List[H3Event]: - def handle_event(self, event: QuicEvent) -> List[HttpEvent]: <0> http_events: List[HttpEvent] = [] <1> <2> if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0: <3> data = event.data <4> if not self._headers_received.get(event.stream_id, False): <5> if self._is_client: <6> http_events.append( <7> HeadersReceived( <8> headers=[], stream_ended=False, stream_id=event.stream_id <9> ) <10> ) <11> else: <12> method, path = data.rstrip().split(b" ", 1) <13> http_events.append( <14> HeadersReceived( <15> headers=[(b":method", method), (b":path", path)], <16> stream_ended=False, <17> stream_id=event.stream_id, <18> ) <19> ) <20> data = b"" <21> self._headers_received[event.stream_id] = True <22> <23> http_events.append( <24> DataReceived( <25> data=data, stream_ended=event.end_stream, stream_id=event.stream_id <26> ) <27> ) <28> <29> return http_events <30>
===========unchanged ref 0=========== at: aioquic.h0.connection.H0Connection.__init__ self._headers_received: Dict[int, bool] = {} self._is_client = quic.configuration.is_client at: aioquic.h3.events H3Event() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.h3.events.DataReceived data: bytes stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.HeadersReceived headers: Headers stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.quic.events QuicEvent() StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: typing List = _alias(list, 1, inst=False, name='List') at: typing.Mapping get(key: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T] get(key: _KT) -> Optional[_VT_co] ===========changed ref 0=========== # module: aioquic.h3.events + class H3Event: + """ + Base class for HTTP/3 events. + """ + ===========changed ref 1=========== # module: aioquic.h3.events - class HttpEvent: - """ - Base class for HTTP/3 events. - """ - - pass -
aioquic.h3.connection/H3Connection._handle_push_frame
Modified
aiortc~aioquic
d290ebea69fdddd2d4afb594a8a312fa5f95d71f
[h3] rename HttpEvent to H3Event
<3>:<add> http_events: List[H3Event] = [] <del> http_events: List[HttpEvent] = []
# module: aioquic.h3.connection class H3Connection: def _handle_push_frame( self, frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool, + ) -> List[H3Event]: - ) -> List[HttpEvent]: <0> """ <1> Handle a frame received on a push stream. <2> """ <3> http_events: List[HttpEvent] = [] <4> <5> if frame_type == FrameType.DATA: <6> http_events.append( <7> DataReceived( <8> data=frame_data, <9> push_id=push_id, <10> stream_ended=stream_ended, <11> stream_id=stream_id, <12> ) <13> ) <14> elif frame_type == FrameType.HEADERS: <15> headers = self._decode_headers(stream_id, frame_data) <16> http_events.append( <17> HeadersReceived( <18> headers=headers, <19> push_id=push_id, <20> stream_id=stream_id, <21> stream_ended=stream_ended, <22> ) <23> ) <24> elif frame_type in ( <25> FrameType.PRIORITY, <26> FrameType.CANCEL_PUSH, <27> FrameType.SETTINGS, <28> FrameType.PUSH_PROMISE, <29> FrameType.GOAWAY, <30> FrameType.MAX_PUSH_ID, <31> FrameType.DUPLICATE_PUSH, <32> ): <33> raise QuicConnectionError( <34> error_code=ErrorCode.HTTP_WRONG_STREAM, <35> frame_type=None, <36> reason_phrase="Invalid frame type on push stream", <37> ) <38> <39> return http_events <40>
===========unchanged ref 0=========== at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) at: aioquic.h3.connection.H3Connection _decode_headers(stream_id: int, frame_data: bytes) -> Headers at: aioquic.h3.events H3Event() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.h3.events.DataReceived data: bytes stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.HeadersReceived headers: Headers stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.quic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) at: typing List = _alias(list, 1, inst=False, name='List') ===========changed ref 0=========== # module: aioquic.h3.events + class H3Event: + """ + Base class for HTTP/3 events. + """ + ===========changed ref 1=========== # module: aioquic.h3.events - class HttpEvent: - """ - Base class for HTTP/3 events. - """ - - pass - ===========changed ref 2=========== # module: aioquic.h0.connection class H0Connection: + def handle_event(self, event: QuicEvent) -> List[H3Event]: - def handle_event(self, event: QuicEvent) -> List[HttpEvent]: + http_events: List[H3Event] = [] - http_events: List[HttpEvent] = [] if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0: data = event.data if not self._headers_received.get(event.stream_id, False): if self._is_client: http_events.append( HeadersReceived( headers=[], stream_ended=False, stream_id=event.stream_id ) ) else: method, path = data.rstrip().split(b" ", 1) http_events.append( HeadersReceived( headers=[(b":method", method), (b":path", path)], stream_ended=False, stream_id=event.stream_id, ) ) data = b"" self._headers_received[event.stream_id] = True http_events.append( DataReceived( data=data, stream_ended=event.end_stream, stream_id=event.stream_id ) ) return http_events
aioquic.h3.connection/H3Connection._receive_stream_data_bidi
Modified
aiortc~aioquic
d290ebea69fdddd2d4afb594a8a312fa5f95d71f
[h3] rename HttpEvent to H3Event
<3>:<add> http_events: List[H3Event] = [] <del> http_events: List[HttpEvent] = []
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool + ) -> List[H3Event]: - ) -> List[HttpEvent]: <0> """ <1> Client-initiated bidirectional streams carry requests and responses. <2> """ <3> http_events: List[HttpEvent] = [] <4> <5> stream = self._stream[stream_id] <6> stream.buffer += data <7> if stream_ended: <8> stream.ended = True <9> if stream.blocked: <10> return http_events <11> <12> # shortcut DATA frame bits <13> if ( <14> stream.frame_type == FrameType.DATA <15> and stream.frame_size is not None <16> and len(stream.buffer) < stream.frame_size <17> ): <18> http_events.append( <19> DataReceived( <20> data=stream.buffer, stream_id=stream_id, stream_ended=False <21> ) <22> ) <23> stream.frame_size -= len(stream.buffer) <24> stream.buffer = b"" <25> return http_events <26> <27> # some peers (e.g. f5) end the stream with no data <28> if stream_ended and not stream.buffer: <29> http_events.append( <30> DataReceived(data=b"", stream_id=stream_id, stream_ended=True) <31> ) <32> return http_events <33> <34> buf = Buffer(data=stream.buffer) <35> consumed = 0 <36> <37> while not buf.eof(): <38> # fetch next frame header <39> if stream.frame_size is None: <40> try: <41> stream.frame_type = buf.pull_uint_var() <42> stream.frame_size = buf.pull_uint_var() <43> except BufferReadError: <44> break <45> consumed = buf.tell() <46> <47> # check how much data is available <48> chunk_size = min</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool + ) -> List[H3Event]: - ) -> List[HttpEvent]: # offset: 1 if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size: break # read available data frame_data = buf.pull_bytes(chunk_size) consumed = buf.tell() # detect end of frame stream.frame_size -= chunk_size if not stream.frame_size: stream.frame_size = None if stream.frame_type == FrameType.DATA and (stream_ended or frame_data): http_events.append( DataReceived( data=frame_data, stream_id=stream_id, stream_ended=stream_ended and buf.eof(), ) ) elif stream.frame_type == FrameType.HEADERS: try: headers = self._decode_headers(stream_id, frame_data) except StreamBlocked: stream.blocked = True break http_events.append( HeadersReceived( headers=headers, stream_id=stream_id, stream_ended=stream_ended and buf.eof(), ) ) elif stream.frame_type == FrameType.PUSH_PROMISE: if not self._is_client: raise QuicConnectionError( error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, frame_type=None, reason_phrase="Clients must not send PUSH_PROMISE", ) frame_buf = Buffer(data=frame_data) push_id = frame_buf.pull_uint_var() headers = self._decode_headers( stream_id, frame_data[frame_buf.tell() :] ) http_events.append( PushPromiseReceived( headers=headers, push_id=</s> ===========below chunk 1=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool + ) -> List[H3Event]: - ) -> List[HttpEvent]: # offset: 2 <s>() :] ) http_events.append( PushPromiseReceived( headers=headers, push_id=push_id, stream_id=stream_id ) ) elif stream.frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on request stream", ) # remove processed data from buffer stream.buffer = stream.buffer[consumed:] return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) at: aioquic.h3.connection.H3Connection _decode_headers(stream_id: int, frame_data: bytes) -> Headers at: aioquic.h3.connection.H3Connection.__init__ self._is_client = quic.configuration.is_client self._stream: Dict[int, H3Stream] = {} at: aioquic.h3.connection.H3Stream.__init__ self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None at: aioquic.h3.events H3Event() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) PushPromiseReceived(headers: Headers, push_id: int, stream_id: int) at: aioquic.quic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) ===========unchanged ref 1=========== at: typing List = _alias(list, 1, inst=False, name='List') ===========changed ref 0=========== # module: aioquic.h3.events + class H3Event: + """ + Base class for HTTP/3 events. + """ + ===========changed ref 1=========== # module: aioquic.h3.connection class H3Connection: def _handle_push_frame( self, frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool, + ) -> List[H3Event]: - ) -> List[HttpEvent]: """ Handle a frame received on a push stream. """ + http_events: List[H3Event] = [] - http_events: List[HttpEvent] = [] if frame_type == FrameType.DATA: http_events.append( DataReceived( data=frame_data, push_id=push_id, stream_ended=stream_ended, stream_id=stream_id, ) ) elif frame_type == FrameType.HEADERS: headers = self._decode_headers(stream_id, frame_data) http_events.append( HeadersReceived( headers=headers, push_id=push_id, stream_id=stream_id, stream_ended=stream_ended, ) ) elif frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.PUSH_PROMISE, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, FrameType.DUPLICATE_PUSH, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on push stream", ) return http_events ===========changed ref 2=========== # module: aioquic.h3.events - class HttpEvent: - """ - Base class for HTTP/3 events. - """ - - pass -
aioquic.h3.connection/H3Connection._receive_stream_data_uni
Modified
aiortc~aioquic
d290ebea69fdddd2d4afb594a8a312fa5f95d71f
[h3] rename HttpEvent to H3Event
<0>:<add> http_events: List[H3Event] = [] <del> http_events: List[HttpEvent] = []
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool + ) -> List[H3Event]: - ) -> List[HttpEvent]: <0> http_events: List[HttpEvent] = [] <1> <2> stream = self._stream[stream_id] <3> stream.buffer += data <4> if stream_ended: <5> stream.ended = True <6> <7> buf = Buffer(data=stream.buffer) <8> consumed = 0 <9> unblocked_streams: Set[int] = set() <10> <11> while not buf.eof(): <12> # fetch stream type for unidirectional streams <13> if stream.stream_type is None: <14> try: <15> stream.stream_type = buf.pull_uint_var() <16> except BufferReadError: <17> break <18> consumed = buf.tell() <19> <20> # check unicity <21> if stream.stream_type == StreamType.CONTROL: <22> assert self._peer_control_stream_id is None <23> self._peer_control_stream_id = stream_id <24> elif stream.stream_type == StreamType.QPACK_DECODER: <25> assert self._peer_decoder_stream_id is None <26> self._peer_decoder_stream_id = stream_id <27> elif stream.stream_type == StreamType.QPACK_ENCODER: <28> assert self._peer_encoder_stream_id is None <29> self._peer_encoder_stream_id = stream_id <30> <31> if stream.stream_type == StreamType.CONTROL: <32> # fetch next frame <33> try: <34> frame_type = buf.pull_uint_var() <35> frame_length = buf.pull_uint_var() <36> frame_data = buf.pull_bytes(frame_length) <37> except BufferReadError: <38> break <39> consumed = buf.tell() <40> <41> self._handle_control_frame(frame_type,</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool + ) -> List[H3Event]: - ) -> List[HttpEvent]: # offset: 1 elif stream.stream_type == StreamType.PUSH: # fetch push id if stream.push_id is None: try: stream.push_id = buf.pull_uint_var() except BufferReadError: break consumed = buf.tell() # fetch next frame try: frame_type = buf.pull_uint_var() frame_length = buf.pull_uint_var() frame_data = buf.pull_bytes(frame_length) except BufferReadError: break consumed = buf.tell() http_events.extend( self._handle_push_frame( frame_type=frame_type, frame_data=frame_data, push_id=stream.push_id, stream_id=stream_id, stream_ended=stream.ended and buf.eof(), ) ) elif stream.stream_type == StreamType.QPACK_DECODER: # feed unframed data to decoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() self._encoder.feed_decoder(data) elif stream.stream_type == StreamType.QPACK_ENCODER: # feed unframed data to encoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() unblocked_streams.update(self._decoder.feed_encoder(data)) else: # unknown stream type, discard data buf.seek(buf.capacity) consumed = buf.tell() # remove processed data from buffer stream.buffer = stream.buffer[consumed:] # process unblocked streams for</s> ===========below chunk 1=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool + ) -> List[H3Event]: - ) -> List[HttpEvent]: # offset: 2 <s> # remove processed data from buffer stream.buffer = stream.buffer[consumed:] # process unblocked streams for stream_id in unblocked_streams: stream = self._stream[stream_id] decoder, headers = self._decoder.resume_header(stream_id) stream.blocked = False http_events.append( HeadersReceived( headers=headers, stream_id=stream_id, stream_ended=stream.ended and not stream.buffer, ) ) http_events.extend( self._receive_stream_data_bidi(stream_id, b"", stream.ended) ) return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.h3.connection StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) at: aioquic.h3.connection.H3Connection _handle_control_frame(frame_type: int, frame_data: bytes) -> None _handle_push_frame(self, frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[H3Event] _handle_push_frame(frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[H3Event] at: aioquic.h3.connection.H3Connection.__init__ self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None at: aioquic.h3.events H3Event() HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: typing List = _alias(list, 1, inst=False, name='List') Set = _alias(set, 1, inst=False, name='Set') ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def _handle_push_frame( self, frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool, + ) -> List[H3Event]: - ) -> List[HttpEvent]: """ Handle a frame received on a push stream. """ + http_events: List[H3Event] = [] - http_events: List[HttpEvent] = [] if frame_type == FrameType.DATA: http_events.append( DataReceived( data=frame_data, push_id=push_id, stream_ended=stream_ended, stream_id=stream_id, ) ) elif frame_type == FrameType.HEADERS: headers = self._decode_headers(stream_id, frame_data) http_events.append( HeadersReceived( headers=headers, push_id=push_id, stream_id=stream_id, stream_ended=stream_ended, ) ) elif frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.PUSH_PROMISE, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, FrameType.DUPLICATE_PUSH, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on push stream", ) return http_events ===========changed ref 1=========== # module: aioquic.h3.events + class H3Event: + """ + Base class for HTTP/3 events. + """ +
examples.http3_client/HttpClient.__init__
Modified
aiortc~aioquic
d290ebea69fdddd2d4afb594a8a312fa5f95d71f
[h3] rename HttpEvent to H3Event
<3>:<add> self._request_events: Dict[int, Deque[H3Event]] = {} <del> self._request_events: Dict[int, Deque[HttpEvent]] = {} <4>:<add> self._request_waiter: Dict[int, asyncio.Future[Deque[H3Event]]] = {} <del> self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {}
# module: examples.http3_client class HttpClient(QuicConnectionProtocol): def __init__(self, *args, **kwargs): <0> super().__init__(*args, **kwargs) <1> <2> self._http: Optional[HttpConnection] = None <3> self._request_events: Dict[int, Deque[HttpEvent]] = {} <4> self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {} <5> self._websockets: Dict[int, WebSocket] = {} <6> <7> if self._quic.configuration.alpn_protocols[0].startswith("hq-"): <8> self._http = H0Connection(self._quic) <9> else: <10> self._http = H3Connection(self._quic) <11>
===========unchanged ref 0=========== at: aioquic.asyncio.protocol.QuicConnectionProtocol __init__(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None) __init__(self, quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None) at: aioquic.asyncio.protocol.QuicConnectionProtocol.__init__ self._quic = quic at: aioquic.h0.connection H0Connection(quic: QuicConnection) at: aioquic.h3.connection H3Connection(quic: QuicConnection) at: aioquic.h3.events H3Event() at: aioquic.quic.configuration.QuicConfiguration alpn_protocols: Optional[List[str]] = None certificate: Any = None connection_id_length: int = 8 idle_timeout: float = 60.0 is_client: bool = True private_key: Any = None quic_logger: Optional[QuicLogger] = None secrets_log_file: TextIO = None server_name: Optional[str] = None session_ticket: Optional[SessionTicket] = None supported_versions: List[int] = field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] ) at: asyncio.futures Future(*, loop: Optional[AbstractEventLoop]=...) Future = _CFuture = _asyncio.Future at: examples.http3_client HttpConnection = Union[H0Connection, H3Connection] WebSocket(http: HttpConnection, stream_id: int, transmit: Callable[[], None]) at: typing Deque = _alias(collections.deque, 1, name='Deque') Dict = _alias(dict, 2, inst=False, name='Dict') ===========changed ref 0=========== # module: aioquic.h3.events + class H3Event: + """ + Base class for HTTP/3 events. + """ + ===========changed ref 1=========== # module: aioquic.h3.events - class HttpEvent: - """ - Base class for HTTP/3 events. - """ - - pass - ===========changed ref 2=========== # module: aioquic.h0.connection class H0Connection: + def handle_event(self, event: QuicEvent) -> List[H3Event]: - def handle_event(self, event: QuicEvent) -> List[HttpEvent]: + http_events: List[H3Event] = [] - http_events: List[HttpEvent] = [] if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0: data = event.data if not self._headers_received.get(event.stream_id, False): if self._is_client: http_events.append( HeadersReceived( headers=[], stream_ended=False, stream_id=event.stream_id ) ) else: method, path = data.rstrip().split(b" ", 1) http_events.append( HeadersReceived( headers=[(b":method", method), (b":path", path)], stream_ended=False, stream_id=event.stream_id, ) ) data = b"" self._headers_received[event.stream_id] = True http_events.append( DataReceived( data=data, stream_ended=event.end_stream, stream_id=event.stream_id ) ) return http_events ===========changed ref 3=========== # module: aioquic.h3.connection class H3Connection: def _handle_push_frame( self, frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool, + ) -> List[H3Event]: - ) -> List[HttpEvent]: """ Handle a frame received on a push stream. """ + http_events: List[H3Event] = [] - http_events: List[HttpEvent] = [] if frame_type == FrameType.DATA: http_events.append( DataReceived( data=frame_data, push_id=push_id, stream_ended=stream_ended, stream_id=stream_id, ) ) elif frame_type == FrameType.HEADERS: headers = self._decode_headers(stream_id, frame_data) http_events.append( HeadersReceived( headers=headers, push_id=push_id, stream_id=stream_id, stream_ended=stream_ended, ) ) elif frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.PUSH_PROMISE, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, FrameType.DUPLICATE_PUSH, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on push stream", ) return http_events ===========changed ref 4=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool + ) -> List[H3Event]: - ) -> List[HttpEvent]: + http_events: List[H3Event] = [] - http_events: List[HttpEvent] = [] stream = self._stream[stream_id] stream.buffer += data if stream_ended: stream.ended = True buf = Buffer(data=stream.buffer) consumed = 0 unblocked_streams: Set[int] = set() while not buf.eof(): # fetch stream type for unidirectional streams if stream.stream_type is None: try: stream.stream_type = buf.pull_uint_var() except BufferReadError: break consumed = buf.tell() # check unicity if stream.stream_type == StreamType.CONTROL: assert self._peer_control_stream_id is None self._peer_control_stream_id = stream_id elif stream.stream_type == StreamType.QPACK_DECODER: assert self._peer_decoder_stream_id is None self._peer_decoder_stream_id = stream_id elif stream.stream_type == StreamType.QPACK_ENCODER: assert self._peer_encoder_stream_id is None self._peer_encoder_stream_id = stream_id if stream.stream_type == StreamType.CONTROL: # fetch next frame try: frame_type = buf.pull_uint_var() frame_length = buf.pull_uint_var() frame_data = buf.pull_bytes(frame_length) except BufferReadError: break consumed = buf.tell() self._handle_control_frame(frame_type, frame_data) elif stream.stream_type == StreamType.PUSH: # fetch push id </s>
examples.http3_client/HttpClient.get
Modified
aiortc~aioquic
d290ebea69fdddd2d4afb594a8a312fa5f95d71f
[h3] rename HttpEvent to H3Event
<11>:<add> (b"user-agent", b"aioquic"),
# module: examples.http3_client class HttpClient(QuicConnectionProtocol): + def get(self, authority: str, path: str) -> Deque[H3Event]: - def get(self, authority: str, path: str) -> Deque[HttpEvent]: <0> """ <1> Perform a GET request. <2> """ <3> stream_id = self._quic.get_next_available_stream_id() <4> self._http.send_headers( <5> stream_id=stream_id, <6> headers=[ <7> (b":method", b"GET"), <8> (b":scheme", b"https"), <9> (b":authority", authority.encode("utf8")), <10> (b":path", path.encode("utf8")), <11> ], <12> ) <13> self._http.send_data(stream_id=stream_id, data=b"", end_stream=True) <14> <15> waiter = self._loop.create_future() <16> self._request_events[stream_id] = deque() <17> self._request_waiter[stream_id] = waiter <18> self.transmit() <19> <20> return await asyncio.shield(waiter) <21>
===========unchanged ref 0=========== at: aioquic.asyncio.protocol.QuicConnectionProtocol transmit() -> None at: aioquic.asyncio.protocol.QuicConnectionProtocol.__init__ self._loop = loop self._quic = quic at: aioquic.h0.connection.H0Connection send_data(stream_id: int, data: bytes, end_stream: bool) -> None send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.connection.H3Connection send_data(stream_id: int, data: bytes, end_stream: bool) -> None send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.events H3Event() at: aioquic.quic.connection.QuicConnection get_next_available_stream_id(is_unidirectional=False) -> int at: asyncio.events.AbstractEventLoop create_future() -> Future[Any] at: collections deque(iterable: Iterable[_T]=..., maxlen: Optional[int]=...) at: examples.http3_client.HttpClient.__init__ self._http = H3Connection(self._quic) self._http: Optional[HttpConnection] = None self._http = H0Connection(self._quic) self._request_events: Dict[int, Deque[H3Event]] = {} self._request_waiter: Dict[int, asyncio.Future[Deque[H3Event]]] = {} at: typing Deque = _alias(collections.deque, 1, name='Deque') ===========changed ref 0=========== # module: aioquic.h3.events + class H3Event: + """ + Base class for HTTP/3 events. + """ + ===========changed ref 1=========== # module: examples.http3_client class HttpClient(QuicConnectionProtocol): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._http: Optional[HttpConnection] = None + self._request_events: Dict[int, Deque[H3Event]] = {} - self._request_events: Dict[int, Deque[HttpEvent]] = {} + self._request_waiter: Dict[int, asyncio.Future[Deque[H3Event]]] = {} - self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {} self._websockets: Dict[int, WebSocket] = {} if self._quic.configuration.alpn_protocols[0].startswith("hq-"): self._http = H0Connection(self._quic) else: self._http = H3Connection(self._quic) ===========changed ref 2=========== # module: aioquic.h3.events - class HttpEvent: - """ - Base class for HTTP/3 events. - """ - - pass - ===========changed ref 3=========== # module: aioquic.h0.connection class H0Connection: + def handle_event(self, event: QuicEvent) -> List[H3Event]: - def handle_event(self, event: QuicEvent) -> List[HttpEvent]: + http_events: List[H3Event] = [] - http_events: List[HttpEvent] = [] if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0: data = event.data if not self._headers_received.get(event.stream_id, False): if self._is_client: http_events.append( HeadersReceived( headers=[], stream_ended=False, stream_id=event.stream_id ) ) else: method, path = data.rstrip().split(b" ", 1) http_events.append( HeadersReceived( headers=[(b":method", method), (b":path", path)], stream_ended=False, stream_id=event.stream_id, ) ) data = b"" self._headers_received[event.stream_id] = True http_events.append( DataReceived( data=data, stream_ended=event.end_stream, stream_id=event.stream_id ) ) return http_events ===========changed ref 4=========== # module: aioquic.h3.connection class H3Connection: def _handle_push_frame( self, frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool, + ) -> List[H3Event]: - ) -> List[HttpEvent]: """ Handle a frame received on a push stream. """ + http_events: List[H3Event] = [] - http_events: List[HttpEvent] = [] if frame_type == FrameType.DATA: http_events.append( DataReceived( data=frame_data, push_id=push_id, stream_ended=stream_ended, stream_id=stream_id, ) ) elif frame_type == FrameType.HEADERS: headers = self._decode_headers(stream_id, frame_data) http_events.append( HeadersReceived( headers=headers, push_id=push_id, stream_id=stream_id, stream_ended=stream_ended, ) ) elif frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.PUSH_PROMISE, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, FrameType.DUPLICATE_PUSH, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on push stream", ) return http_events
examples.httpx_client/H3Dispatcher.__init__
Modified
aiortc~aioquic
d290ebea69fdddd2d4afb594a8a312fa5f95d71f
[h3] rename HttpEvent to H3Event
<3>:<add> self._request_events: Dict[int, Deque[H3Event]] = {} <del> self._request_events: Dict[int, Deque[HttpEvent]] = {} <4>:<add> self._request_waiter: Dict[int, asyncio.Future[Deque[H3Event]]] = {} <del> self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {}
# module: examples.httpx_client class H3Dispatcher(QuicConnectionProtocol, AsyncDispatcher): def __init__(self, *args, **kwargs): <0> super().__init__(*args, **kwargs) <1> <2> self._http = H3Connection(self._quic) <3> self._request_events: Dict[int, Deque[HttpEvent]] = {} <4> self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {} <5>
===========unchanged ref 0=========== at: aioquic.asyncio.protocol.QuicConnectionProtocol __init__(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None) __init__(self, quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None) at: aioquic.asyncio.protocol.QuicConnectionProtocol.__init__ self._quic = quic at: aioquic.h3.connection H3Connection(quic: QuicConnection) at: aioquic.h3.events H3Event() at: asyncio.futures Future(*, loop: Optional[AbstractEventLoop]=...) Future = _CFuture = _asyncio.Future at: typing Deque = _alias(collections.deque, 1, name='Deque') Dict = _alias(dict, 2, inst=False, name='Dict') ===========changed ref 0=========== # module: aioquic.h3.events + class H3Event: + """ + Base class for HTTP/3 events. + """ + ===========changed ref 1=========== # module: aioquic.h3.events - class HttpEvent: - """ - Base class for HTTP/3 events. - """ - - pass - ===========changed ref 2=========== # module: examples.http3_client class HttpClient(QuicConnectionProtocol): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._http: Optional[HttpConnection] = None + self._request_events: Dict[int, Deque[H3Event]] = {} - self._request_events: Dict[int, Deque[HttpEvent]] = {} + self._request_waiter: Dict[int, asyncio.Future[Deque[H3Event]]] = {} - self._request_waiter: Dict[int, asyncio.Future[Deque[HttpEvent]]] = {} self._websockets: Dict[int, WebSocket] = {} if self._quic.configuration.alpn_protocols[0].startswith("hq-"): self._http = H0Connection(self._quic) else: self._http = H3Connection(self._quic) ===========changed ref 3=========== # module: examples.http3_client class HttpClient(QuicConnectionProtocol): + def get(self, authority: str, path: str) -> Deque[H3Event]: - def get(self, authority: str, path: str) -> Deque[HttpEvent]: """ Perform a GET request. """ stream_id = self._quic.get_next_available_stream_id() self._http.send_headers( stream_id=stream_id, headers=[ (b":method", b"GET"), (b":scheme", b"https"), (b":authority", authority.encode("utf8")), (b":path", path.encode("utf8")), + (b"user-agent", b"aioquic"), ], ) self._http.send_data(stream_id=stream_id, data=b"", end_stream=True) waiter = self._loop.create_future() self._request_events[stream_id] = deque() self._request_waiter[stream_id] = waiter self.transmit() return await asyncio.shield(waiter) ===========changed ref 4=========== # module: aioquic.h0.connection class H0Connection: + def handle_event(self, event: QuicEvent) -> List[H3Event]: - def handle_event(self, event: QuicEvent) -> List[HttpEvent]: + http_events: List[H3Event] = [] - http_events: List[HttpEvent] = [] if isinstance(event, StreamDataReceived) and (event.stream_id % 4) == 0: data = event.data if not self._headers_received.get(event.stream_id, False): if self._is_client: http_events.append( HeadersReceived( headers=[], stream_ended=False, stream_id=event.stream_id ) ) else: method, path = data.rstrip().split(b" ", 1) http_events.append( HeadersReceived( headers=[(b":method", method), (b":path", path)], stream_ended=False, stream_id=event.stream_id, ) ) data = b"" self._headers_received[event.stream_id] = True http_events.append( DataReceived( data=data, stream_ended=event.end_stream, stream_id=event.stream_id ) ) return http_events ===========changed ref 5=========== # module: aioquic.h3.connection class H3Connection: def _handle_push_frame( self, frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool, + ) -> List[H3Event]: - ) -> List[HttpEvent]: """ Handle a frame received on a push stream. """ + http_events: List[H3Event] = [] - http_events: List[HttpEvent] = [] if frame_type == FrameType.DATA: http_events.append( DataReceived( data=frame_data, push_id=push_id, stream_ended=stream_ended, stream_id=stream_id, ) ) elif frame_type == FrameType.HEADERS: headers = self._decode_headers(stream_id, frame_data) http_events.append( HeadersReceived( headers=headers, push_id=push_id, stream_id=stream_id, stream_ended=stream_ended, ) ) elif frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.PUSH_PROMISE, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, FrameType.DUPLICATE_PUSH, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on push stream", ) return http_events
aioquic.h3.connection/H3Stream.__init__
Modified
aiortc~aioquic
2fe6a3623f9ee69fa9c0d718d723a28ee48ec289
[http3] validate state in which headers and data are received
<5>:<add> self.headers_state: HeadersState = HeadersState.INITIAL
# module: aioquic.h3.connection class H3Stream: def __init__(self) -> None: <0> self.blocked = False <1> self.buffer = b"" <2> self.ended = False <3> self.frame_size: Optional[int] = None <4> self.frame_type: Optional[int] = None <5> self.push_id: Optional[int] = None <6> self.stream_type: Optional[int] = None <7>
===========unchanged ref 0=========== at: aioquic._buffer.Buffer pull_uint_var() -> int at: aioquic.h3.connection.parse_settings buf = Buffer(data=data) settings = [] setting = buf.pull_uint_var() ===========changed ref 0=========== # module: aioquic.h3.connection + class HeadersState(Enum): + INITIAL = 0 + AFTER_HEADERS = 1 + AFTER_TRAILERS = 2 +
aioquic.h3.connection/H3Connection._receive_stream_data_bidi
Modified
aiortc~aioquic
2fe6a3623f9ee69fa9c0d718d723a28ee48ec289
[http3] validate state in which headers and data are received
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: <0> """ <1> Client-initiated bidirectional streams carry requests and responses. <2> """ <3> http_events: List[H3Event] = [] <4> <5> stream = self._stream[stream_id] <6> stream.buffer += data <7> if stream_ended: <8> stream.ended = True <9> if stream.blocked: <10> return http_events <11> <12> # shortcut DATA frame bits <13> if ( <14> stream.frame_type == FrameType.DATA <15> and stream.frame_size is not None <16> and len(stream.buffer) < stream.frame_size <17> ): <18> http_events.append( <19> DataReceived( <20> data=stream.buffer, stream_id=stream_id, stream_ended=False <21> ) <22> ) <23> stream.frame_size -= len(stream.buffer) <24> stream.buffer = b"" <25> return http_events <26> <27> # some peers (e.g. f5) end the stream with no data <28> if stream_ended and not stream.buffer: <29> http_events.append( <30> DataReceived(data=b"", stream_id=stream_id, stream_ended=True) <31> ) <32> return http_events <33> <34> buf = Buffer(data=stream.buffer) <35> consumed = 0 <36> <37> while not buf.eof(): <38> # fetch next frame header <39> if stream.frame_size is None: <40> try: <41> stream.frame_type = buf.pull_uint_var() <42> stream.frame_size = buf.pull_uint_var() <43> except BufferReadError: <44> break <45> consumed = buf.tell() <46> <47> # check how much data is available <48> chunk_size = min(stream.frame_size, buf.capacity</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 1 if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size: break # read available data frame_data = buf.pull_bytes(chunk_size) consumed = buf.tell() # detect end of frame stream.frame_size -= chunk_size if not stream.frame_size: stream.frame_size = None if stream.frame_type == FrameType.DATA and (stream_ended or frame_data): http_events.append( DataReceived( data=frame_data, stream_id=stream_id, stream_ended=stream_ended and buf.eof(), ) ) elif stream.frame_type == FrameType.HEADERS: try: headers = self._decode_headers(stream_id, frame_data) except StreamBlocked: stream.blocked = True break http_events.append( HeadersReceived( headers=headers, stream_id=stream_id, stream_ended=stream_ended and buf.eof(), ) ) elif stream.frame_type == FrameType.PUSH_PROMISE: if not self._is_client: raise QuicConnectionError( error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, frame_type=None, reason_phrase="Clients must not send PUSH_PROMISE", ) frame_buf = Buffer(data=frame_data) push_id = frame_buf.pull_uint_var() headers = self._decode_headers( stream_id, frame_data[frame_buf.tell() :] ) http_events.append( PushPromiseReceived( headers=headers, push_id=push_id, stream_id=stream_id</s> ===========below chunk 1=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 2 <s>.append( PushPromiseReceived( headers=headers, push_id=push_id, stream_id=stream_id ) ) elif stream.frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on request stream", ) # remove processed data from buffer stream.buffer = stream.buffer[consumed:] return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) Setting(x: Union[str, bytes, bytearray], base: int) Setting(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) encode_frame(frame_type: int, frame_data: bytes) -> bytes encode_settings(settings: Dict[int, int]) -> bytes at: aioquic.h3.connection.H3Connection _create_uni_stream(stream_type: int) -> int _handle_request_or_push_frame(frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[H3Event] at: aioquic.h3.connection.H3Connection.__init__ self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client self._quic = quic ===========unchanged ref 1=========== self._stream: Dict[int, H3Stream] = {} self._max_push_id: Optional[int] = 8 if self._is_client else None self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None at: aioquic.h3.connection.H3Connection._handle_control_frame self._max_push_id = parse_max_push_id(frame_data) at: aioquic.h3.connection.H3Connection._handle_request_or_push_frame http_events: List[H3Event] = [] at: aioquic.h3.connection.H3Stream.__init__ self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None at: aioquic.h3.events H3Event() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.h3.events.DataReceived data: bytes stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.quic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) at: aioquic.quic.connection.QuicConnection send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None at: typing List = _alias(list, 1, inst=False, name='List')
aioquic.h3.connection/H3Connection._receive_stream_data_uni
Modified
aiortc~aioquic
2fe6a3623f9ee69fa9c0d718d723a28ee48ec289
[http3] validate state in which headers and data are received
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: <0> http_events: List[H3Event] = [] <1> <2> stream = self._stream[stream_id] <3> stream.buffer += data <4> if stream_ended: <5> stream.ended = True <6> <7> buf = Buffer(data=stream.buffer) <8> consumed = 0 <9> unblocked_streams: Set[int] = set() <10> <11> while not buf.eof(): <12> # fetch stream type for unidirectional streams <13> if stream.stream_type is None: <14> try: <15> stream.stream_type = buf.pull_uint_var() <16> except BufferReadError: <17> break <18> consumed = buf.tell() <19> <20> # check unicity <21> if stream.stream_type == StreamType.CONTROL: <22> assert self._peer_control_stream_id is None <23> self._peer_control_stream_id = stream_id <24> elif stream.stream_type == StreamType.QPACK_DECODER: <25> assert self._peer_decoder_stream_id is None <26> self._peer_decoder_stream_id = stream_id <27> elif stream.stream_type == StreamType.QPACK_ENCODER: <28> assert self._peer_encoder_stream_id is None <29> self._peer_encoder_stream_id = stream_id <30> <31> if stream.stream_type == StreamType.CONTROL: <32> # fetch next frame <33> try: <34> frame_type = buf.pull_uint_var() <35> frame_length = buf.pull_uint_var() <36> frame_data = buf.pull_bytes(frame_length) <37> except BufferReadError: <38> break <39> consumed = buf.tell() <40> <41> self._handle_control_frame(frame_type, frame_data) <42> elif stream.</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 1 # fetch push id if stream.push_id is None: try: stream.push_id = buf.pull_uint_var() except BufferReadError: break consumed = buf.tell() # fetch next frame try: frame_type = buf.pull_uint_var() frame_length = buf.pull_uint_var() frame_data = buf.pull_bytes(frame_length) except BufferReadError: break consumed = buf.tell() http_events.extend( self._handle_push_frame( frame_type=frame_type, frame_data=frame_data, push_id=stream.push_id, stream_id=stream_id, stream_ended=stream.ended and buf.eof(), ) ) elif stream.stream_type == StreamType.QPACK_DECODER: # feed unframed data to decoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() self._encoder.feed_decoder(data) elif stream.stream_type == StreamType.QPACK_ENCODER: # feed unframed data to encoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() unblocked_streams.update(self._decoder.feed_encoder(data)) else: # unknown stream type, discard data buf.seek(buf.capacity) consumed = buf.tell() # remove processed data from buffer stream.buffer = stream.buffer[consumed:] # process unblocked streams for stream_id in unblocked_streams: stream = self._stream[stream_id] decoder,</s> ===========below chunk 1=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 2 <s>blocked streams for stream_id in unblocked_streams: stream = self._stream[stream_id] decoder, headers = self._decoder.resume_header(stream_id) stream.blocked = False http_events.append( HeadersReceived( headers=headers, stream_id=stream_id, stream_ended=stream.ended and not stream.buffer, ) ) http_events.extend( self._receive_stream_data_bidi(stream_id, b"", stream.ended) ) return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.h3.connection StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) at: aioquic.h3.connection.H3Connection _handle_control_frame(frame_type: int, frame_data: bytes) -> None _handle_request_or_push_frame(frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[H3Event] at: aioquic.h3.connection.H3Connection.__init__ self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None at: aioquic.h3.connection.H3Connection._receive_stream_data_bidi http_events: List[H3Event] = [] stream = self._stream[stream_id] consumed = buf.tell() consumed = 0 at: aioquic.h3.events H3Event() at: typing List = _alias(list, 1, inst=False, name='List') Set = _alias(set, 1, inst=False, name='Set') ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: + def _handle_request_or_push_frame( + self, + frame_type: int, + frame_data: bytes, + push_id: int, + stream_id: int, + stream_ended: bool, + ) -> List[H3Event]: + """ + Handle a frame received on a push stream. + """ + http_events: List[H3Event] = [] + stream = self._stream[stream_id] + + if frame_type == FrameType.DATA: + # check DATA frame is allowed + if stream.headers_state != HeadersState.AFTER_HEADERS: + raise QuicConnectionError( + error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, + frame_type=None, + reason_phrase="DATA frame is not allowed in this state", + ) + + if stream_ended or frame_data: + http_events.append( + DataReceived( + data=frame_data, + push_id=push_id, + stream_ended=stream_ended, + stream_id=stream_id, + ) + ) + elif frame_type == FrameType.HEADERS: + # check HEADERS frame is allowed + if stream.headers_state == HeadersState.AFTER_TRAILERS: + raise QuicConnectionError( + error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, + frame_type=None, + reason_phrase="HEADERS frame is not allowed in this state", + ) + + # try to decode HEADERS + headers = self._decode_headers(stream_id, frame_data) + + # update state and emit headers + if stream.headers_state == HeadersState.INITIAL: + stream.headers_state = HeadersState.AFTER_HEADERS + else: + stream.headers_state = HeadersState.AFTER_TRAILERS + http_events.append(</s>
aioquic.h3.connection/H3Connection._receive_stream_data_uni
Modified
aiortc~aioquic
799c6172486cec794209a6e8e0b0d077d5ff03e6
[http3] send out decoder stream updates after unblocking stream
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: <0> http_events: List[H3Event] = [] <1> <2> stream = self._stream[stream_id] <3> stream.buffer += data <4> if stream_ended: <5> stream.ended = True <6> <7> buf = Buffer(data=stream.buffer) <8> consumed = 0 <9> unblocked_streams: Set[int] = set() <10> <11> while not buf.eof(): <12> # fetch stream type for unidirectional streams <13> if stream.stream_type is None: <14> try: <15> stream.stream_type = buf.pull_uint_var() <16> except BufferReadError: <17> break <18> consumed = buf.tell() <19> <20> # check unicity <21> if stream.stream_type == StreamType.CONTROL: <22> assert self._peer_control_stream_id is None <23> self._peer_control_stream_id = stream_id <24> elif stream.stream_type == StreamType.QPACK_DECODER: <25> assert self._peer_decoder_stream_id is None <26> self._peer_decoder_stream_id = stream_id <27> elif stream.stream_type == StreamType.QPACK_ENCODER: <28> assert self._peer_encoder_stream_id is None <29> self._peer_encoder_stream_id = stream_id <30> <31> if stream.stream_type == StreamType.CONTROL: <32> # fetch next frame <33> try: <34> frame_type = buf.pull_uint_var() <35> frame_length = buf.pull_uint_var() <36> frame_data = buf.pull_bytes(frame_length) <37> except BufferReadError: <38> break <39> consumed = buf.tell() <40> <41> self._handle_control_frame(frame_type, frame_data) <42> elif stream.</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 1 # fetch push id if stream.push_id is None: try: stream.push_id = buf.pull_uint_var() except BufferReadError: break consumed = buf.tell() # fetch next frame try: frame_type = buf.pull_uint_var() frame_length = buf.pull_uint_var() frame_data = buf.pull_bytes(frame_length) except BufferReadError: break consumed = buf.tell() http_events.extend( self._handle_request_or_push_frame( frame_type=frame_type, frame_data=frame_data, push_id=stream.push_id, stream_id=stream_id, stream_ended=stream.ended and buf.eof(), ) ) elif stream.stream_type == StreamType.QPACK_DECODER: # feed unframed data to decoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() self._encoder.feed_decoder(data) elif stream.stream_type == StreamType.QPACK_ENCODER: # feed unframed data to encoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() unblocked_streams.update(self._decoder.feed_encoder(data)) else: # unknown stream type, discard data buf.seek(buf.capacity) consumed = buf.tell() # remove processed data from buffer stream.buffer = stream.buffer[consumed:] # process unblocked streams for stream_id in unblocked_streams: stream = self._stream[stream_id]</s> ===========below chunk 1=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 2 <s> # process unblocked streams for stream_id in unblocked_streams: stream = self._stream[stream_id] decoder, headers = self._decoder.resume_header(stream_id) stream.blocked = False # update state and emit headers if stream.headers_state == HeadersState.INITIAL: stream.headers_state = HeadersState.AFTER_HEADERS else: stream.headers_state = HeadersState.AFTER_TRAILERS http_events.append( HeadersReceived( headers=headers, stream_id=stream_id, stream_ended=stream.ended and not stream.buffer, ) ) # resume processing if stream.buffer: http_events.extend( self._receive_stream_data_bidi(stream_id, b"", stream.ended) ) return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.h3.connection HeadersState() StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) at: aioquic.h3.connection.H3Connection _handle_control_frame(frame_type: int, frame_data: bytes) -> None _handle_request_or_push_frame(frame_type: int, frame_data: bytes, push_id: int, stream_id: int, stream_ended: bool) -> List[H3Event] at: aioquic.h3.connection.H3Connection.__init__ self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None at: aioquic.h3.connection.H3Stream.__init__ self.buffer = b"" self.ended = False self.push_id: Optional[int] = None self.stream_type: Optional[int] = None at: aioquic.h3.events H3Event() HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: typing List = _alias(list, 1, inst=False, name='List') Set = _alias(set, 1, inst=False, name='Set')
aioquic.h3.connection/H3Connection._handle_request_or_push_frame
Modified
aiortc~aioquic
40dde6efab7ee6a9e05bd06a4d6393681d46e5e7
[http3] ensure stream_ended is propagated for server push
<19>:<add> push_id=stream.push_id, <del> push_id=push_id,
# module: aioquic.h3.connection class H3Connection: def _handle_request_or_push_frame( - self, - frame_type: int, - frame_data: bytes, - push_id: int, - stream_id: int, - stream_ended: bool, + self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool ) -> List[H3Event]: <0> """ <1> Handle a frame received on a push stream. <2> """ <3> http_events: List[H3Event] = [] <4> stream = self._stream[stream_id] <5> <6> if frame_type == FrameType.DATA: <7> # check DATA frame is allowed <8> if stream.headers_state != HeadersState.AFTER_HEADERS: <9> raise QuicConnectionError( <10> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, <11> frame_type=None, <12> reason_phrase="DATA frame is not allowed in this state", <13> ) <14> <15> if stream_ended or frame_data: <16> http_events.append( <17> DataReceived( <18> data=frame_data, <19> push_id=push_id, <20> stream_ended=stream_ended, <21> stream_id=stream_id, <22> ) <23> ) <24> elif frame_type == FrameType.HEADERS: <25> # check HEADERS frame is allowed <26> if stream.headers_state == HeadersState.AFTER_TRAILERS: <27> raise QuicConnectionError( <28> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, <29> frame_type=None, <30> reason_phrase="HEADERS frame is not allowed in this state", <31> ) <32> <33> # try to decode HEADERS <34> headers = self._decode_headers(stream_id, frame_data) <35> <36> # update state and emit headers <37> if stream.headers_state == HeadersState.INITIAL: <38> stream.headers_state = HeadersState.AFTER_HEADERS <39> else:</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _handle_request_or_push_frame( - self, - frame_type: int, - frame_data: bytes, - push_id: int, - stream_id: int, - stream_ended: bool, + self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool ) -> List[H3Event]: # offset: 1 http_events.append( HeadersReceived( headers=headers, push_id=push_id, stream_id=stream_id, stream_ended=stream_ended, ) ) elif stream.frame_type == FrameType.PUSH_PROMISE and push_id is None: if not self._is_client: raise QuicConnectionError( error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, frame_type=None, reason_phrase="Clients must not send PUSH_PROMISE", ) frame_buf = Buffer(data=frame_data) push_id = frame_buf.pull_uint_var() headers = self._decode_headers(stream_id, frame_data[frame_buf.tell() :]) http_events.append( PushPromiseReceived( headers=headers, push_id=push_id, stream_id=stream_id ) ) elif frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.PUSH_PROMISE, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, FrameType.DUPLICATE_PUSH, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on push stream", ) return http_events ===========unchanged ref 0=========== at: aioquic._buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer tell() -> int pull_uint_var() -> int at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) HeadersState() StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) at: aioquic.h3.connection.H3Connection _create_uni_stream(stream_type: int) -> int _decode_headers(stream_id: int, frame_data: bytes) -> Headers at: aioquic.h3.connection.H3Connection.__init__ self._is_client = quic.configuration.is_client self._quic = quic self._stream: Dict[int, H3Stream] = {} self._local_control_stream_id: Optional[int] = None at: aioquic.h3.connection.H3Stream.__init__ self.frame_type: Optional[int] = None self.headers_state: HeadersState = HeadersState.INITIAL self.push_id: Optional[int] = None at: aioquic.h3.events H3Event() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) ===========unchanged ref 1=========== PushPromiseReceived(headers: Headers, push_id: int, stream_id: int) at: aioquic.h3.events.DataReceived data: bytes stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.HeadersReceived headers: Headers stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.PushPromiseReceived headers: Headers push_id: int stream_id: int at: aioquic.quic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) at: aioquic.quic.connection.QuicConnection send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None at: typing List = _alias(list, 1, inst=False, name='List')
aioquic.h3.connection/H3Connection._receive_stream_data_bidi
Modified
aiortc~aioquic
40dde6efab7ee6a9e05bd06a4d6393681d46e5e7
[http3] ensure stream_ended is propagated for server push
<12>:<add> # shortcut for DATA frame fragments <del> # shortcut DATA frame bits <20>:<add> data=stream.buffer, <add> push_id=stream.push_id, <add> stream_id=stream_id, <add> stream_ended=False, <del> data=stream.buffer, stream_id=stream_id, stream_ended=False <27>:<add> # handle lone FIN <del> # some peers (e.g. f5) end the stream with no data <30>:<add> DataReceived( <add> data=b"", <add> push_id=stream.push_id, <add> stream_id=stream_id, <add> stream_ended=True, <add> ) <del> DataReceived(data=b"", stream_id=stream_id, stream_ended=True)
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: <0> """ <1> Client-initiated bidirectional streams carry requests and responses. <2> """ <3> http_events: List[H3Event] = [] <4> <5> stream = self._stream[stream_id] <6> stream.buffer += data <7> if stream_ended: <8> stream.ended = True <9> if stream.blocked: <10> return http_events <11> <12> # shortcut DATA frame bits <13> if ( <14> stream.frame_type == FrameType.DATA <15> and stream.frame_size is not None <16> and len(stream.buffer) < stream.frame_size <17> ): <18> http_events.append( <19> DataReceived( <20> data=stream.buffer, stream_id=stream_id, stream_ended=False <21> ) <22> ) <23> stream.frame_size -= len(stream.buffer) <24> stream.buffer = b"" <25> return http_events <26> <27> # some peers (e.g. f5) end the stream with no data <28> if stream_ended and not stream.buffer: <29> http_events.append( <30> DataReceived(data=b"", stream_id=stream_id, stream_ended=True) <31> ) <32> return http_events <33> <34> buf = Buffer(data=stream.buffer) <35> consumed = 0 <36> <37> while not buf.eof(): <38> # fetch next frame header <39> if stream.frame_size is None: <40> try: <41> stream.frame_type = buf.pull_uint_var() <42> stream.frame_size = buf.pull_uint_var() <43> except BufferReadError: <44> break <45> consumed = buf.tell() <46> <47> # check how much data is available <48> chunk_size = min(stream.frame_size, buf.capacity</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 1 if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size: break # read available data frame_data = buf.pull_bytes(chunk_size) consumed = buf.tell() # detect end of frame stream.frame_size -= chunk_size if not stream.frame_size: stream.frame_size = None try: http_events.extend( self._handle_request_or_push_frame( frame_type=stream.frame_type, frame_data=frame_data, push_id=None, stream_id=stream_id, stream_ended=stream.ended and buf.eof(), ) ) except StreamBlocked: stream.blocked = True break # remove processed data from buffer stream.buffer = stream.buffer[consumed:] return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.h3.connection FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) at: aioquic.h3.connection.H3Connection _handle_request_or_push_frame(frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool) -> List[H3Event] _handle_request_or_push_frame(self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool) -> List[H3Event] at: aioquic.h3.connection.H3Connection.__init__ self._stream: Dict[int, H3Stream] = {} at: aioquic.h3.connection.H3Stream.__init__ self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None self.push_id: Optional[int] = None at: aioquic.h3.events H3Event() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: typing List = _alias(list, 1, inst=False, name='List') ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def _handle_request_or_push_frame( - self, - frame_type: int, - frame_data: bytes, - push_id: int, - stream_id: int, - stream_ended: bool, + self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool ) -> List[H3Event]: """ Handle a frame received on a push stream. """ http_events: List[H3Event] = [] stream = self._stream[stream_id] if frame_type == FrameType.DATA: # check DATA frame is allowed if stream.headers_state != HeadersState.AFTER_HEADERS: raise QuicConnectionError( error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, frame_type=None, reason_phrase="DATA frame is not allowed in this state", ) if stream_ended or frame_data: http_events.append( DataReceived( data=frame_data, + push_id=stream.push_id, - push_id=push_id, stream_ended=stream_ended, stream_id=stream_id, ) ) elif frame_type == FrameType.HEADERS: # check HEADERS frame is allowed if stream.headers_state == HeadersState.AFTER_TRAILERS: raise QuicConnectionError( error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, frame_type=None, reason_phrase="HEADERS frame is not allowed in this state", ) # try to decode HEADERS headers = self._decode_headers(stream_id, frame_data) # update state and emit headers if stream.headers_state == HeadersState.INITIAL: stream.headers_state = HeadersState.AFTER_HEADERS else: stream.headers_state = HeadersState.AFTER_TRAILERS http_events.append( </s> ===========changed ref 1=========== # module: aioquic.h3.connection class H3Connection: def _handle_request_or_push_frame( - self, - frame_type: int, - frame_data: bytes, - push_id: int, - stream_id: int, - stream_ended: bool, + self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool ) -> List[H3Event]: # offset: 1 <s> else: stream.headers_state = HeadersState.AFTER_TRAILERS http_events.append( HeadersReceived( headers=headers, + push_id=stream.push_id, - push_id=push_id, stream_id=stream_id, stream_ended=stream_ended, ) ) + elif stream.frame_type == FrameType.PUSH_PROMISE and stream.push_id is None: - elif stream.frame_type == FrameType.PUSH_PROMISE and push_id is None: if not self._is_client: raise QuicConnectionError( error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, frame_type=None, reason_phrase="Clients must not send PUSH_PROMISE", ) frame_buf = Buffer(data=frame_data) push_id = frame_buf.pull_uint_var() headers = self._decode_headers(stream_id, frame_data[frame_buf.tell() :]) http_events.append( PushPromiseReceived( headers=headers, push_id=push_id, stream_id=stream_id ) ) elif frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.PUSH_PROMISE, FrameType.GOAWAY, FrameType</s> ===========changed ref 2=========== # module: aioquic.h3.connection class H3Connection: def _handle_request_or_push_frame( - self, - frame_type: int, - frame_data: bytes, - push_id: int, - stream_id: int, - stream_ended: bool, + self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool ) -> List[H3Event]: # offset: 2 <s>_PUSH_ID, FrameType.DUPLICATE_PUSH, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on push stream", ) return http_events
aioquic.h3.connection/H3Connection._receive_stream_data_uni
Modified
aiortc~aioquic
40dde6efab7ee6a9e05bd06a4d6393681d46e5e7
[http3] ensure stream_ended is propagated for server push
<11>:<add> while stream.stream_type == StreamType.PUSH or not buf.eof(): <del> while not buf.eof():
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: <0> http_events: List[H3Event] = [] <1> <2> stream = self._stream[stream_id] <3> stream.buffer += data <4> if stream_ended: <5> stream.ended = True <6> <7> buf = Buffer(data=stream.buffer) <8> consumed = 0 <9> unblocked_streams: Set[int] = set() <10> <11> while not buf.eof(): <12> # fetch stream type for unidirectional streams <13> if stream.stream_type is None: <14> try: <15> stream.stream_type = buf.pull_uint_var() <16> except BufferReadError: <17> break <18> consumed = buf.tell() <19> <20> # check unicity <21> if stream.stream_type == StreamType.CONTROL: <22> assert self._peer_control_stream_id is None <23> self._peer_control_stream_id = stream_id <24> elif stream.stream_type == StreamType.QPACK_DECODER: <25> assert self._peer_decoder_stream_id is None <26> self._peer_decoder_stream_id = stream_id <27> elif stream.stream_type == StreamType.QPACK_ENCODER: <28> assert self._peer_encoder_stream_id is None <29> self._peer_encoder_stream_id = stream_id <30> <31> if stream.stream_type == StreamType.CONTROL: <32> # fetch next frame <33> try: <34> frame_type = buf.pull_uint_var() <35> frame_length = buf.pull_uint_var() <36> frame_data = buf.pull_bytes(frame_length) <37> except BufferReadError: <38> break <39> consumed = buf.tell() <40> <41> self._handle_control_frame(frame_type, frame_data) <42> elif stream.</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 1 # fetch push id if stream.push_id is None: try: stream.push_id = buf.pull_uint_var() except BufferReadError: break consumed = buf.tell() # fetch next frame try: frame_type = buf.pull_uint_var() frame_length = buf.pull_uint_var() frame_data = buf.pull_bytes(frame_length) except BufferReadError: break consumed = buf.tell() http_events.extend( self._handle_request_or_push_frame( frame_type=frame_type, frame_data=frame_data, push_id=stream.push_id, stream_id=stream_id, stream_ended=stream.ended and buf.eof(), ) ) elif stream.stream_type == StreamType.QPACK_DECODER: # feed unframed data to decoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() self._encoder.feed_decoder(data) elif stream.stream_type == StreamType.QPACK_ENCODER: # feed unframed data to encoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() unblocked_streams.update(self._decoder.feed_encoder(data)) else: # unknown stream type, discard data buf.seek(buf.capacity) consumed = buf.tell() # remove processed data from buffer stream.buffer = stream.buffer[consumed:] # process unblocked streams for stream_id in unblocked_streams: stream = self._stream[stream_id]</s> ===========below chunk 1=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 2 <s> # process unblocked streams for stream_id in unblocked_streams: stream = self._stream[stream_id] # decode headers decoder, headers = self._decoder.resume_header(stream_id) self._quic.send_stream_data(self._local_decoder_stream_id, decoder) stream.blocked = False # update state and emit headers if stream.headers_state == HeadersState.INITIAL: stream.headers_state = HeadersState.AFTER_HEADERS else: stream.headers_state = HeadersState.AFTER_TRAILERS http_events.append( HeadersReceived( headers=headers, stream_id=stream_id, stream_ended=stream.ended and not stream.buffer, ) ) # resume processing if stream.buffer: http_events.extend( self._receive_stream_data_bidi(stream_id, b"", stream.ended) ) return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.h3.connection HeadersState() StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) at: aioquic.h3.connection.H3Connection _handle_control_frame(frame_type: int, frame_data: bytes) -> None _handle_request_or_push_frame(frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool) -> List[H3Event] _handle_request_or_push_frame(self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool) -> List[H3Event] at: aioquic.h3.connection.H3Connection.__init__ self._stream: Dict[int, H3Stream] = {} self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None at: aioquic.h3.connection.H3Connection._receive_stream_data_bidi http_events: List[H3Event] = [] at: aioquic.h3.events H3Event() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: typing List = _alias(list, 1, inst=False, name='List') Set = _alias(set, 1, inst=False, name='Set') ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def _handle_request_or_push_frame( - self, - frame_type: int, - frame_data: bytes, - push_id: int, - stream_id: int, - stream_ended: bool, + self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool ) -> List[H3Event]: """ Handle a frame received on a push stream. """ http_events: List[H3Event] = [] stream = self._stream[stream_id] if frame_type == FrameType.DATA: # check DATA frame is allowed if stream.headers_state != HeadersState.AFTER_HEADERS: raise QuicConnectionError( error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, frame_type=None, reason_phrase="DATA frame is not allowed in this state", ) if stream_ended or frame_data: http_events.append( DataReceived( data=frame_data, + push_id=stream.push_id, - push_id=push_id, stream_ended=stream_ended, stream_id=stream_id, ) ) elif frame_type == FrameType.HEADERS: # check HEADERS frame is allowed if stream.headers_state == HeadersState.AFTER_TRAILERS: raise QuicConnectionError( error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, frame_type=None, reason_phrase="HEADERS frame is not allowed in this state", ) # try to decode HEADERS headers = self._decode_headers(stream_id, frame_data) # update state and emit headers if stream.headers_state == HeadersState.INITIAL: stream.headers_state = HeadersState.AFTER_HEADERS else: stream.headers_state = HeadersState.AFTER_TRAILERS http_events.append( </s>
tests.test_h3/H3ConnectionTest.test_request_headers_only
Modified
aiortc~aioquic
40dde6efab7ee6a9e05bd06a4d6393681d46e5e7
[http3] ensure stream_ended is propagated for server push
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_headers_only(self): <0> with client_and_server( <1> client_options={"alpn_protocols": ["h3-22"]}, <2> server_options={"alpn_protocols": ["h3-22"]}, <3> ) as (quic_client, quic_server): <4> h3_client = H3Connection(quic_client) <5> h3_server = H3Connection(quic_server) <6> <7> # send request <8> stream_id = quic_client.get_next_available_stream_id() <9> h3_client.send_headers( <10> stream_id=stream_id, <11> headers=[ <12> (b":method", b"HEAD"), <13> (b":scheme", b"https"), <14> (b":authority", b"localhost"), <15> (b":path", b"/"), <16> (b"x-foo", b"client"), <17> ], <18> end_stream=True, <19> ) <20> <21> # receive request <22> events = h3_transfer(quic_client, h3_server) <23> self.assertEqual( <24> events, <25> [ <26> HeadersReceived( <27> headers=[ <28> (b":method", b"HEAD"), <29> (b":scheme", b"https"), <30> (b":authority", b"localhost"), <31> (b":path", b"/"), <32> (b"x-foo", b"client"), <33> ], <34> stream_id=stream_id, <35> stream_ended=True, <36> ) <37> ], <38> ) <39> <40> # send response <41> h3_server.send_headers( <42> stream_id=stream_id, <43> headers=[ <44> (b":status", b"200"), <45> (b"content-type", b"text/html; charset=utf-8"), <46> (b</s>
===========below chunk 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_headers_only(self): # offset: 1 ], end_stream=True, ) # receive response events = h3_transfer(quic_server, h3_client) self.assertEqual(len(events), 1) self.assertTrue( events, [ HeadersReceived( headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), (b"x-foo", b"server"), ], stream_id=stream_id, stream_ended=True, ) ], ) ===========unchanged ref 0=========== at: aioquic.h3.connection H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.events HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.h3.events.HeadersReceived headers: Headers stream_id: int stream_ended: bool push_id: Optional[int] = None at: tests.test_connection client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_options={}, server_patch=lambda x: None, transport_options={}) at: tests.test_h3 h3_transfer(quic_sender, h3_receiver) at: tests.test_h3.H3ConnectionTest maxDiff = None at: unittest.case.TestCase failureException: Type[BaseException] longMessage: bool maxDiff: Optional[int] _testMethodName: str _testMethodDoc: str assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: """ Client-initiated bidirectional streams carry requests and responses. """ http_events: List[H3Event] = [] stream = self._stream[stream_id] stream.buffer += data if stream_ended: stream.ended = True if stream.blocked: return http_events + # shortcut for DATA frame fragments - # shortcut DATA frame bits if ( stream.frame_type == FrameType.DATA and stream.frame_size is not None and len(stream.buffer) < stream.frame_size ): http_events.append( DataReceived( + data=stream.buffer, + push_id=stream.push_id, + stream_id=stream_id, + stream_ended=False, - data=stream.buffer, stream_id=stream_id, stream_ended=False ) ) stream.frame_size -= len(stream.buffer) stream.buffer = b"" return http_events + # handle lone FIN - # some peers (e.g. f5) end the stream with no data if stream_ended and not stream.buffer: http_events.append( + DataReceived( + data=b"", + push_id=stream.push_id, + stream_id=stream_id, + stream_ended=True, + ) - DataReceived(data=b"", stream_id=stream_id, stream_ended=True) ) return http_events buf = Buffer(data=stream.buffer) consumed = 0 while not buf.eof(): # fetch next frame header if stream.frame_size is None: try: stream.frame_type = buf.pull_uint</s> ===========changed ref 1=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_bidi( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 1 <s> frame header if stream.frame_size is None: try: stream.frame_type = buf.pull_uint_var() stream.frame_size = buf.pull_uint_var() except BufferReadError: break consumed = buf.tell() # check how much data is available chunk_size = min(stream.frame_size, buf.capacity - consumed) if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size: break # read available data frame_data = buf.pull_bytes(chunk_size) consumed = buf.tell() # detect end of frame stream.frame_size -= chunk_size if not stream.frame_size: stream.frame_size = None try: http_events.extend( self._handle_request_or_push_frame( frame_type=stream.frame_type, frame_data=frame_data, - push_id=None, stream_id=stream_id, stream_ended=stream.ended and buf.eof(), ) ) except StreamBlocked: stream.blocked = True break # remove processed data from buffer stream.buffer = stream.buffer[consumed:] return http_events ===========changed ref 2=========== # module: aioquic.h3.connection class H3Connection: def _handle_request_or_push_frame( - self, - frame_type: int, - frame_data: bytes, - push_id: int, - stream_id: int, - stream_ended: bool, + self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool ) -> List[H3Event]: """ Handle a frame received on a push stream. """ http_events: List[H3Event] = [] stream = self._stream[stream_id] if frame_type == FrameType.DATA: # check DATA frame is allowed if stream.headers_state != HeadersState.AFTER_HEADERS: raise QuicConnectionError( error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, frame_type=None, reason_phrase="DATA frame is not allowed in this state", ) if stream_ended or frame_data: http_events.append( DataReceived( data=frame_data, + push_id=stream.push_id, - push_id=push_id, stream_ended=stream_ended, stream_id=stream_id, ) ) elif frame_type == FrameType.HEADERS: # check HEADERS frame is allowed if stream.headers_state == HeadersState.AFTER_TRAILERS: raise QuicConnectionError( error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, frame_type=None, reason_phrase="HEADERS frame is not allowed in this state", ) # try to decode HEADERS headers = self._decode_headers(stream_id, frame_data) # update state and emit headers if stream.headers_state == HeadersState.INITIAL: stream.headers_state = HeadersState.AFTER_HEADERS else: stream.headers_state = HeadersState.AFTER_TRAILERS http_events.append( </s>
tests.test_h3/H3ConnectionTest.test_request_fragmented_frame
Modified
aiortc~aioquic
40dde6efab7ee6a9e05bd06a4d6393681d46e5e7
[http3] ensure stream_ended is propagated for server push
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_fragmented_frame(self): <0> quic_client = FakeQuicConnection( <1> configuration=QuicConfiguration(is_client=True) <2> ) <3> quic_server = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=False) <5> ) <6> <7> h3_client = H3Connection(quic_client) <8> h3_server = H3Connection(quic_server) <9> <10> # send request <11> stream_id = quic_client.get_next_available_stream_id() <12> h3_client.send_headers( <13> stream_id=stream_id, <14> headers=[ <15> (b":method", b"GET"), <16> (b":scheme", b"https"), <17> (b":authority", b"localhost"), <18> (b":path", b"/"), <19> (b"x-foo", b"client"), <20> ], <21> ) <22> h3_client.send_data(stream_id=stream_id, data=b"hello", end_stream=True) <23> <24> # receive request <25> events = h3_transfer(quic_client, h3_server) <26> self.assertEqual( <27> events, <28> [ <29> HeadersReceived( <30> headers=[ <31> (b":method", b"GET"), <32> (b":scheme", b"https"), <33> (b":authority", b"localhost"), <34> (b":path", b"/"), <35> (b"x-foo", b"client"), <36> ], <37> stream_id=stream_id, <38> stream_ended=False, <39> ), <40> DataReceived(data=b"h", stream_id=0, stream_ended=False), <41> DataReceived(data=b"e", stream_id=0, stream_ended=False), <42> DataReceived(data=b"l", stream</s>
===========below chunk 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_fragmented_frame(self): # offset: 1 DataReceived(data=b"l", stream_id=0, stream_ended=False), DataReceived(data=b"o", stream_id=0, stream_ended=False), DataReceived(data=b"", stream_id=0, stream_ended=True), ], ) # send push promise push_stream_id = h3_server.send_push_promise( stream_id=stream_id, headers=[ (b":method", b"GET"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/app.txt"), ], ) self.assertEqual(push_stream_id, 15) # send response h3_server.send_headers( stream_id=stream_id, headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), ], end_stream=False, ) h3_server.send_data(stream_id=stream_id, data=b"html", end_stream=True) #  fulfill push promise h3_server.send_headers( stream_id=push_stream_id, headers=[(b":status", b"200"), (b"content-type", b"text/plain")], end_stream=False, ) h3_server.send_data(stream_id=push_stream_id, data=b"text", end_stream=True) # receive push promise / reponse events = h3_transfer(quic_server, h3_client) self.assertEqual( events, [ PushPromiseReceived( headers=[ (b":method", b"GET"), (</s> ===========below chunk 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_fragmented_frame(self): # offset: 2 <s> events, [ PushPromiseReceived( headers=[ (b":method", b"GET"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/app.txt"), ], push_id=0, stream_id=stream_id, ), HeadersReceived( headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), ], stream_id=0, stream_ended=False, ), DataReceived(data=b"h", stream_id=0, stream_ended=False), DataReceived(data=b"t", stream_id=0, stream_ended=False), DataReceived(data=b"m", stream_id=0, stream_ended=False), DataReceived(data=b"l", stream_id=0, stream_ended=False), DataReceived(data=b"", stream_id=0, stream_ended=True), HeadersReceived( headers=[(b":status", b"200"), (b"content-type", b"text/plain")], stream_id=15, stream_ended=False, push_id=0, ), DataReceived(data=b"text", stream_id=15, stream_ended=False, push_id=0), ], ) ===========unchanged ref 0=========== at: aioquic.h3.connection H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection send_push_promise(stream_id: int, headers: Headers) -> int send_data(stream_id: int, data: bytes, end_stream: bool) -> None send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.events DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) PushPromiseReceived(headers: Headers, push_id: int, stream_id: int) at: aioquic.h3.events.DataReceived data: bytes stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.PushPromiseReceived headers: Headers push_id: int stream_id: int at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.configuration.QuicConfiguration alpn_protocols: Optional[List[str]] = None certificate: Any = None connection_id_length: int = 8 ===========unchanged ref 1=========== idle_timeout: float = 60.0 is_client: bool = True private_key: Any = None quic_logger: Optional[QuicLogger] = None secrets_log_file: TextIO = None server_name: Optional[str] = None session_ticket: Optional[SessionTicket] = None supported_versions: List[int] = field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] ) at: tests.test_h3 h3_transfer(quic_sender, h3_receiver) FakeQuicConnection(configuration) at: tests.test_h3.FakeQuicConnection get_next_available_stream_id(is_unidirectional=False) at: tests.test_h3.H3ConnectionTest.test_request_fragmented_frame quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None
examples.http3_server/HttpRequestHandler.http_event_received
Modified
aiortc~aioquic
b84214711641ee82bfeb182d81847a0016d41132
[http3 server] receive request trailers
<8>:<add> elif isinstance(event, HeadersReceived) and event.stream_ended: <add> self.queue.put_nowait( <add> {"type": "http.request", "body": b"", "more_body": False} <add> )
# module: examples.http3_server class HttpRequestHandler: def http_event_received(self, event: H3Event): <0> if isinstance(event, DataReceived): <1> self.queue.put_nowait( <2> { <3> "type": "http.request", <4> "body": event.data, <5> "more_body": not event.stream_ended, <6> } <7> ) <8>
===========unchanged ref 0=========== at: aioquic.h3.events H3Event() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: asyncio.queues.Queue __class_getitem__ = classmethod(GenericAlias) put_nowait(item: _T) -> None at: examples.http3_server.HttpRequestHandler.__init__ self.queue: asyncio.Queue[Dict] = asyncio.Queue()
examples.http3_server/HttpServerProtocol.http_event_received
Modified
aiortc~aioquic
b84214711641ee82bfeb182d81847a0016d41132
[http3 server] receive request trailers
# module: examples.http3_server class HttpServerProtocol(QuicConnectionProtocol): def http_event_received(self, event: H3Event) -> None: <0> if isinstance(event, HeadersReceived) and event.stream_id not in self._handlers: <1> authority = None <2> headers = [] <3> http_version = "0.9" if isinstance(self._http, H0Connection) else "3" <4> raw_path = b"" <5> method = "" <6> protocol = None <7> for header, value in event.headers: <8> if header == b":authority": <9> authority = value <10> headers.append((b"host", value)) <11> elif header == b":method": <12> method = value.decode("utf8") <13> elif header == b":path": <14> raw_path = value <15> elif header == b":protocol": <16> protocol = value.decode("utf8") <17> elif header and not header.startswith(b":"): <18> headers.append((header, value)) <19> <20> if b"?" in raw_path: <21> path_bytes, query_string = raw_path.split(b"?", maxsplit=1) <22> else: <23> path_bytes, query_string = raw_path, b"" <24> path = path_bytes.decode("utf8") <25> <26> handler: Handler <27> if method == "CONNECT" and protocol == "websocket": <28> subprotocols: List[str] = [] <29> for header, value in event.headers: <30> if header == b"sec-websocket-protocol": <31> subprotocols = [ <32> x.strip() for x in value.decode("utf8").split(",") <33> ] <34> scope = { <35> "headers": headers, <36> "http_version": http_version, <37> "method": method, <38> "path": path, <39> "query_string": query_string, <40> "raw_path": raw_path, <41> "root_path": "", <42> "scheme": "wss", <43> "subprotocols</s>
===========below chunk 0=========== # module: examples.http3_server class HttpServerProtocol(QuicConnectionProtocol): def http_event_received(self, event: H3Event) -> None: # offset: 1 "type": "websocket", } handler = WebSocketHandler( connection=self._http, scope=scope, stream_id=event.stream_id, transmit=self.transmit, ) else: extensions: Dict[str, Dict] = {} if isinstance(self._http, H3Connection): extensions["http.response.push"] = {} scope = { "extensions": extensions, "headers": headers, "http_version": http_version, "method": method, "path": path, "query_string": query_string, "raw_path": raw_path, "root_path": "", "scheme": "https", "type": "http", } handler = HttpRequestHandler( authority=authority, connection=self._http, protocol=self, scope=scope, stream_ended=event.stream_ended, stream_id=event.stream_id, transmit=self.transmit, ) self._handlers[event.stream_id] = handler asyncio.ensure_future(handler.run_asgi(application)) elif isinstance(event, DataReceived) and event.stream_id in self._handlers: handler = self._handlers[event.stream_id] handler.http_event_received(event) ===========unchanged ref 0=========== at: aioquic.asyncio.protocol.QuicConnectionProtocol __init__(quic: QuicConnection, stream_handler: Optional[QuicStreamHandler]=None) transmit() -> None at: aioquic.h0.connection H0Connection(quic: QuicConnection) at: aioquic.h3.connection H3Connection(quic: QuicConnection) at: aioquic.h3.events H3Event() HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: examples.http3_server HttpConnection = Union[H0Connection, H3Connection] HttpRequestHandler(*, authority: bytes, connection: HttpConnection, protocol: QuicConnectionProtocol, scope: Dict, stream_ended: bool, stream_id: int, transmit: Callable[[], None]) WebSocketHandler(*, connection: HttpConnection, scope: Dict, stream_id: int, transmit: Callable[[], None]) Handler = Union[HttpRequestHandler, WebSocketHandler] at: examples.http3_server.HttpServerProtocol.quic_event_received self._http = H3Connection(self._quic) self._http = H0Connection(self._quic) at: typing List = _alias(list, 1, inst=False, name='List') Dict = _alias(dict, 2, inst=False, name='Dict') ===========changed ref 0=========== # module: examples.http3_server class HttpRequestHandler: def http_event_received(self, event: H3Event): if isinstance(event, DataReceived): self.queue.put_nowait( { "type": "http.request", "body": event.data, "more_body": not event.stream_ended, } ) + elif isinstance(event, HeadersReceived) and event.stream_ended: + self.queue.put_nowait( + {"type": "http.request", "body": b"", "more_body": False} + )
aioquic.h3.connection/H3Connection.handle_event
Modified
aiortc~aioquic
67b188972a0b6539a74ba52ddaba87dba341d1dc
[http3] de-duplicate some push / request code
<10>:<add> return self._receive_request_or_push_data( <del> return self._receive_stream_data_bidi(
# module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: <0> """ <1> Handle a QUIC event and return a list of HTTP events. <2> <3> :param event: The QUIC event to handle. <4> """ <5> if isinstance(event, StreamDataReceived): <6> stream_id = event.stream_id <7> if stream_id not in self._stream: <8> self._stream[stream_id] = H3Stream() <9> if stream_id % 4 == 0: <10> return self._receive_stream_data_bidi( <11> stream_id, event.data, event.end_stream <12> ) <13> elif stream_is_unidirectional(stream_id): <14> return self._receive_stream_data_uni( <15> stream_id, event.data, event.end_stream <16> ) <17> return [] <18>
===========unchanged ref 0=========== at: aioquic.h3.connection H3Stream() at: aioquic.h3.connection.H3Connection _receive_request_or_push_data(stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event] _receive_stream_data_uni(self, stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event] _receive_stream_data_uni(stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event] at: aioquic.h3.connection.H3Connection.__init__ self._stream: Dict[int, H3Stream] = {} at: aioquic.h3.events H3Event() at: aioquic.quic.connection stream_is_unidirectional(stream_id: int) -> bool at: aioquic.quic.events QuicEvent() StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: typing List = _alias(list, 1, inst=False, name='List')
aioquic.h3.connection/H3Connection._handle_request_or_push_frame
Modified
aiortc~aioquic
67b188972a0b6539a74ba52ddaba87dba341d1dc
[http3] de-duplicate some push / request code
<1>:<add> Handle a frame received on a request or push stream. <del> Handle a frame received on a push stream.
# module: aioquic.h3.connection class H3Connection: def _handle_request_or_push_frame( self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool ) -> List[H3Event]: <0> """ <1> Handle a frame received on a push stream. <2> """ <3> http_events: List[H3Event] = [] <4> stream = self._stream[stream_id] <5> <6> if frame_type == FrameType.DATA: <7> # check DATA frame is allowed <8> if stream.headers_state != HeadersState.AFTER_HEADERS: <9> raise QuicConnectionError( <10> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, <11> frame_type=None, <12> reason_phrase="DATA frame is not allowed in this state", <13> ) <14> <15> if stream_ended or frame_data: <16> http_events.append( <17> DataReceived( <18> data=frame_data, <19> push_id=stream.push_id, <20> stream_ended=stream_ended, <21> stream_id=stream_id, <22> ) <23> ) <24> elif frame_type == FrameType.HEADERS: <25> # check HEADERS frame is allowed <26> if stream.headers_state == HeadersState.AFTER_TRAILERS: <27> raise QuicConnectionError( <28> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, <29> frame_type=None, <30> reason_phrase="HEADERS frame is not allowed in this state", <31> ) <32> <33> # try to decode HEADERS <34> headers = self._decode_headers(stream_id, frame_data) <35> <36> # update state and emit headers <37> if stream.headers_state == HeadersState.INITIAL: <38> stream.headers_state = HeadersState.AFTER_HEADERS <39> else: <40> stream.headers_state = HeadersState.AFTER_TRAILERS <41> http_events.append( <42> HeadersReceived( <43> headers=headers, <44> push_id=stream.push</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _handle_request_or_push_frame( self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool ) -> List[H3Event]: # offset: 1 stream_id=stream_id, stream_ended=stream_ended, ) ) elif stream.frame_type == FrameType.PUSH_PROMISE and stream.push_id is None: if not self._is_client: raise QuicConnectionError( error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, frame_type=None, reason_phrase="Clients must not send PUSH_PROMISE", ) frame_buf = Buffer(data=frame_data) push_id = frame_buf.pull_uint_var() headers = self._decode_headers(stream_id, frame_data[frame_buf.tell() :]) http_events.append( PushPromiseReceived( headers=headers, push_id=push_id, stream_id=stream_id ) ) elif frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.PUSH_PROMISE, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, FrameType.DUPLICATE_PUSH, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on push stream", ) return http_events ===========unchanged ref 0=========== at: aioquic._buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer tell() -> int pull_uint_var() -> int at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) HeadersState() at: aioquic.h3.connection.H3Connection _decode_headers(stream_id: int, frame_data: bytes) -> Headers at: aioquic.h3.connection.H3Connection.__init__ self._is_client = quic.configuration.is_client self._stream: Dict[int, H3Stream] = {} at: aioquic.h3.connection.H3Stream.__init__ self.frame_type: Optional[int] = None self.headers_state: HeadersState = HeadersState.INITIAL self.push_id: Optional[int] = None at: aioquic.h3.events H3Event() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) PushPromiseReceived(headers: Headers, push_id: int, stream_id: int) at: aioquic.h3.events.DataReceived data: bytes stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.HeadersReceived headers: Headers stream_id: int stream_ended: bool ===========unchanged ref 1=========== push_id: Optional[int] = None at: aioquic.h3.events.PushPromiseReceived headers: Headers push_id: int stream_id: int at: aioquic.quic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) at: typing List = _alias(list, 1, inst=False, name='List') ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_stream_data_bidi( stream_id, event.data, event.end_stream ) elif stream_is_unidirectional(stream_id): return self._receive_stream_data_uni( stream_id, event.data, event.end_stream ) return []
aioquic.h3.connection/H3Connection._receive_stream_data_uni
Modified
aiortc~aioquic
67b188972a0b6539a74ba52ddaba87dba341d1dc
[http3] de-duplicate some push / request code
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: <0> http_events: List[H3Event] = [] <1> <2> stream = self._stream[stream_id] <3> stream.buffer += data <4> if stream_ended: <5> stream.ended = True <6> <7> buf = Buffer(data=stream.buffer) <8> consumed = 0 <9> unblocked_streams: Set[int] = set() <10> <11> while stream.stream_type == StreamType.PUSH or not buf.eof(): <12> # fetch stream type for unidirectional streams <13> if stream.stream_type is None: <14> try: <15> stream.stream_type = buf.pull_uint_var() <16> except BufferReadError: <17> break <18> consumed = buf.tell() <19> <20> # check unicity <21> if stream.stream_type == StreamType.CONTROL: <22> assert self._peer_control_stream_id is None <23> self._peer_control_stream_id = stream_id <24> elif stream.stream_type == StreamType.QPACK_DECODER: <25> assert self._peer_decoder_stream_id is None <26> self._peer_decoder_stream_id = stream_id <27> elif stream.stream_type == StreamType.QPACK_ENCODER: <28> assert self._peer_encoder_stream_id is None <29> self._peer_encoder_stream_id = stream_id <30> <31> if stream.stream_type == StreamType.CONTROL: <32> # fetch next frame <33> try: <34> frame_type = buf.pull_uint_var() <35> frame_length = buf.pull_uint_var() <36> frame_data = buf.pull_bytes(frame_length) <37> except BufferReadError: <38> break <39> consumed = buf.tell() <40> <41> self._handle_control_frame(frame_type</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 1 elif stream.stream_type == StreamType.PUSH: # fetch push id if stream.push_id is None: try: stream.push_id = buf.pull_uint_var() except BufferReadError: break consumed = buf.tell() # handle lone FIN if stream_ended and buf.eof(): http_events.append( DataReceived( data=b"", push_id=stream.push_id, stream_id=stream_id, stream_ended=True, ) ) # fetch next frame try: frame_type = buf.pull_uint_var() frame_length = buf.pull_uint_var() frame_data = buf.pull_bytes(frame_length) except BufferReadError: break consumed = buf.tell() http_events.extend( self._handle_request_or_push_frame( frame_type=frame_type, frame_data=frame_data, stream_id=stream_id, stream_ended=stream.ended and buf.eof(), ) ) # stop if there is no more data if buf.eof(): break elif stream.stream_type == StreamType.QPACK_DECODER: # feed unframed data to decoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() self._encoder.feed_decoder(data) elif stream.stream_type == StreamType.QPACK_ENCODER: # feed unframed data to encoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() unblocked_streams</s> ===========below chunk 1=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 2 <s> buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() unblocked_streams.update(self._decoder.feed_encoder(data)) else: # unknown stream type, discard data buf.seek(buf.capacity) consumed = buf.tell() # remove processed data from buffer stream.buffer = stream.buffer[consumed:] # process unblocked streams for stream_id in unblocked_streams: stream = self._stream[stream_id] # decode headers decoder, headers = self._decoder.resume_header(stream_id) self._quic.send_stream_data(self._local_decoder_stream_id, decoder) stream.blocked = False # update state and emit headers if stream.headers_state == HeadersState.INITIAL: stream.headers_state = HeadersState.AFTER_HEADERS else: stream.headers_state = HeadersState.AFTER_TRAILERS http_events.append( HeadersReceived( headers=headers, stream_id=stream_id, stream_ended=stream.ended and not stream.buffer, ) ) # resume processing if stream.buffer: http_events.extend( self._receive_stream_data_bidi(stream_id, b"", stream.ended) ) return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool seek(pos: int) -> None tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.h3.connection HeadersState() StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) at: aioquic.h3.connection.H3Connection _handle_control_frame(frame_type: int, frame_data: bytes) -> None _receive_request_or_push_data(stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event] at: aioquic.h3.connection.H3Connection.__init__ self._decoder = Decoder(self._max_table_capacity, self._blocked_streams) self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None at: aioquic.h3.connection.H3Connection._receive_request_or_push_data http_events: List[H3Event] = [] at: aioquic.h3.connection.H3Stream.__init__ self.buffer = b"" self.ended = False self.push_id: Optional[int] = None self.stream_type: Optional[int] = None at: aioquic.h3.events H3Event() ===========unchanged ref 1=========== HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: typing List = _alias(list, 1, inst=False, name='List') Set = _alias(set, 1, inst=False, name='Set')
tests.test_h3/H3ConnectionTest.test_handle_push_frame_wrong_frame_type
Modified
aiortc~aioquic
67b188972a0b6539a74ba52ddaba87dba341d1dc
[http3] de-duplicate some push / request code
<16>:<add> self.assertEqual( <add> str(cm.exception), "Error: 10, reason: Invalid frame type on push stream" <add> )
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_push_frame_wrong_frame_type(self): <0> quic_client = FakeQuicConnection( <1> configuration=QuicConfiguration(is_client=True) <2> ) <3> h3_client = H3Connection(quic_client) <4> <5> with self.assertRaises(QuicConnectionError) as cm: <6> h3_client.handle_event( <7> StreamDataReceived( <8> stream_id=15, <9> data=encode_uint_var(StreamType.PUSH) <10> + encode_uint_var(0) # push ID <11> + encode_frame(FrameType.SETTINGS, b""), <12> end_stream=False, <13> ) <14> ) <15> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) <16>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) encode_frame(frame_type: int, frame_data: bytes) -> bytes H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.configuration.QuicConfiguration alpn_protocols: Optional[List[str]] = None certificate: Any = None connection_id_length: int = 8 idle_timeout: float = 60.0 is_client: bool = True private_key: Any = None quic_logger: Optional[QuicLogger] = None secrets_log_file: TextIO = None ===========unchanged ref 1=========== server_name: Optional[str] = None session_ticket: Optional[SessionTicket] = None supported_versions: List[int] = field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] ) at: aioquic.quic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: aioquic.quic.events.StreamDataReceived data: bytes end_stream: bool stream_id: int at: tests.test_h3 FakeQuicConnection(configuration) at: tests.test_h3.H3ConnectionTest maxDiff = None at: unittest.case.TestCase failureException: Type[BaseException] longMessage: bool maxDiff: Optional[int] _testMethodName: str _testMethodDoc: str assertEqual(first: Any, second: Any, msg: Any=...) -> None assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E] assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None at: unittest.case._AssertRaisesContext.__exit__ self.exception = exc_value.with_traceback(None) ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_stream_data_bidi( stream_id, event.data, event.end_stream ) elif stream_is_unidirectional(stream_id): return self._receive_stream_data_uni( stream_id, event.data, event.end_stream ) return [] ===========changed ref 1=========== # module: aioquic.h3.connection class H3Connection: + def _receive_request_or_push_data( + self, stream_id: int, data: bytes, stream_ended: bool + ) -> List[H3Event]: + """ + Handle data received on a request or push stream. + """ + http_events: List[H3Event] = [] + + stream = self._stream[stream_id] + stream.buffer += data + if stream_ended: + stream.ended = True + if stream.blocked: + return http_events + + # shortcut for DATA frame fragments + if ( + stream.frame_type == FrameType.DATA + and stream.frame_size is not None + and len(stream.buffer) < stream.frame_size + ): + http_events.append( + DataReceived( + data=stream.buffer, + push_id=stream.push_id, + stream_id=stream_id, + stream_ended=False, + ) + ) + stream.frame_size -= len(stream.buffer) + stream.buffer = b"" + return http_events + + # handle lone FIN + if stream_ended and not stream.buffer: + http_events.append( + DataReceived( + data=b"", + push_id=stream.push_id, + stream_id=stream_id, + stream_ended=True, + ) + ) + return http_events + + buf = Buffer(data=stream.buffer) + consumed = 0 + + while not buf.eof(): + # fetch next frame header + if stream.frame_size is None: + try: + stream.frame_type = buf.pull_uint_var() + stream.frame_size = buf.pull_uint_var() + except BufferReadError: + break + </s>
tests.test_h3/H3ConnectionTest.test_handle_request_frame_wrong_frame_type
Modified
aiortc~aioquic
67b188972a0b6539a74ba52ddaba87dba341d1dc
[http3] de-duplicate some push / request code
<14>:<add> self.assertEqual( <add> str(cm.exception), "Error: 10, reason: Invalid frame type on request stream" <add> )
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_wrong_frame_type(self): <0> quic_server = FakeQuicConnection( <1> configuration=QuicConfiguration(is_client=False) <2> ) <3> h3_server = H3Connection(quic_server) <4> <5> with self.assertRaises(QuicConnectionError) as cm: <6> h3_server.handle_event( <7> StreamDataReceived( <8> stream_id=0, <9> data=encode_frame(FrameType.SETTINGS, b""), <10> end_stream=False, <11> ) <12> ) <13> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) <14>
===========unchanged ref 0=========== at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) encode_frame(frame_type: int, frame_data: bytes) -> bytes H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.connection QuicConnectionError(error_code: int, frame_type: int, reason_phrase: str) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_h3 FakeQuicConnection(configuration) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========unchanged ref 1=========== assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E] assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None at: unittest.case._AssertRaisesContext.__exit__ self.exception = exc_value.with_traceback(None) ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_stream_data_bidi( stream_id, event.data, event.end_stream ) elif stream_is_unidirectional(stream_id): return self._receive_stream_data_uni( stream_id, event.data, event.end_stream ) return [] ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_push_frame_wrong_frame_type(self): quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) with self.assertRaises(QuicConnectionError) as cm: h3_client.handle_event( StreamDataReceived( stream_id=15, data=encode_uint_var(StreamType.PUSH) + encode_uint_var(0) # push ID + encode_frame(FrameType.SETTINGS, b""), end_stream=False, ) ) self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) + self.assertEqual( + str(cm.exception), "Error: 10, reason: Invalid frame type on push stream" + ) ===========changed ref 2=========== # module: aioquic.h3.connection class H3Connection: + def _receive_request_or_push_data( + self, stream_id: int, data: bytes, stream_ended: bool + ) -> List[H3Event]: + """ + Handle data received on a request or push stream. + """ + http_events: List[H3Event] = [] + + stream = self._stream[stream_id] + stream.buffer += data + if stream_ended: + stream.ended = True + if stream.blocked: + return http_events + + # shortcut for DATA frame fragments + if ( + stream.frame_type == FrameType.DATA + and stream.frame_size is not None + and len(stream.buffer) < stream.frame_size + ): + http_events.append( + DataReceived( + data=stream.buffer, + push_id=stream.push_id, + stream_id=stream_id, + stream_ended=False, + ) + ) + stream.frame_size -= len(stream.buffer) + stream.buffer = b"" + return http_events + + # handle lone FIN + if stream_ended and not stream.buffer: + http_events.append( + DataReceived( + data=b"", + push_id=stream.push_id, + stream_id=stream_id, + stream_ended=True, + ) + ) + return http_events + + buf = Buffer(data=stream.buffer) + consumed = 0 + + while not buf.eof(): + # fetch next frame header + if stream.frame_size is None: + try: + stream.frame_type = buf.pull_uint_var() + stream.frame_size = buf.pull_uint_var() + except BufferReadError: + break + </s> ===========changed ref 3=========== # module: aioquic.h3.connection class H3Connection: + def _receive_request_or_push_data( + self, stream_id: int, data: bytes, stream_ended: bool + ) -> List[H3Event]: # offset: 1 <s> stream.frame_size = buf.pull_uint_var() + except BufferReadError: + break + consumed = buf.tell() + + # check how much data is available + chunk_size = min(stream.frame_size, buf.capacity - consumed) + if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size: + break + + # read available data + frame_data = buf.pull_bytes(chunk_size) + consumed = buf.tell() + + # detect end of frame + stream.frame_size -= chunk_size + if not stream.frame_size: + stream.frame_size = None + + try: + http_events.extend( + self._handle_request_or_push_frame( + frame_type=stream.frame_type, + frame_data=frame_data, + stream_id=stream_id, + stream_ended=stream.ended and buf.eof(), + ) + ) + except StreamBlocked: + stream.blocked = True + break + + # remove processed data from buffer + stream.buffer = stream.buffer[consumed:] + + return http_events +
tests.test_h3/H3ConnectionTest.test_request_fragmented_frame
Modified
aiortc~aioquic
67b188972a0b6539a74ba52ddaba87dba341d1dc
[http3] de-duplicate some push / request code
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_fragmented_frame(self): <0> quic_client = FakeQuicConnection( <1> configuration=QuicConfiguration(is_client=True) <2> ) <3> quic_server = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=False) <5> ) <6> <7> h3_client = H3Connection(quic_client) <8> h3_server = H3Connection(quic_server) <9> <10> # send request <11> stream_id = quic_client.get_next_available_stream_id() <12> h3_client.send_headers( <13> stream_id=stream_id, <14> headers=[ <15> (b":method", b"GET"), <16> (b":scheme", b"https"), <17> (b":authority", b"localhost"), <18> (b":path", b"/"), <19> (b"x-foo", b"client"), <20> ], <21> ) <22> h3_client.send_data(stream_id=stream_id, data=b"hello", end_stream=True) <23> <24> # receive request <25> events = h3_transfer(quic_client, h3_server) <26> self.assertEqual( <27> events, <28> [ <29> HeadersReceived( <30> headers=[ <31> (b":method", b"GET"), <32> (b":scheme", b"https"), <33> (b":authority", b"localhost"), <34> (b":path", b"/"), <35> (b"x-foo", b"client"), <36> ], <37> stream_id=stream_id, <38> stream_ended=False, <39> ), <40> DataReceived(data=b"h", stream_id=0, stream_ended=False), <41> DataReceived(data=b"e", stream_id=0, stream_ended=False), <42> DataReceived(data=b"l", stream</s>
===========below chunk 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_fragmented_frame(self): # offset: 1 DataReceived(data=b"l", stream_id=0, stream_ended=False), DataReceived(data=b"o", stream_id=0, stream_ended=False), DataReceived(data=b"", stream_id=0, stream_ended=True), ], ) # send push promise push_stream_id = h3_server.send_push_promise( stream_id=stream_id, headers=[ (b":method", b"GET"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/app.txt"), ], ) self.assertEqual(push_stream_id, 15) # send response h3_server.send_headers( stream_id=stream_id, headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), ], end_stream=False, ) h3_server.send_data(stream_id=stream_id, data=b"html", end_stream=True) #  fulfill push promise h3_server.send_headers( stream_id=push_stream_id, headers=[(b":status", b"200"), (b"content-type", b"text/plain")], end_stream=False, ) h3_server.send_data(stream_id=push_stream_id, data=b"text", end_stream=True) # receive push promise / reponse events = h3_transfer(quic_server, h3_client) self.assertEqual( events, [ PushPromiseReceived( headers=[ (b":method", b"GET"), (</s> ===========below chunk 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_request_fragmented_frame(self): # offset: 2 <s> events, [ PushPromiseReceived( headers=[ (b":method", b"GET"), (b":scheme", b"https"), (b":authority", b"localhost"), (b":path", b"/app.txt"), ], push_id=0, stream_id=stream_id, ), HeadersReceived( headers=[ (b":status", b"200"), (b"content-type", b"text/html; charset=utf-8"), ], stream_id=0, stream_ended=False, ), DataReceived(data=b"h", stream_id=0, stream_ended=False), DataReceived(data=b"t", stream_id=0, stream_ended=False), DataReceived(data=b"m", stream_id=0, stream_ended=False), DataReceived(data=b"l", stream_id=0, stream_ended=False), DataReceived(data=b"", stream_id=0, stream_ended=True), HeadersReceived( headers=[(b":status", b"200"), (b"content-type", b"text/plain")], stream_id=15, stream_ended=False, push_id=0, ), DataReceived(data=b"text", stream_id=15, stream_ended=False, push_id=0), DataReceived(data=b"", stream_id=15, stream_ended=True, push_id=0), ], ) ===========unchanged ref 0=========== at: aioquic.h3.connection H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection send_push_promise(stream_id: int, headers: Headers) -> int send_data(stream_id: int, data: bytes, end_stream: bool) -> None send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: aioquic.h3.events DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) PushPromiseReceived(headers: Headers, push_id: int, stream_id: int) at: aioquic.h3.events.DataReceived data: bytes stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.HeadersReceived headers: Headers stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.PushPromiseReceived headers: Headers push_id: int stream_id: int at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) ===========unchanged ref 1=========== at: tests.test_h3 h3_transfer(quic_sender, h3_receiver) FakeQuicConnection(configuration) at: tests.test_h3.FakeQuicConnection get_next_available_stream_id(is_unidirectional=False) at: tests.test_h3.H3ConnectionTest.test_request_headers_only stream_id = quic_client.get_next_available_stream_id() at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_wrong_frame_type(self): quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) with self.assertRaises(QuicConnectionError) as cm: h3_server.handle_event( StreamDataReceived( stream_id=0, data=encode_frame(FrameType.SETTINGS, b""), end_stream=False, ) ) self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) + self.assertEqual( + str(cm.exception), "Error: 10, reason: Invalid frame type on request stream" + )
aioquic.h3.connection/H3Connection.__init__
Modified
aiortc~aioquic
286c400feb5e3fdee22b0434ae89351de094c88a
[http3] add some internal exception types
<5>:<add> self._decoder = pylsqpack.Decoder( <add> self._max_table_capacity, self._blocked_streams <del> self._decoder = Decoder(self._max_table_capacity, self._blocked_streams) <6>:<add> ) <add> self._encoder = pylsqpack.Encoder() <del> self._encoder = Encoder()
# module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): <0> self._max_table_capacity = 0x100 <1> self._blocked_streams = 0x10 <2> <3> self._is_client = quic.configuration.is_client <4> self._quic = quic <5> self._decoder = Decoder(self._max_table_capacity, self._blocked_streams) <6> self._encoder = Encoder() <7> self._stream: Dict[int, H3Stream] = {} <8> <9> self._max_push_id: Optional[int] = 8 if self._is_client else None <10> self._next_push_id: int = 0 <11> <12> self._local_control_stream_id: Optional[int] = None <13> self._local_decoder_stream_id: Optional[int] = None <14> self._local_encoder_stream_id: Optional[int] = None <15> <16> self._peer_control_stream_id: Optional[int] = None <17> self._peer_decoder_stream_id: Optional[int] = None <18> self._peer_encoder_stream_id: Optional[int] = None <19> <20> self._init_connection() <21>
===========unchanged ref 0=========== at: aioquic._buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool pull_uint_var() -> int at: typing Dict = _alias(dict, 2, inst=False, name='Dict') ===========changed ref 0=========== # module: aioquic.h3.connection + class WrongStream(ProtocolError): + error_code = ErrorCode.HTTP_WRONG_STREAM + ===========changed ref 1=========== # module: aioquic.h3.connection + class UnexpectedFrame(ProtocolError): + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME + ===========changed ref 2=========== # module: aioquic.h3.connection + class StreamCreationError(ProtocolError): + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR + ===========changed ref 3=========== # module: aioquic.h3.connection + class QpackEncoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR + ===========changed ref 4=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + def __init__(self, reason_phrase: str = ""): + self.reason_phrase = reason_phrase + ===========changed ref 5=========== # module: aioquic.h3.connection + class QpackDecoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR + ===========changed ref 6=========== # module: aioquic.h3.connection + class QpackDecompressionFailed(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED + ===========changed ref 7=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + """ + Base class for protocol errors. + + These errors are not exposed to the API user, they are handled + in :meth:`H3Connection.handle_event`. + """ + + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR + ===========changed ref 8=========== # module: aioquic.h3.connection class ErrorCode(IntEnum): HTTP_NO_ERROR = 0x00 HTTP_GENERAL_PROTOCOL_ERROR = 0x01 HTTP_INTERNAL_ERROR = 0x03 HTTP_REQUEST_CANCELLED = 0x05 HTTP_INCOMPLETE_REQUEST = 0x06 HTTP_CONNECT_ERROR = 0x07 HTTP_EXCESSIVE_LOAD = 0x08 HTTP_VERSION_FALLBACK = 0x09 HTTP_WRONG_STREAM = 0x0A HTTP_ID_ERROR = 0x0B HTTP_STREAM_CREATION_ERROR = 0x0D HTTP_CLOSED_CRITICAL_STREAM = 0x0F HTTP_EARLY_RESPONSE = 0x11 HTTP_MISSING_SETTINGS = 0x12 HTTP_UNEXPECTED_FRAME = 0x13 HTTP_REQUEST_REJECTED = 0x14 HTTP_SETTINGS_ERROR = 0xFF + HTTP_QPACK_DECOMPRESSION_FAILED = 0x200 + HTTP_QPACK_ENCODER_STREAM_ERROR = 0x201 + HTTP_QPACK_DECODER_STREAM_ERROR = 0x202
aioquic.h3.connection/H3Connection._decode_headers
Modified
aiortc~aioquic
286c400feb5e3fdee22b0434ae89351de094c88a
[http3] add some internal exception types
<3>:<add> try: <add> decoder, headers = self._decoder.feed_header(stream_id, frame_data) <del> decoder, headers = self._decoder.feed_header(stream_id, frame_data) <4>:<add> self._quic.send_stream_data(self._local_decoder_stream_id, decoder) <del> self._quic.send_stream_data(self._local_decoder_stream_id, decoder) <5>:<add> except pylsqpack.DecompressionFailed as exc: <add> raise QpackDecompressionFailed() from exc <add>
# module: aioquic.h3.connection class H3Connection: def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers: <0> """ <1> Decode a HEADERS block and send decoder updates on the decoder stream. <2> """ <3> decoder, headers = self._decoder.feed_header(stream_id, frame_data) <4> self._quic.send_stream_data(self._local_decoder_stream_id, decoder) <5> return headers <6>
===========changed ref 0=========== # module: aioquic.h3.connection + class WrongStream(ProtocolError): + error_code = ErrorCode.HTTP_WRONG_STREAM + ===========changed ref 1=========== # module: aioquic.h3.connection + class UnexpectedFrame(ProtocolError): + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME + ===========changed ref 2=========== # module: aioquic.h3.connection + class StreamCreationError(ProtocolError): + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR + ===========changed ref 3=========== # module: aioquic.h3.connection + class QpackEncoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR + ===========changed ref 4=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + def __init__(self, reason_phrase: str = ""): + self.reason_phrase = reason_phrase + ===========changed ref 5=========== # module: aioquic.h3.connection + class QpackDecoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR + ===========changed ref 6=========== # module: aioquic.h3.connection + class QpackDecompressionFailed(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED + ===========changed ref 7=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + """ + Base class for protocol errors. + + These errors are not exposed to the API user, they are handled + in :meth:`H3Connection.handle_event`. + """ + + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR + ===========changed ref 8=========== # module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client self._quic = quic + self._decoder = pylsqpack.Decoder( + self._max_table_capacity, self._blocked_streams - self._decoder = Decoder(self._max_table_capacity, self._blocked_streams) + ) + self._encoder = pylsqpack.Encoder() - self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} self._max_push_id: Optional[int] = 8 if self._is_client else None self._next_push_id: int = 0 self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None self._init_connection() ===========changed ref 9=========== # module: aioquic.h3.connection class ErrorCode(IntEnum): HTTP_NO_ERROR = 0x00 HTTP_GENERAL_PROTOCOL_ERROR = 0x01 HTTP_INTERNAL_ERROR = 0x03 HTTP_REQUEST_CANCELLED = 0x05 HTTP_INCOMPLETE_REQUEST = 0x06 HTTP_CONNECT_ERROR = 0x07 HTTP_EXCESSIVE_LOAD = 0x08 HTTP_VERSION_FALLBACK = 0x09 HTTP_WRONG_STREAM = 0x0A HTTP_ID_ERROR = 0x0B HTTP_STREAM_CREATION_ERROR = 0x0D HTTP_CLOSED_CRITICAL_STREAM = 0x0F HTTP_EARLY_RESPONSE = 0x11 HTTP_MISSING_SETTINGS = 0x12 HTTP_UNEXPECTED_FRAME = 0x13 HTTP_REQUEST_REJECTED = 0x14 HTTP_SETTINGS_ERROR = 0xFF + HTTP_QPACK_DECOMPRESSION_FAILED = 0x200 + HTTP_QPACK_ENCODER_STREAM_ERROR = 0x201 + HTTP_QPACK_DECODER_STREAM_ERROR = 0x202
aioquic.h3.connection/H3Connection._handle_control_frame
Modified
aiortc~aioquic
286c400feb5e3fdee22b0434ae89351de094c88a
[http3] add some internal exception types
<12>:<del> raise QuicConnectionError( <13>:<del> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, <14>:<del> frame_type=None, <15>:<add> raise UnexpectedFrame("Servers must not send MAX_PUSH_ID") <del> reason_phrase="Servers must not send MAX_PUSH_ID", <16>:<del> ) <24>:<del> raise QuicConnectionError( <25>:<del> error_code=ErrorCode.HTTP_WRONG_STREAM, <26>:<del> frame_type=None, <27>:<add> raise WrongStream("Invalid frame type on control stream") <del> reason_phrase="Invalid frame type on control stream", <28>:<del> )
# module: aioquic.h3.connection class H3Connection: def _handle_control_frame(self, frame_type: int, frame_data: bytes) -> None: <0> """ <1> Handle a frame received on the peer's control stream. <2> """ <3> if frame_type == FrameType.SETTINGS: <4> settings = parse_settings(frame_data) <5> encoder = self._encoder.apply_settings( <6> max_table_capacity=settings.get(Setting.QPACK_MAX_TABLE_CAPACITY, 0), <7> blocked_streams=settings.get(Setting.QPACK_BLOCKED_STREAMS, 0), <8> ) <9> self._quic.send_stream_data(self._local_encoder_stream_id, encoder) <10> elif frame_type == FrameType.MAX_PUSH_ID: <11> if self._is_client: <12> raise QuicConnectionError( <13> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, <14> frame_type=None, <15> reason_phrase="Servers must not send MAX_PUSH_ID", <16> ) <17> self._max_push_id = parse_max_push_id(frame_data) <18> elif frame_type in ( <19> FrameType.DATA, <20> FrameType.HEADERS, <21> FrameType.PUSH_PROMISE, <22> FrameType.DUPLICATE_PUSH, <23> ): <24> raise QuicConnectionError( <25> error_code=ErrorCode.HTTP_WRONG_STREAM, <26> frame_type=None, <27> reason_phrase="Invalid frame type on control stream", <28> ) <29>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) encode_frame(frame_type: int, frame_data: bytes) -> bytes at: aioquic.h3.connection.H3Connection _encode_headers(stream_id, headers: Headers) -> bytes _encode_headers(self, stream_id, headers: Headers) -> bytes at: aioquic.h3.connection.H3Connection.__init__ self._quic = quic self._decoder = pylsqpack.Decoder( self._max_table_capacity, self._blocked_streams ) self._local_decoder_stream_id: Optional[int] = None at: aioquic.h3.connection.H3Connection._init_connection self._local_decoder_stream_id = self._create_uni_stream( StreamType.QPACK_DECODER ) at: aioquic.h3.events Headers = List[Tuple[bytes, bytes]] at: aioquic.quic.connection.QuicConnection get_next_available_stream_id(is_unidirectional=False) -> int send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers: """ Decode a HEADERS block and send decoder updates on the decoder stream. """ + try: + decoder, headers = self._decoder.feed_header(stream_id, frame_data) - decoder, headers = self._decoder.feed_header(stream_id, frame_data) + self._quic.send_stream_data(self._local_decoder_stream_id, decoder) - self._quic.send_stream_data(self._local_decoder_stream_id, decoder) + except pylsqpack.DecompressionFailed as exc: + raise QpackDecompressionFailed() from exc + return headers ===========changed ref 1=========== # module: aioquic.h3.connection + class WrongStream(ProtocolError): + error_code = ErrorCode.HTTP_WRONG_STREAM + ===========changed ref 2=========== # module: aioquic.h3.connection + class UnexpectedFrame(ProtocolError): + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME + ===========changed ref 3=========== # module: aioquic.h3.connection + class StreamCreationError(ProtocolError): + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR + ===========changed ref 4=========== # module: aioquic.h3.connection + class QpackEncoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR + ===========changed ref 5=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + def __init__(self, reason_phrase: str = ""): + self.reason_phrase = reason_phrase + ===========changed ref 6=========== # module: aioquic.h3.connection + class QpackDecoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR + ===========changed ref 7=========== # module: aioquic.h3.connection + class QpackDecompressionFailed(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED + ===========changed ref 8=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + """ + Base class for protocol errors. + + These errors are not exposed to the API user, they are handled + in :meth:`H3Connection.handle_event`. + """ + + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR + ===========changed ref 9=========== # module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client self._quic = quic + self._decoder = pylsqpack.Decoder( + self._max_table_capacity, self._blocked_streams - self._decoder = Decoder(self._max_table_capacity, self._blocked_streams) + ) + self._encoder = pylsqpack.Encoder() - self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} self._max_push_id: Optional[int] = 8 if self._is_client else None self._next_push_id: int = 0 self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None self._init_connection() ===========changed ref 10=========== # module: aioquic.h3.connection class ErrorCode(IntEnum): HTTP_NO_ERROR = 0x00 HTTP_GENERAL_PROTOCOL_ERROR = 0x01 HTTP_INTERNAL_ERROR = 0x03 HTTP_REQUEST_CANCELLED = 0x05 HTTP_INCOMPLETE_REQUEST = 0x06 HTTP_CONNECT_ERROR = 0x07 HTTP_EXCESSIVE_LOAD = 0x08 HTTP_VERSION_FALLBACK = 0x09 HTTP_WRONG_STREAM = 0x0A HTTP_ID_ERROR = 0x0B HTTP_STREAM_CREATION_ERROR = 0x0D HTTP_CLOSED_CRITICAL_STREAM = 0x0F HTTP_EARLY_RESPONSE = 0x11 HTTP_MISSING_SETTINGS = 0x12 HTTP_UNEXPECTED_FRAME = 0x13 HTTP_REQUEST_REJECTED = 0x14 HTTP_SETTINGS_ERROR = 0xFF + HTTP_QPACK_DECOMPRESSION_FAILED = 0x200 + HTTP_QPACK_ENCODER_STREAM_ERROR = 0x201 + HTTP_QPACK_DECODER_STREAM_ERROR = 0x202
aioquic.h3.connection/H3Connection._handle_request_or_push_frame
Modified
aiortc~aioquic
286c400feb5e3fdee22b0434ae89351de094c88a
[http3] add some internal exception types
<9>:<del> raise QuicConnectionError( <10>:<del> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, <11>:<del> frame_type=None, <12>:<add> raise UnexpectedFrame("DATA frame is not allowed in this state") <del> reason_phrase="DATA frame is not allowed in this state", <13>:<del> ) <27>:<del> raise QuicConnectionError( <28>:<del> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, <29>:<del> frame_type=None, <30>:<add> raise UnexpectedFrame("HEADERS frame is not allowed in this state") <del> reason_phrase="HEADERS frame is not allowed in this state", <31>:<del> )
# module: aioquic.h3.connection class H3Connection: def _handle_request_or_push_frame( self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool ) -> List[H3Event]: <0> """ <1> Handle a frame received on a request or push stream. <2> """ <3> http_events: List[H3Event] = [] <4> stream = self._stream[stream_id] <5> <6> if frame_type == FrameType.DATA: <7> # check DATA frame is allowed <8> if stream.headers_state != HeadersState.AFTER_HEADERS: <9> raise QuicConnectionError( <10> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, <11> frame_type=None, <12> reason_phrase="DATA frame is not allowed in this state", <13> ) <14> <15> if stream_ended or frame_data: <16> http_events.append( <17> DataReceived( <18> data=frame_data, <19> push_id=stream.push_id, <20> stream_ended=stream_ended, <21> stream_id=stream_id, <22> ) <23> ) <24> elif frame_type == FrameType.HEADERS: <25> # check HEADERS frame is allowed <26> if stream.headers_state == HeadersState.AFTER_TRAILERS: <27> raise QuicConnectionError( <28> error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, <29> frame_type=None, <30> reason_phrase="HEADERS frame is not allowed in this state", <31> ) <32> <33> # try to decode HEADERS <34> headers = self._decode_headers(stream_id, frame_data) <35> <36> # update state and emit headers <37> if stream.headers_state == HeadersState.INITIAL: <38> stream.headers_state = HeadersState.AFTER_HEADERS <39> else: <40> stream.headers_state = HeadersState.AFTER_TRAILERS <41> http_events.append( <42> HeadersReceived( <43> headers=headers, <44> push_id=stream</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _handle_request_or_push_frame( self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool ) -> List[H3Event]: # offset: 1 stream_id=stream_id, stream_ended=stream_ended, ) ) elif stream.frame_type == FrameType.PUSH_PROMISE and stream.push_id is None: if not self._is_client: raise QuicConnectionError( error_code=ErrorCode.HTTP_UNEXPECTED_FRAME, frame_type=None, reason_phrase="Clients must not send PUSH_PROMISE", ) frame_buf = Buffer(data=frame_data) push_id = frame_buf.pull_uint_var() headers = self._decode_headers(stream_id, frame_data[frame_buf.tell() :]) http_events.append( PushPromiseReceived( headers=headers, push_id=push_id, stream_id=stream_id ) ) elif frame_type in ( FrameType.PRIORITY, FrameType.CANCEL_PUSH, FrameType.SETTINGS, FrameType.PUSH_PROMISE, FrameType.GOAWAY, FrameType.MAX_PUSH_ID, FrameType.DUPLICATE_PUSH, ): raise QuicConnectionError( error_code=ErrorCode.HTTP_WRONG_STREAM, frame_type=None, reason_phrase="Invalid frame type on request stream" if stream.push_id is None else "Invalid frame type on push stream", ) return http_events ===========unchanged ref 0=========== at: aioquic._buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer tell() -> int pull_uint_var() -> int at: aioquic.h3.connection FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) HeadersState() Setting(x: Union[str, bytes, bytearray], base: int) Setting(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QpackDecompressionFailed(reason_phrase: str="") UnexpectedFrame(reason_phrase: str="") WrongStream(reason_phrase: str="") parse_max_push_id(data: bytes) -> int parse_settings(data: bytes) -> Dict[int, int] at: aioquic.h3.connection.H3Connection _decode_headers(stream_id: int, frame_data: bytes) -> Headers _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers at: aioquic.h3.connection.H3Connection.__init__ self._is_client = quic.configuration.is_client self._quic = quic self._encoder = pylsqpack.Encoder() self._stream: Dict[int, H3Stream] = {} self._max_push_id: Optional[int] = 8 if self._is_client else None self._local_encoder_stream_id: Optional[int] = None at: aioquic.h3.connection.H3Connection._decode_headers decoder, headers = self._decoder.feed_header(stream_id, frame_data) ===========unchanged ref 1=========== at: aioquic.h3.connection.H3Connection._init_connection self._local_encoder_stream_id = self._create_uni_stream( StreamType.QPACK_ENCODER ) at: aioquic.h3.connection.H3Stream.__init__ self.frame_type: Optional[int] = None self.headers_state: HeadersState = HeadersState.INITIAL self.push_id: Optional[int] = None at: aioquic.h3.events Headers = List[Tuple[bytes, bytes]] H3Event() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) HeadersReceived(headers: Headers, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.h3.events.DataReceived data: bytes stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.h3.events.HeadersReceived headers: Headers stream_id: int stream_ended: bool push_id: Optional[int] = None at: aioquic.quic.connection.QuicConnection send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None at: typing List = _alias(list, 1, inst=False, name='List') at: typing.Mapping get(key: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T] get(key: _KT) -> Optional[_VT_co] ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers: """ Decode a HEADERS block and send decoder updates on the decoder stream. """ + try: + decoder, headers = self._decoder.feed_header(stream_id, frame_data) - decoder, headers = self._decoder.feed_header(stream_id, frame_data) + self._quic.send_stream_data(self._local_decoder_stream_id, decoder) - self._quic.send_stream_data(self._local_decoder_stream_id, decoder) + except pylsqpack.DecompressionFailed as exc: + raise QpackDecompressionFailed() from exc + return headers ===========changed ref 1=========== # module: aioquic.h3.connection + class WrongStream(ProtocolError): + error_code = ErrorCode.HTTP_WRONG_STREAM + ===========changed ref 2=========== # module: aioquic.h3.connection + class UnexpectedFrame(ProtocolError): + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME + ===========changed ref 3=========== # module: aioquic.h3.connection + class QpackDecompressionFailed(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED + ===========changed ref 4=========== # module: aioquic.h3.connection + class StreamCreationError(ProtocolError): + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR + ===========changed ref 5=========== # module: aioquic.h3.connection + class QpackEncoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR + ===========changed ref 6=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + def __init__(self, reason_phrase: str = ""): + self.reason_phrase = reason_phrase + ===========changed ref 7=========== # module: aioquic.h3.connection + class QpackDecoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR + ===========changed ref 8=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + """ + Base class for protocol errors. + + These errors are not exposed to the API user, they are handled + in :meth:`H3Connection.handle_event`. + """ + + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR +
aioquic.h3.connection/H3Connection._receive_request_or_push_data
Modified
aiortc~aioquic
286c400feb5e3fdee22b0434ae89351de094c88a
[http3] add some internal exception types
# module: aioquic.h3.connection class H3Connection: def _receive_request_or_push_data( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: <0> """ <1> Handle data received on a request or push stream. <2> """ <3> http_events: List[H3Event] = [] <4> <5> stream = self._stream[stream_id] <6> stream.buffer += data <7> if stream_ended: <8> stream.ended = True <9> if stream.blocked: <10> return http_events <11> <12> # shortcut for DATA frame fragments <13> if ( <14> stream.frame_type == FrameType.DATA <15> and stream.frame_size is not None <16> and len(stream.buffer) < stream.frame_size <17> ): <18> http_events.append( <19> DataReceived( <20> data=stream.buffer, <21> push_id=stream.push_id, <22> stream_id=stream_id, <23> stream_ended=False, <24> ) <25> ) <26> stream.frame_size -= len(stream.buffer) <27> stream.buffer = b"" <28> return http_events <29> <30> # handle lone FIN <31> if stream_ended and not stream.buffer: <32> http_events.append( <33> DataReceived( <34> data=b"", <35> push_id=stream.push_id, <36> stream_id=stream_id, <37> stream_ended=True, <38> ) <39> ) <40> return http_events <41> <42> buf = Buffer(data=stream.buffer) <43> consumed = 0 <44> <45> while not buf.eof(): <46> # fetch next frame header <47> if stream.frame_size is None: <48> try: <49> stream.frame_type = buf.pull_uint_var() <50> stream.frame_size = buf.pull_uint_var() <51> except BufferReadError: <52> break <53> consumed = buf</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_request_or_push_data( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 1 # check how much data is available chunk_size = min(stream.frame_size, buf.capacity - consumed) if stream.frame_type != FrameType.DATA and chunk_size < stream.frame_size: break # read available data frame_data = buf.pull_bytes(chunk_size) consumed = buf.tell() # detect end of frame stream.frame_size -= chunk_size if not stream.frame_size: stream.frame_size = None try: http_events.extend( self._handle_request_or_push_frame( frame_type=stream.frame_type, frame_data=frame_data, stream_id=stream_id, stream_ended=stream.ended and buf.eof(), ) ) except StreamBlocked: stream.blocked = True break # remove processed data from buffer stream.buffer = stream.buffer[consumed:] return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) Setting(x: Union[str, bytes, bytearray], base: int) Setting(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) encode_frame(frame_type: int, frame_data: bytes) -> bytes at: aioquic.h3.connection.H3Connection _create_uni_stream(stream_type: int) -> int _create_uni_stream(self, stream_type: int) -> int at: aioquic.h3.connection.H3Connection.__init__ self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client self._quic = quic self._stream: Dict[int, H3Stream] = {} self._max_push_id: Optional[int] = 8 if self._is_client else None self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None ===========unchanged ref 1=========== at: aioquic.h3.connection.H3Connection._handle_control_frame self._max_push_id = parse_max_push_id(frame_data) at: aioquic.h3.connection.H3Connection._init_connection self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL) at: aioquic.h3.connection.H3Stream.__init__ self.blocked = False self.buffer = b"" self.ended = False self.frame_size: Optional[int] = None self.frame_type: Optional[int] = None self.push_id: Optional[int] = None at: aioquic.h3.events H3Event() DataReceived(data: bytes, stream_id: int, stream_ended: bool, push_id: Optional[int]=None) at: aioquic.quic.connection.QuicConnection send_stream_data(stream_id: int, data: bytes, end_stream: bool=False) -> None at: typing List = _alias(list, 1, inst=False, name='List') ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers: """ Decode a HEADERS block and send decoder updates on the decoder stream. """ + try: + decoder, headers = self._decoder.feed_header(stream_id, frame_data) - decoder, headers = self._decoder.feed_header(stream_id, frame_data) + self._quic.send_stream_data(self._local_decoder_stream_id, decoder) - self._quic.send_stream_data(self._local_decoder_stream_id, decoder) + except pylsqpack.DecompressionFailed as exc: + raise QpackDecompressionFailed() from exc + return headers ===========changed ref 1=========== # module: aioquic.h3.connection + class WrongStream(ProtocolError): + error_code = ErrorCode.HTTP_WRONG_STREAM + ===========changed ref 2=========== # module: aioquic.h3.connection + class UnexpectedFrame(ProtocolError): + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME + ===========changed ref 3=========== # module: aioquic.h3.connection + class StreamCreationError(ProtocolError): + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR + ===========changed ref 4=========== # module: aioquic.h3.connection + class QpackEncoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR + ===========changed ref 5=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + def __init__(self, reason_phrase: str = ""): + self.reason_phrase = reason_phrase + ===========changed ref 6=========== # module: aioquic.h3.connection + class QpackDecoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR + ===========changed ref 7=========== # module: aioquic.h3.connection + class QpackDecompressionFailed(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED + ===========changed ref 8=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + """ + Base class for protocol errors. + + These errors are not exposed to the API user, they are handled + in :meth:`H3Connection.handle_event`. + """ + + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR +
aioquic.h3.connection/H3Connection._receive_stream_data_uni
Modified
aiortc~aioquic
286c400feb5e3fdee22b0434ae89351de094c88a
[http3] add some internal exception types
<22>:<add> if self._peer_control_stream_id is not None: <del> assert self._peer_control_stream_id is None <23>:<add> raise StreamCreationError("Only one control stream is allowed") <25>:<add> if self._peer_decoder_stream_id is not None: <del> assert self._peer_decoder_stream_id is None <26>:<add> raise StreamCreationError( <add> "Only one QPACK decoder stream is allowed" <add> ) <28>:<add> if self._peer_encoder_stream_id is not None: <del> assert self._peer_encoder_stream_id is None <29>:<add> raise StreamCreationError( <add> "Only one QPACK encoder stream is allowed" <add> )
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: <0> http_events: List[H3Event] = [] <1> <2> stream = self._stream[stream_id] <3> stream.buffer += data <4> if stream_ended: <5> stream.ended = True <6> <7> buf = Buffer(data=stream.buffer) <8> consumed = 0 <9> unblocked_streams: Set[int] = set() <10> <11> while stream.stream_type == StreamType.PUSH or not buf.eof(): <12> # fetch stream type for unidirectional streams <13> if stream.stream_type is None: <14> try: <15> stream.stream_type = buf.pull_uint_var() <16> except BufferReadError: <17> break <18> consumed = buf.tell() <19> <20> # check unicity <21> if stream.stream_type == StreamType.CONTROL: <22> assert self._peer_control_stream_id is None <23> self._peer_control_stream_id = stream_id <24> elif stream.stream_type == StreamType.QPACK_DECODER: <25> assert self._peer_decoder_stream_id is None <26> self._peer_decoder_stream_id = stream_id <27> elif stream.stream_type == StreamType.QPACK_ENCODER: <28> assert self._peer_encoder_stream_id is None <29> self._peer_encoder_stream_id = stream_id <30> <31> if stream.stream_type == StreamType.CONTROL: <32> # fetch next frame <33> try: <34> frame_type = buf.pull_uint_var() <35> frame_length = buf.pull_uint_var() <36> frame_data = buf.pull_bytes(frame_length) <37> except BufferReadError: <38> break <39> consumed = buf.tell() <40> <41> self._handle_control_frame(frame_type</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 1 elif stream.stream_type == StreamType.PUSH: # fetch push id if stream.push_id is None: try: stream.push_id = buf.pull_uint_var() except BufferReadError: break consumed = buf.tell() # remove processed data from buffer stream.buffer = stream.buffer[consumed:] return self._receive_request_or_push_data(stream_id, b"", stream_ended) elif stream.stream_type == StreamType.QPACK_DECODER: # feed unframed data to decoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() self._encoder.feed_decoder(data) elif stream.stream_type == StreamType.QPACK_ENCODER: # feed unframed data to encoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() unblocked_streams.update(self._decoder.feed_encoder(data)) else: # unknown stream type, discard data buf.seek(buf.capacity) consumed = buf.tell() # remove processed data from buffer stream.buffer = stream.buffer[consumed:] # process unblocked streams for stream_id in unblocked_streams: stream = self._stream[stream_id] # decode headers decoder, headers = self._decoder.resume_header(stream_id) self._quic.send_stream_data(self._local_decoder_stream_id, decoder) stream.blocked = False # update state and emit headers if stream.headers_state == HeadersState.INITIAL: stream.headers_state = HeadersState.AFTER_HEADERS else:</s> ===========below chunk 1=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 2 <s> if stream.headers_state == HeadersState.INITIAL: stream.headers_state = HeadersState.AFTER_HEADERS else: stream.headers_state = HeadersState.AFTER_TRAILERS http_events.append( HeadersReceived( headers=headers, stream_id=stream_id, stream_ended=stream.ended and not stream.buffer, ) ) # resume processing if stream.buffer: http_events.extend( self._receive_request_or_push_data(stream_id, b"", stream.ended) ) return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool seek(pos: int) -> None tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.h3.connection StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) QpackDecoderStreamError(reason_phrase: str="") QpackEncoderStreamError(reason_phrase: str="") StreamCreationError(reason_phrase: str="") at: aioquic.h3.connection.H3Connection _handle_control_frame(frame_type: int, frame_data: bytes) -> None _handle_control_frame(self, frame_type: int, frame_data: bytes) -> None _handle_request_or_push_frame(frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool) -> List[H3Event] _handle_request_or_push_frame(self, frame_type: int, frame_data: bytes, stream_id: int, stream_ended: bool) -> List[H3Event] _receive_request_or_push_data(self, stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event] _receive_request_or_push_data(stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event] at: aioquic.h3.connection.H3Connection.__init__ self._decoder = pylsqpack.Decoder( self._max_table_capacity, self._blocked_streams ) self._encoder = pylsqpack.Encoder() ===========unchanged ref 1=========== self._stream: Dict[int, H3Stream] = {} self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None at: aioquic.h3.connection.H3Connection._receive_request_or_push_data http_events: List[H3Event] = [] stream = self._stream[stream_id] buf = Buffer(data=stream.buffer) consumed = buf.tell() consumed = 0 frame_data = buf.pull_bytes(chunk_size) at: aioquic.h3.events H3Event() at: typing List = _alias(list, 1, inst=False, name='List') Set = _alias(set, 1, inst=False, name='Set') ===========changed ref 0=========== # module: aioquic.h3.connection + class StreamCreationError(ProtocolError): + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR + ===========changed ref 1=========== # module: aioquic.h3.connection + class QpackEncoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR + ===========changed ref 2=========== # module: aioquic.h3.connection + class QpackDecoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR +
tests.test_h3/H3ConnectionTest.test_handle_control_frame_headers
Modified
aiortc~aioquic
286c400feb5e3fdee22b0434ae89351de094c88a
[http3] add some internal exception types
<8>:<add> with self.assertRaises(WrongStream) as cm: <del> with self.assertRaises(QuicConnectionError) as cm: <9>:<add> h3_server.handle_event( <add> StreamDataReceived( <add> stream_id=2, <add> data=encode_uint_var(StreamType.CONTROL) <add> + encode_frame(FrameType.HEADERS, b""), <add> end_stream=False, <add> ) <add> ) <add> self.assertEqual(str(cm.exception), "Invalid frame type on control stream") <del> h3_server._handle_control_frame(FrameType.HEADERS, b"") <10>:<del> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_headers(self): <0> """ <1> We should not receive HEADERS on the control stream. <2> """ <3> quic_server = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=False) <5> ) <6> h3_server = H3Connection(quic_server) <7> <8> with self.assertRaises(QuicConnectionError) as cm: <9> h3_server._handle_control_frame(FrameType.HEADERS, b"") <10> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) <11>
===========unchanged ref 0=========== at: aioquic.h3.connection H3Connection(quic: QuicConnection) at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.configuration.QuicConfiguration alpn_protocols: Optional[List[str]] = None certificate: Any = None connection_id_length: int = 8 idle_timeout: float = 60.0 is_client: bool = True private_key: Any = None quic_logger: Optional[QuicLogger] = None secrets_log_file: TextIO = None server_name: Optional[str] = None session_ticket: Optional[SessionTicket] = None supported_versions: List[int] = field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] ) at: tests.test_h3 FakeQuicConnection(configuration) at: tests.test_h3.H3ConnectionTest maxDiff = None ===========changed ref 0=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + def __init__(self, reason_phrase: str = ""): + self.reason_phrase = reason_phrase + ===========changed ref 1=========== # module: aioquic.h3.connection + class WrongStream(ProtocolError): + error_code = ErrorCode.HTTP_WRONG_STREAM + ===========changed ref 2=========== # module: aioquic.h3.connection + class UnexpectedFrame(ProtocolError): + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME + ===========changed ref 3=========== # module: aioquic.h3.connection + class StreamCreationError(ProtocolError): + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR + ===========changed ref 4=========== # module: aioquic.h3.connection + class QpackDecompressionFailed(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED + ===========changed ref 5=========== # module: aioquic.h3.connection + class QpackEncoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR + ===========changed ref 6=========== # module: aioquic.h3.connection + class QpackDecoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR + ===========changed ref 7=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + """ + Base class for protocol errors. + + These errors are not exposed to the API user, they are handled + in :meth:`H3Connection.handle_event`. + """ + + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR + ===========changed ref 8=========== # module: aioquic.h3.connection class H3Connection: def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers: """ Decode a HEADERS block and send decoder updates on the decoder stream. """ + try: + decoder, headers = self._decoder.feed_header(stream_id, frame_data) - decoder, headers = self._decoder.feed_header(stream_id, frame_data) + self._quic.send_stream_data(self._local_decoder_stream_id, decoder) - self._quic.send_stream_data(self._local_decoder_stream_id, decoder) + except pylsqpack.DecompressionFailed as exc: + raise QpackDecompressionFailed() from exc + return headers ===========changed ref 9=========== # module: aioquic.h3.connection class ErrorCode(IntEnum): HTTP_NO_ERROR = 0x00 HTTP_GENERAL_PROTOCOL_ERROR = 0x01 HTTP_INTERNAL_ERROR = 0x03 HTTP_REQUEST_CANCELLED = 0x05 HTTP_INCOMPLETE_REQUEST = 0x06 HTTP_CONNECT_ERROR = 0x07 HTTP_EXCESSIVE_LOAD = 0x08 HTTP_VERSION_FALLBACK = 0x09 HTTP_WRONG_STREAM = 0x0A HTTP_ID_ERROR = 0x0B HTTP_STREAM_CREATION_ERROR = 0x0D HTTP_CLOSED_CRITICAL_STREAM = 0x0F HTTP_EARLY_RESPONSE = 0x11 HTTP_MISSING_SETTINGS = 0x12 HTTP_UNEXPECTED_FRAME = 0x13 HTTP_REQUEST_REJECTED = 0x14 HTTP_SETTINGS_ERROR = 0xFF + HTTP_QPACK_DECOMPRESSION_FAILED = 0x200 + HTTP_QPACK_ENCODER_STREAM_ERROR = 0x201 + HTTP_QPACK_DECODER_STREAM_ERROR = 0x202 ===========changed ref 10=========== # module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client self._quic = quic + self._decoder = pylsqpack.Decoder( + self._max_table_capacity, self._blocked_streams - self._decoder = Decoder(self._max_table_capacity, self._blocked_streams) + ) + self._encoder = pylsqpack.Encoder() - self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} self._max_push_id: Optional[int] = 8 if self._is_client else None self._next_push_id: int = 0 self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None self._init_connection()
tests.test_h3/H3ConnectionTest.test_handle_control_frame_max_push_id_from_server
Modified
aiortc~aioquic
286c400feb5e3fdee22b0434ae89351de094c88a
[http3] add some internal exception types
<8>:<add> with self.assertRaises(UnexpectedFrame) as cm: <del> with self.assertRaises(QuicConnectionError) as cm: <9>:<add> h3_client.handle_event( <add> StreamDataReceived( <add> stream_id=3, <add> data=encode_uint_var(StreamType.CONTROL) <add> + encode_frame(FrameType.MAX_PUSH_ID, b""), <add> end_stream=False, <add> ) <add> ) <add> self.assertEqual(str(cm.exception), "Servers must not send MAX_PUSH_ID") <del> h3_client._handle_control_frame(FrameType.MAX_PUSH_ID, encode_uint_var(0)) <10>:<del> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_max_push_id_from_server(self): <0> """ <1> A client should not receive MAX_PUSH_ID on the control stream. <2> """ <3> quic_client = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=True) <5> ) <6> h3_client = H3Connection(quic_client) <7> <8> with self.assertRaises(QuicConnectionError) as cm: <9> h3_client._handle_control_frame(FrameType.MAX_PUSH_ID, encode_uint_var(0)) <10> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME) <11>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) WrongStream(reason_phrase: str="") encode_frame(frame_type: int, frame_data: bytes) -> bytes at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: aioquic.quic.events.StreamDataReceived data: bytes end_stream: bool stream_id: int at: tests.test_h3.H3ConnectionTest.test_handle_control_frame_headers h3_server = H3Connection(quic_server) at: unittest.case.TestCase failureException: Type[BaseException] longMessage: bool maxDiff: Optional[int] _testMethodName: str _testMethodDoc: str assertEqual(first: Any, second: Any, msg: Any=...) -> None assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E] assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None at: unittest.case._AssertRaisesContext.__exit__ self.exception = exc_value.with_traceback(None) ===========changed ref 0=========== # module: aioquic.h3.connection + class WrongStream(ProtocolError): + error_code = ErrorCode.HTTP_WRONG_STREAM + ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_headers(self): """ We should not receive HEADERS on the control stream. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) + with self.assertRaises(WrongStream) as cm: - with self.assertRaises(QuicConnectionError) as cm: + h3_server.handle_event( + StreamDataReceived( + stream_id=2, + data=encode_uint_var(StreamType.CONTROL) + + encode_frame(FrameType.HEADERS, b""), + end_stream=False, + ) + ) + self.assertEqual(str(cm.exception), "Invalid frame type on control stream") - h3_server._handle_control_frame(FrameType.HEADERS, b"") - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) ===========changed ref 2=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + def __init__(self, reason_phrase: str = ""): + self.reason_phrase = reason_phrase + ===========changed ref 3=========== # module: aioquic.h3.connection + class UnexpectedFrame(ProtocolError): + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME + ===========changed ref 4=========== # module: aioquic.h3.connection + class StreamCreationError(ProtocolError): + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR + ===========changed ref 5=========== # module: aioquic.h3.connection + class QpackDecompressionFailed(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED + ===========changed ref 6=========== # module: aioquic.h3.connection + class QpackEncoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR + ===========changed ref 7=========== # module: aioquic.h3.connection + class QpackDecoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR + ===========changed ref 8=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + """ + Base class for protocol errors. + + These errors are not exposed to the API user, they are handled + in :meth:`H3Connection.handle_event`. + """ + + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR + ===========changed ref 9=========== # module: aioquic.h3.connection class H3Connection: def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers: """ Decode a HEADERS block and send decoder updates on the decoder stream. """ + try: + decoder, headers = self._decoder.feed_header(stream_id, frame_data) - decoder, headers = self._decoder.feed_header(stream_id, frame_data) + self._quic.send_stream_data(self._local_decoder_stream_id, decoder) - self._quic.send_stream_data(self._local_decoder_stream_id, decoder) + except pylsqpack.DecompressionFailed as exc: + raise QpackDecompressionFailed() from exc + return headers ===========changed ref 10=========== # module: aioquic.h3.connection class ErrorCode(IntEnum): HTTP_NO_ERROR = 0x00 HTTP_GENERAL_PROTOCOL_ERROR = 0x01 HTTP_INTERNAL_ERROR = 0x03 HTTP_REQUEST_CANCELLED = 0x05 HTTP_INCOMPLETE_REQUEST = 0x06 HTTP_CONNECT_ERROR = 0x07 HTTP_EXCESSIVE_LOAD = 0x08 HTTP_VERSION_FALLBACK = 0x09 HTTP_WRONG_STREAM = 0x0A HTTP_ID_ERROR = 0x0B HTTP_STREAM_CREATION_ERROR = 0x0D HTTP_CLOSED_CRITICAL_STREAM = 0x0F HTTP_EARLY_RESPONSE = 0x11 HTTP_MISSING_SETTINGS = 0x12 HTTP_UNEXPECTED_FRAME = 0x13 HTTP_REQUEST_REJECTED = 0x14 HTTP_SETTINGS_ERROR = 0xFF + HTTP_QPACK_DECOMPRESSION_FAILED = 0x200 + HTTP_QPACK_ENCODER_STREAM_ERROR = 0x201 + HTTP_QPACK_DECODER_STREAM_ERROR = 0x202 ===========changed ref 11=========== # module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client self._quic = quic + self._decoder = pylsqpack.Decoder( + self._max_table_capacity, self._blocked_streams - self._decoder = Decoder(self._max_table_capacity, self._blocked_streams) + ) + self._encoder = pylsqpack.Encoder() - self._encoder = Encoder() self._stream: Dict[int, H3Stream] = {} self._max_push_id: Optional[int] = 8 if self._is_client else None self._next_push_id: int = 0 self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None self._init_connection()
tests.test_h3/H3ConnectionTest.test_handle_push_frame_wrong_frame_type
Modified
aiortc~aioquic
286c400feb5e3fdee22b0434ae89351de094c88a
[http3] add some internal exception types
<0>:<add> """ <add> We should not received SETTINGS on a push stream. <add> """ <5>:<add> with self.assertRaises(WrongStream) as cm: <del> with self.assertRaises(QuicConnectionError) as cm: <15>:<del> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) <16>:<del> self.assertEqual( <17>:<add> self.assertEqual(str(cm.exception), "Invalid frame type on push stream") <del> str(cm.exception), "Error: 10, reason: Invalid frame type on push stream" <18>:<del> )
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_push_frame_wrong_frame_type(self): <0> quic_client = FakeQuicConnection( <1> configuration=QuicConfiguration(is_client=True) <2> ) <3> h3_client = H3Connection(quic_client) <4> <5> with self.assertRaises(QuicConnectionError) as cm: <6> h3_client.handle_event( <7> StreamDataReceived( <8> stream_id=15, <9> data=encode_uint_var(StreamType.PUSH) <10> + encode_uint_var(0) # push ID <11> + encode_frame(FrameType.SETTINGS, b""), <12> end_stream=False, <13> ) <14> ) <15> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) <16> self.assertEqual( <17> str(cm.exception), "Error: 10, reason: Invalid frame type on push stream" <18> ) <19>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) UnexpectedFrame(reason_phrase: str="") encode_frame(frame_type: int, frame_data: bytes) -> bytes H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_h3 FakeQuicConnection(configuration) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========unchanged ref 1=========== assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E] assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None at: unittest.case._AssertRaisesContext.__exit__ self.exception = exc_value.with_traceback(None) ===========changed ref 0=========== # module: aioquic.h3.connection + class UnexpectedFrame(ProtocolError): + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME + ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_headers(self): """ We should not receive HEADERS on the control stream. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) + with self.assertRaises(WrongStream) as cm: - with self.assertRaises(QuicConnectionError) as cm: + h3_server.handle_event( + StreamDataReceived( + stream_id=2, + data=encode_uint_var(StreamType.CONTROL) + + encode_frame(FrameType.HEADERS, b""), + end_stream=False, + ) + ) + self.assertEqual(str(cm.exception), "Invalid frame type on control stream") - h3_server._handle_control_frame(FrameType.HEADERS, b"") - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) ===========changed ref 2=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_max_push_id_from_server(self): """ A client should not receive MAX_PUSH_ID on the control stream. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) + with self.assertRaises(UnexpectedFrame) as cm: - with self.assertRaises(QuicConnectionError) as cm: + h3_client.handle_event( + StreamDataReceived( + stream_id=3, + data=encode_uint_var(StreamType.CONTROL) + + encode_frame(FrameType.MAX_PUSH_ID, b""), + end_stream=False, + ) + ) + self.assertEqual(str(cm.exception), "Servers must not send MAX_PUSH_ID") - h3_client._handle_control_frame(FrameType.MAX_PUSH_ID, encode_uint_var(0)) - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME) ===========changed ref 3=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + def __init__(self, reason_phrase: str = ""): + self.reason_phrase = reason_phrase + ===========changed ref 4=========== # module: aioquic.h3.connection + class WrongStream(ProtocolError): + error_code = ErrorCode.HTTP_WRONG_STREAM + ===========changed ref 5=========== # module: aioquic.h3.connection + class StreamCreationError(ProtocolError): + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR + ===========changed ref 6=========== # module: aioquic.h3.connection + class QpackDecompressionFailed(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED + ===========changed ref 7=========== # module: aioquic.h3.connection + class QpackEncoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR + ===========changed ref 8=========== # module: aioquic.h3.connection + class QpackDecoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR + ===========changed ref 9=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + """ + Base class for protocol errors. + + These errors are not exposed to the API user, they are handled + in :meth:`H3Connection.handle_event`. + """ + + error_code = ErrorCode.HTTP_GENERAL_PROTOCOL_ERROR + ===========changed ref 10=========== # module: aioquic.h3.connection class H3Connection: def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers: """ Decode a HEADERS block and send decoder updates on the decoder stream. """ + try: + decoder, headers = self._decoder.feed_header(stream_id, frame_data) - decoder, headers = self._decoder.feed_header(stream_id, frame_data) + self._quic.send_stream_data(self._local_decoder_stream_id, decoder) - self._quic.send_stream_data(self._local_decoder_stream_id, decoder) + except pylsqpack.DecompressionFailed as exc: + raise QpackDecompressionFailed() from exc + return headers
tests.test_h3/H3ConnectionTest.test_handle_request_frame_data_before_headers
Modified
aiortc~aioquic
286c400feb5e3fdee22b0434ae89351de094c88a
[http3] add some internal exception types
<8>:<add> with self.assertRaises(UnexpectedFrame) as cm: <del> with self.assertRaises(QuicConnectionError) as cm: <16>:<add> self.assertEqual(str(cm.exception), "DATA frame is not allowed in this state") <del> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_data_before_headers(self): <0> """ <1> We should not receive DATA before receiving headers. <2> """ <3> quic_server = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=False) <5> ) <6> h3_server = H3Connection(quic_server) <7> <8> with self.assertRaises(QuicConnectionError) as cm: <9> h3_server.handle_event( <10> StreamDataReceived( <11> stream_id=0, <12> data=encode_frame(FrameType.DATA, b""), <13> end_stream=False, <14> ) <15> ) <16> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME) <17>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) StreamCreationError(reason_phrase: str="") H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_h3 FakeQuicConnection(configuration) at: unittest.case.TestCase assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E] assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None ===========changed ref 0=========== # module: aioquic.h3.connection + class StreamCreationError(ProtocolError): + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR + ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): + def test_handle_control_stream_duplicate(self): + """ + We must only receive a single control stream. + """ + quic_server = FakeQuicConnection( + configuration=QuicConfiguration(is_client=False) + ) + h3_server = H3Connection(quic_server) + + # receive a first control stream + h3_server.handle_event( + StreamDataReceived( + stream_id=2, data=encode_uint_var(StreamType.CONTROL), end_stream=False + ) + ) + with self.assertRaises(StreamCreationError) as cm: + # receive a second control stream + h3_server.handle_event( + StreamDataReceived( + stream_id=6, + data=encode_uint_var(StreamType.CONTROL), + end_stream=False, + ) + ) + self.assertEqual(str(cm.exception), "Only one control stream is allowed") + ===========changed ref 2=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_push_frame_wrong_frame_type(self): + """ + We should not received SETTINGS on a push stream. + """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) + with self.assertRaises(WrongStream) as cm: - with self.assertRaises(QuicConnectionError) as cm: h3_client.handle_event( StreamDataReceived( stream_id=15, data=encode_uint_var(StreamType.PUSH) + encode_uint_var(0) # push ID + encode_frame(FrameType.SETTINGS, b""), end_stream=False, ) ) - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) - self.assertEqual( + self.assertEqual(str(cm.exception), "Invalid frame type on push stream") - str(cm.exception), "Error: 10, reason: Invalid frame type on push stream" - ) ===========changed ref 3=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_headers(self): """ We should not receive HEADERS on the control stream. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) + with self.assertRaises(WrongStream) as cm: - with self.assertRaises(QuicConnectionError) as cm: + h3_server.handle_event( + StreamDataReceived( + stream_id=2, + data=encode_uint_var(StreamType.CONTROL) + + encode_frame(FrameType.HEADERS, b""), + end_stream=False, + ) + ) + self.assertEqual(str(cm.exception), "Invalid frame type on control stream") - h3_server._handle_control_frame(FrameType.HEADERS, b"") - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) ===========changed ref 4=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_max_push_id_from_server(self): """ A client should not receive MAX_PUSH_ID on the control stream. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) + with self.assertRaises(UnexpectedFrame) as cm: - with self.assertRaises(QuicConnectionError) as cm: + h3_client.handle_event( + StreamDataReceived( + stream_id=3, + data=encode_uint_var(StreamType.CONTROL) + + encode_frame(FrameType.MAX_PUSH_ID, b""), + end_stream=False, + ) + ) + self.assertEqual(str(cm.exception), "Servers must not send MAX_PUSH_ID") - h3_client._handle_control_frame(FrameType.MAX_PUSH_ID, encode_uint_var(0)) - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME) ===========changed ref 5=========== # module: aioquic.h3.connection + class ProtocolError(Exception): + def __init__(self, reason_phrase: str = ""): + self.reason_phrase = reason_phrase + ===========changed ref 6=========== # module: aioquic.h3.connection + class WrongStream(ProtocolError): + error_code = ErrorCode.HTTP_WRONG_STREAM + ===========changed ref 7=========== # module: aioquic.h3.connection + class UnexpectedFrame(ProtocolError): + error_code = ErrorCode.HTTP_UNEXPECTED_FRAME + ===========changed ref 8=========== # module: aioquic.h3.connection + class QpackDecompressionFailed(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED + ===========changed ref 9=========== # module: aioquic.h3.connection + class QpackEncoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR + ===========changed ref 10=========== # module: aioquic.h3.connection + class QpackDecoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR +
tests.test_h3/H3ConnectionTest.test_handle_request_frame_headers_after_trailers
Modified
aiortc~aioquic
286c400feb5e3fdee22b0434ae89351de094c88a
[http3] add some internal exception types
<28>:<add> with self.assertRaises(UnexpectedFrame) as cm: <del> with self.assertRaises(QuicConnectionError) as cm: <36>:<add> self.assertEqual( <add> str(cm.exception), "HEADERS frame is not allowed in this state" <add> ) <del> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_headers_after_trailers(self): <0> """ <1> We should not receive HEADERS after receiving trailers. <2> """ <3> quic_client = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=True) <5> ) <6> quic_server = FakeQuicConnection( <7> configuration=QuicConfiguration(is_client=False) <8> ) <9> <10> h3_client = H3Connection(quic_client) <11> h3_server = H3Connection(quic_server) <12> <13> stream_id = quic_client.get_next_available_stream_id() <14> h3_client.send_headers( <15> stream_id=stream_id, <16> headers=[ <17> (b":method", b"GET"), <18> (b":scheme", b"https"), <19> (b":authority", b"localhost"), <20> (b":path", b"/"), <21> ], <22> ) <23> h3_client.send_headers( <24> stream_id=stream_id, headers=[(b"x-some-trailer", b"foo")], end_stream=True <25> ) <26> h3_transfer(quic_client, h3_server) <27> <28> with self.assertRaises(QuicConnectionError) as cm: <29> h3_server.handle_event( <30> StreamDataReceived( <31> stream_id=0, <32> data=encode_frame(FrameType.HEADERS, b""), <33> end_stream=False, <34> ) <35> ) <36> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME) <37>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) WrongStream(reason_phrase: str="") encode_frame(frame_type: int, frame_data: bytes) -> bytes H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_h3 FakeQuicConnection(configuration) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========unchanged ref 1=========== assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E] assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None at: unittest.case._AssertRaisesContext.__exit__ self.exception = exc_value.with_traceback(None) ===========changed ref 0=========== # module: aioquic.h3.connection + class WrongStream(ProtocolError): + error_code = ErrorCode.HTTP_WRONG_STREAM + ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_data_before_headers(self): """ We should not receive DATA before receiving headers. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) + with self.assertRaises(UnexpectedFrame) as cm: - with self.assertRaises(QuicConnectionError) as cm: h3_server.handle_event( StreamDataReceived( stream_id=0, data=encode_frame(FrameType.DATA, b""), end_stream=False, ) ) + self.assertEqual(str(cm.exception), "DATA frame is not allowed in this state") - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME) ===========changed ref 2=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): + def test_handle_control_stream_duplicate(self): + """ + We must only receive a single control stream. + """ + quic_server = FakeQuicConnection( + configuration=QuicConfiguration(is_client=False) + ) + h3_server = H3Connection(quic_server) + + # receive a first control stream + h3_server.handle_event( + StreamDataReceived( + stream_id=2, data=encode_uint_var(StreamType.CONTROL), end_stream=False + ) + ) + with self.assertRaises(StreamCreationError) as cm: + # receive a second control stream + h3_server.handle_event( + StreamDataReceived( + stream_id=6, + data=encode_uint_var(StreamType.CONTROL), + end_stream=False, + ) + ) + self.assertEqual(str(cm.exception), "Only one control stream is allowed") + ===========changed ref 3=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_push_frame_wrong_frame_type(self): + """ + We should not received SETTINGS on a push stream. + """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) + with self.assertRaises(WrongStream) as cm: - with self.assertRaises(QuicConnectionError) as cm: h3_client.handle_event( StreamDataReceived( stream_id=15, data=encode_uint_var(StreamType.PUSH) + encode_uint_var(0) # push ID + encode_frame(FrameType.SETTINGS, b""), end_stream=False, ) ) - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) - self.assertEqual( + self.assertEqual(str(cm.exception), "Invalid frame type on push stream") - str(cm.exception), "Error: 10, reason: Invalid frame type on push stream" - ) ===========changed ref 4=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_headers(self): """ We should not receive HEADERS on the control stream. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) + with self.assertRaises(WrongStream) as cm: - with self.assertRaises(QuicConnectionError) as cm: + h3_server.handle_event( + StreamDataReceived( + stream_id=2, + data=encode_uint_var(StreamType.CONTROL) + + encode_frame(FrameType.HEADERS, b""), + end_stream=False, + ) + ) + self.assertEqual(str(cm.exception), "Invalid frame type on control stream") - h3_server._handle_control_frame(FrameType.HEADERS, b"") - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)
tests.test_h3/H3ConnectionTest.test_handle_request_frame_push_promise_from_client
Modified
aiortc~aioquic
286c400feb5e3fdee22b0434ae89351de094c88a
[http3] add some internal exception types
<8>:<add> with self.assertRaises(UnexpectedFrame) as cm: <del> with self.assertRaises(QuicConnectionError) as cm: <16>:<add> self.assertEqual(str(cm.exception), "Clients must not send PUSH_PROMISE") <del> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME)
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_push_promise_from_client(self): <0> """ <1> A server should not receive PUSH_PROMISE on a request stream. <2> """ <3> quic_server = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=False) <5> ) <6> h3_server = H3Connection(quic_server) <7> <8> with self.assertRaises(QuicConnectionError) as cm: <9> h3_server.handle_event( <10> StreamDataReceived( <11> stream_id=0, <12> data=encode_frame(FrameType.PUSH_PROMISE, b""), <13> end_stream=False, <14> ) <15> ) <16> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME) <17>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) StreamCreationError(reason_phrase: str="") at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_h3 FakeQuicConnection(configuration) at: tests.test_h3.H3ConnectionTest.test_handle_qpack_decoder_duplicate h3_client = H3Connection(quic_client) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E] assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None ===========unchanged ref 1=========== at: unittest.case._AssertRaisesContext.__exit__ self.exception = exc_value.with_traceback(None) ===========changed ref 0=========== # module: aioquic.h3.connection + class StreamCreationError(ProtocolError): + error_code = ErrorCode.HTTP_STREAM_CREATION_ERROR + ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): + def test_handle_qpack_decoder_duplicate(self): + """ + We must only receive a single QPACK decoder stream. + """ + quic_client = FakeQuicConnection( + configuration=QuicConfiguration(is_client=True) + ) + h3_client = H3Connection(quic_client) + + h3_client.handle_event( + StreamDataReceived( + stream_id=11, + data=encode_uint_var(StreamType.QPACK_DECODER), + end_stream=False, + ) + ) + with self.assertRaises(StreamCreationError) as cm: + h3_client.handle_event( + StreamDataReceived( + stream_id=15, + data=encode_uint_var(StreamType.QPACK_DECODER), + end_stream=False, + ) + ) + self.assertEqual(str(cm.exception), "Only one QPACK decoder stream is allowed") + ===========changed ref 2=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_data_before_headers(self): """ We should not receive DATA before receiving headers. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) + with self.assertRaises(UnexpectedFrame) as cm: - with self.assertRaises(QuicConnectionError) as cm: h3_server.handle_event( StreamDataReceived( stream_id=0, data=encode_frame(FrameType.DATA, b""), end_stream=False, ) ) + self.assertEqual(str(cm.exception), "DATA frame is not allowed in this state") - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME) ===========changed ref 3=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): + def test_handle_control_stream_duplicate(self): + """ + We must only receive a single control stream. + """ + quic_server = FakeQuicConnection( + configuration=QuicConfiguration(is_client=False) + ) + h3_server = H3Connection(quic_server) + + # receive a first control stream + h3_server.handle_event( + StreamDataReceived( + stream_id=2, data=encode_uint_var(StreamType.CONTROL), end_stream=False + ) + ) + with self.assertRaises(StreamCreationError) as cm: + # receive a second control stream + h3_server.handle_event( + StreamDataReceived( + stream_id=6, + data=encode_uint_var(StreamType.CONTROL), + end_stream=False, + ) + ) + self.assertEqual(str(cm.exception), "Only one control stream is allowed") + ===========changed ref 4=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_push_frame_wrong_frame_type(self): + """ + We should not received SETTINGS on a push stream. + """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) + with self.assertRaises(WrongStream) as cm: - with self.assertRaises(QuicConnectionError) as cm: h3_client.handle_event( StreamDataReceived( stream_id=15, data=encode_uint_var(StreamType.PUSH) + encode_uint_var(0) # push ID + encode_frame(FrameType.SETTINGS, b""), end_stream=False, ) ) - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) - self.assertEqual( + self.assertEqual(str(cm.exception), "Invalid frame type on push stream") - str(cm.exception), "Error: 10, reason: Invalid frame type on push stream" - ) ===========changed ref 5=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_headers(self): """ We should not receive HEADERS on the control stream. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) + with self.assertRaises(WrongStream) as cm: - with self.assertRaises(QuicConnectionError) as cm: + h3_server.handle_event( + StreamDataReceived( + stream_id=2, + data=encode_uint_var(StreamType.CONTROL) + + encode_frame(FrameType.HEADERS, b""), + end_stream=False, + ) + ) + self.assertEqual(str(cm.exception), "Invalid frame type on control stream") - h3_server._handle_control_frame(FrameType.HEADERS, b"") - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM)
tests.test_h3/H3ConnectionTest.test_handle_request_frame_wrong_frame_type
Modified
aiortc~aioquic
286c400feb5e3fdee22b0434ae89351de094c88a
[http3] add some internal exception types
<5>:<add> with self.assertRaises(WrongStream) as cm: <del> with self.assertRaises(QuicConnectionError) as cm: <13>:<del> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) <14>:<del> self.assertEqual( <15>:<add> self.assertEqual(str(cm.exception), "Invalid frame type on request stream") <del> str(cm.exception), "Error: 10, reason: Invalid frame type on request stream" <16>:<del> )
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_wrong_frame_type(self): <0> quic_server = FakeQuicConnection( <1> configuration=QuicConfiguration(is_client=False) <2> ) <3> h3_server = H3Connection(quic_server) <4> <5> with self.assertRaises(QuicConnectionError) as cm: <6> h3_server.handle_event( <7> StreamDataReceived( <8> stream_id=0, <9> data=encode_frame(FrameType.SETTINGS, b""), <10> end_stream=False, <11> ) <12> ) <13> self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_WRONG_STREAM) <14> self.assertEqual( <15> str(cm.exception), "Error: 10, reason: Invalid frame type on request stream" <16> ) <17>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) QpackDecoderStreamError(reason_phrase: str="") H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_h3 FakeQuicConnection(configuration) at: tests.test_h3.H3ConnectionTest.test_handle_qpack_decoder_stream_error quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========unchanged ref 1=========== assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E] assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None at: unittest.case._AssertRaisesContext.__exit__ self.exception = exc_value.with_traceback(None) ===========changed ref 0=========== # module: aioquic.h3.connection + class QpackDecoderStreamError(ProtocolError): + error_code = ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR + ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): + def test_handle_qpack_decoder_stream_error(self): + """ + Receiving garbage on the QPACK decoder stream triggers an exception. + """ + quic_client = FakeQuicConnection( + configuration=QuicConfiguration(is_client=True) + ) + h3_client = H3Connection(quic_client) + + with self.assertRaises(QpackDecoderStreamError) as cm: + h3_client.handle_event( + StreamDataReceived( + stream_id=11, + data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", + end_stream=False, + ) + ) + self.assertEqual(str(cm.exception), "") + ===========changed ref 2=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_push_promise_from_client(self): """ A server should not receive PUSH_PROMISE on a request stream. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) + with self.assertRaises(UnexpectedFrame) as cm: - with self.assertRaises(QuicConnectionError) as cm: h3_server.handle_event( StreamDataReceived( stream_id=0, data=encode_frame(FrameType.PUSH_PROMISE, b""), end_stream=False, ) ) + self.assertEqual(str(cm.exception), "Clients must not send PUSH_PROMISE") - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME) ===========changed ref 3=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): + def test_handle_qpack_decoder_duplicate(self): + """ + We must only receive a single QPACK decoder stream. + """ + quic_client = FakeQuicConnection( + configuration=QuicConfiguration(is_client=True) + ) + h3_client = H3Connection(quic_client) + + h3_client.handle_event( + StreamDataReceived( + stream_id=11, + data=encode_uint_var(StreamType.QPACK_DECODER), + end_stream=False, + ) + ) + with self.assertRaises(StreamCreationError) as cm: + h3_client.handle_event( + StreamDataReceived( + stream_id=15, + data=encode_uint_var(StreamType.QPACK_DECODER), + end_stream=False, + ) + ) + self.assertEqual(str(cm.exception), "Only one QPACK decoder stream is allowed") + ===========changed ref 4=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_data_before_headers(self): """ We should not receive DATA before receiving headers. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) + with self.assertRaises(UnexpectedFrame) as cm: - with self.assertRaises(QuicConnectionError) as cm: h3_server.handle_event( StreamDataReceived( stream_id=0, data=encode_frame(FrameType.DATA, b""), end_stream=False, ) ) + self.assertEqual(str(cm.exception), "DATA frame is not allowed in this state") - self.assertEqual(cm.exception.error_code, ErrorCode.HTTP_UNEXPECTED_FRAME) ===========changed ref 5=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): + def test_handle_control_stream_duplicate(self): + """ + We must only receive a single control stream. + """ + quic_server = FakeQuicConnection( + configuration=QuicConfiguration(is_client=False) + ) + h3_server = H3Connection(quic_server) + + # receive a first control stream + h3_server.handle_event( + StreamDataReceived( + stream_id=2, data=encode_uint_var(StreamType.CONTROL), end_stream=False + ) + ) + with self.assertRaises(StreamCreationError) as cm: + # receive a second control stream + h3_server.handle_event( + StreamDataReceived( + stream_id=6, + data=encode_uint_var(StreamType.CONTROL), + end_stream=False, + ) + ) + self.assertEqual(str(cm.exception), "Only one control stream is allowed") +
aioquic.h3.connection/H3Connection.__init__
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<4>:<add> self._is_done = False
# module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): <0> self._max_table_capacity = 0x100 <1> self._blocked_streams = 0x10 <2> <3> self._is_client = quic.configuration.is_client <4> self._quic = quic <5> self._decoder = pylsqpack.Decoder( <6> self._max_table_capacity, self._blocked_streams <7> ) <8> self._encoder = pylsqpack.Encoder() <9> self._stream: Dict[int, H3Stream] = {} <10> <11> self._max_push_id: Optional[int] = 8 if self._is_client else None <12> self._next_push_id: int = 0 <13> <14> self._local_control_stream_id: Optional[int] = None <15> self._local_decoder_stream_id: Optional[int] = None <16> self._local_encoder_stream_id: Optional[int] = None <17> <18> self._peer_control_stream_id: Optional[int] = None <19> self._peer_decoder_stream_id: Optional[int] = None <20> self._peer_encoder_stream_id: Optional[int] = None <21> <22> self._init_connection() <23>
===========unchanged ref 0=========== at: aioquic.h3.connection H3Stream() at: aioquic.h3.connection.H3Connection._handle_control_frame self._max_push_id = parse_max_push_id(frame_data) at: aioquic.h3.connection.H3Connection._init_connection self._local_control_stream_id = self._create_uni_stream(StreamType.CONTROL) self._local_encoder_stream_id = self._create_uni_stream( StreamType.QPACK_ENCODER ) self._local_decoder_stream_id = self._create_uni_stream( StreamType.QPACK_DECODER ) at: aioquic.h3.connection.H3Connection._receive_stream_data_uni self._peer_control_stream_id = stream_id self._peer_decoder_stream_id = stream_id self._peer_encoder_stream_id = stream_id at: aioquic.h3.connection.H3Connection.handle_event self._is_done = True at: aioquic.h3.connection.H3Connection.send_push_promise self._next_push_id += 1 at: aioquic.quic.configuration.QuicConfiguration alpn_protocols: Optional[List[str]] = None certificate: Any = None connection_id_length: int = 8 idle_timeout: float = 60.0 is_client: bool = True private_key: Any = None quic_logger: Optional[QuicLogger] = None secrets_log_file: TextIO = None server_name: Optional[str] = None session_ticket: Optional[SessionTicket] = None supported_versions: List[int] = field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] ) ===========unchanged ref 1=========== at: aioquic.quic.connection QuicConnection(*, configuration: QuicConfiguration, logger_connection_id: Optional[bytes]=None, original_connection_id: Optional[bytes]=None, session_ticket_fetcher: Optional[tls.SessionTicketFetcher]=None, session_ticket_handler: Optional[tls.SessionTicketHandler]=None) at: typing Dict = _alias(dict, 2, inst=False, name='Dict')
aioquic.h3.connection/H3Connection.handle_event
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<5>:<add> if isinstance(event, StreamDataReceived) and not self._is_done: <del> if isinstance(event, StreamDataReceived): <9>:<add> try: <add> if stream_id % 4 == 0: <del> if stream_id % 4 == 0: <10>:<add> return self._receive_request_or_push_data( <del> return self._receive_request_or_push_data( <11>:<add> stream_id, event.data, event.end_stream <del> stream_id, event.data, event.end_stream <12>:<add> ) <del> ) <13>:<add> elif stream_is_unidirectional(stream_id): <del> elif stream_is_unidirectional(stream_id): <14>:<add> return self._receive_stream_data_uni( <del> return self._receive_stream_data_uni( <15>:<add> stream_id, event.data, event.end_stream <del> stream_id, event.data, event.end_stream <16>:<add> ) <add> except ProtocolError as exc: <add> self._is_done = True <add> self._quic.close( <add> error_code=exc.error_code, reason_phrase=exc.reason_phrase
# module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: <0> """ <1> Handle a QUIC event and return a list of HTTP events. <2> <3> :param event: The QUIC event to handle. <4> """ <5> if isinstance(event, StreamDataReceived): <6> stream_id = event.stream_id <7> if stream_id not in self._stream: <8> self._stream[stream_id] = H3Stream() <9> if stream_id % 4 == 0: <10> return self._receive_request_or_push_data( <11> stream_id, event.data, event.end_stream <12> ) <13> elif stream_is_unidirectional(stream_id): <14> return self._receive_stream_data_uni( <15> stream_id, event.data, event.end_stream <16> ) <17> return [] <18>
===========unchanged ref 0=========== at: aioquic.h3.connection H3Stream() at: aioquic.h3.connection.H3Connection _receive_request_or_push_data(stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event] _receive_stream_data_uni(stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event] at: aioquic.h3.connection.H3Connection.__init__ self._is_done = False self._stream: Dict[int, H3Stream] = {} at: aioquic.h3.connection.H3Connection.handle_event self._is_done = True at: aioquic.h3.events H3Event() at: aioquic.quic.connection stream_is_unidirectional(stream_id: int) -> bool at: aioquic.quic.events QuicEvent() StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: typing List = _alias(list, 1, inst=False, name='List') ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client + self._is_done = False self._quic = quic self._decoder = pylsqpack.Decoder( self._max_table_capacity, self._blocked_streams ) self._encoder = pylsqpack.Encoder() self._stream: Dict[int, H3Stream] = {} self._max_push_id: Optional[int] = 8 if self._is_client else None self._next_push_id: int = 0 self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None self._init_connection()
tests.test_h3/FakeQuicConnection.__init__
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<0>:<add> self.closed = None
# module: tests.test_h3 class FakeQuicConnection: def __init__(self, configuration): <0> self.configuration = configuration <1> self.stream_queue = [] <2> self._events = [] <3> self._next_stream_bidi = 0 if configuration.is_client else 1 <4> self._next_stream_uni = 2 if configuration.is_client else 3 <5>
===========unchanged ref 0=========== at: aioquic.quic.configuration.QuicConfiguration alpn_protocols: Optional[List[str]] = None certificate: Any = None connection_id_length: int = 8 idle_timeout: float = 60.0 is_client: bool = True private_key: Any = None quic_logger: Optional[QuicLogger] = None secrets_log_file: TextIO = None server_name: Optional[str] = None session_ticket: Optional[SessionTicket] = None supported_versions: List[int] = field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] ) at: tests.test_h3.FakeQuicConnection.__init__ self.closed = None at: tests.test_h3.FakeQuicConnection.get_next_available_stream_id self._next_stream_uni += 4 self._next_stream_bidi += 4 ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client + self._is_done = False self._quic = quic self._decoder = pylsqpack.Decoder( self._max_table_capacity, self._blocked_streams ) self._encoder = pylsqpack.Encoder() self._stream: Dict[int, H3Stream] = {} self._max_push_id: Optional[int] = 8 if self._is_client else None self._next_push_id: int = 0 self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None self._init_connection() ===========changed ref 1=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ + if isinstance(event, StreamDataReceived) and not self._is_done: - if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() + try: + if stream_id % 4 == 0: - if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_request_or_push_data( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) - ) + elif stream_is_unidirectional(stream_id): - elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) + except ProtocolError as exc: + self._is_done = True + self._quic.close( + error_code=exc.error_code, reason_phrase=exc.reason_phrase ) return []
tests.test_h3/H3ConnectionTest.test_handle_control_frame_headers
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<8>:<del> with self.assertRaises(WrongStream) as cm: <9>:<add> h3_server.handle_event( <del> h3_server.handle_event( <10>:<add> StreamDataReceived( <del> StreamDataReceived( <11>:<add> stream_id=2, <del> stream_id=2, <12>:<add> data=encode_uint_var(StreamType.CONTROL) <del> data=encode_uint_var(StreamType.CONTROL) <13>:<add> + encode_frame(FrameType.HEADERS, b""), <del> + encode_frame(FrameType.HEADERS, b""), <14>:<add> end_stream=False, <del> end_stream=False, <15>:<del> ) <17>:<add> ) <add> self.assertEqual( <add> quic_server.closed, <add> (ErrorCode.HTTP_WRONG_STREAM, "Invalid frame type on control stream"), <add> ) <del> self.assertEqual(str(cm.exception), "Invalid frame type on control stream")
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_headers(self): <0> """ <1> We should not receive HEADERS on the control stream. <2> """ <3> quic_server = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=False) <5> ) <6> h3_server = H3Connection(quic_server) <7> <8> with self.assertRaises(WrongStream) as cm: <9> h3_server.handle_event( <10> StreamDataReceived( <11> stream_id=2, <12> data=encode_uint_var(StreamType.CONTROL) <13> + encode_frame(FrameType.HEADERS, b""), <14> end_stream=False, <15> ) <16> ) <17> self.assertEqual(str(cm.exception), "Invalid frame type on control stream") <18>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) encode_frame(frame_type: int, frame_data: bytes) -> bytes H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: aioquic.quic.events.StreamDataReceived data: bytes end_stream: bool stream_id: int at: tests.test_h3 FakeQuicConnection(configuration) at: tests.test_h3.FakeQuicConnection.__init__ self.closed = None ===========unchanged ref 1=========== at: tests.test_h3.FakeQuicConnection.close self.closed = (error_code, reason_phrase) at: unittest.case.TestCase failureException: Type[BaseException] longMessage: bool maxDiff: Optional[int] _testMethodName: str _testMethodDoc: str assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ + if isinstance(event, StreamDataReceived) and not self._is_done: - if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() + try: + if stream_id % 4 == 0: - if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_request_or_push_data( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) - ) + elif stream_is_unidirectional(stream_id): - elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) + except ProtocolError as exc: + self._is_done = True + self._quic.close( + error_code=exc.error_code, reason_phrase=exc.reason_phrase ) return [] ===========changed ref 1=========== # module: tests.test_h3 class FakeQuicConnection: + def close(self, error_code, reason_phrase): + self.closed = (error_code, reason_phrase) + ===========changed ref 2=========== # module: tests.test_h3 class FakeQuicConnection: def __init__(self, configuration): + self.closed = None self.configuration = configuration self.stream_queue = [] self._events = [] self._next_stream_bidi = 0 if configuration.is_client else 1 self._next_stream_uni = 2 if configuration.is_client else 3 ===========changed ref 3=========== # module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client + self._is_done = False self._quic = quic self._decoder = pylsqpack.Decoder( self._max_table_capacity, self._blocked_streams ) self._encoder = pylsqpack.Encoder() self._stream: Dict[int, H3Stream] = {} self._max_push_id: Optional[int] = 8 if self._is_client else None self._next_push_id: int = 0 self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None self._init_connection()
tests.test_h3/H3ConnectionTest.test_handle_control_frame_max_push_id_from_server
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<8>:<del> with self.assertRaises(UnexpectedFrame) as cm: <9>:<add> h3_client.handle_event( <del> h3_client.handle_event( <10>:<add> StreamDataReceived( <del> StreamDataReceived( <11>:<add> stream_id=3, <del> stream_id=3, <12>:<add> data=encode_uint_var(StreamType.CONTROL) <del> data=encode_uint_var(StreamType.CONTROL) <13>:<add> + encode_frame(FrameType.MAX_PUSH_ID, b""), <del> + encode_frame(FrameType.MAX_PUSH_ID, b""), <14>:<add> end_stream=False, <del> end_stream=False, <15>:<del> ) <17>:<add> ) <add> self.assertEqual( <add> quic_client.closed, <add> (ErrorCode.HTTP_UNEXPECTED_FRAME, "Servers must not send MAX_PUSH_ID"), <add> ) <del> self.assertEqual(str(cm.exception), "Servers must not send MAX_PUSH_ID")
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_max_push_id_from_server(self): <0> """ <1> A client should not receive MAX_PUSH_ID on the control stream. <2> """ <3> quic_client = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=True) <5> ) <6> h3_client = H3Connection(quic_client) <7> <8> with self.assertRaises(UnexpectedFrame) as cm: <9> h3_client.handle_event( <10> StreamDataReceived( <11> stream_id=3, <12> data=encode_uint_var(StreamType.CONTROL) <13> + encode_frame(FrameType.MAX_PUSH_ID, b""), <14> end_stream=False, <15> ) <16> ) <17> self.assertEqual(str(cm.exception), "Servers must not send MAX_PUSH_ID") <18>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) encode_frame(frame_type: int, frame_data: bytes) -> bytes H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_h3 FakeQuicConnection(configuration) at: tests.test_h3.H3ConnectionTest maxDiff = None at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ + if isinstance(event, StreamDataReceived) and not self._is_done: - if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() + try: + if stream_id % 4 == 0: - if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_request_or_push_data( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) - ) + elif stream_is_unidirectional(stream_id): - elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) + except ProtocolError as exc: + self._is_done = True + self._quic.close( + error_code=exc.error_code, reason_phrase=exc.reason_phrase ) return [] ===========changed ref 1=========== # module: tests.test_h3 class FakeQuicConnection: + def close(self, error_code, reason_phrase): + self.closed = (error_code, reason_phrase) + ===========changed ref 2=========== # module: tests.test_h3 class FakeQuicConnection: def __init__(self, configuration): + self.closed = None self.configuration = configuration self.stream_queue = [] self._events = [] self._next_stream_bidi = 0 if configuration.is_client else 1 self._next_stream_uni = 2 if configuration.is_client else 3 ===========changed ref 3=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_headers(self): """ We should not receive HEADERS on the control stream. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) - with self.assertRaises(WrongStream) as cm: + h3_server.handle_event( - h3_server.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=2, - stream_id=2, + data=encode_uint_var(StreamType.CONTROL) - data=encode_uint_var(StreamType.CONTROL) + + encode_frame(FrameType.HEADERS, b""), - + encode_frame(FrameType.HEADERS, b""), + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_server.closed, + (ErrorCode.HTTP_WRONG_STREAM, "Invalid frame type on control stream"), + ) - self.assertEqual(str(cm.exception), "Invalid frame type on control stream") ===========changed ref 4=========== # module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client + self._is_done = False self._quic = quic self._decoder = pylsqpack.Decoder( self._max_table_capacity, self._blocked_streams ) self._encoder = pylsqpack.Encoder() self._stream: Dict[int, H3Stream] = {} self._max_push_id: Optional[int] = 8 if self._is_client else None self._next_push_id: int = 0 self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None self._init_connection()
tests.test_h3/H3ConnectionTest.test_handle_control_stream_duplicate
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<14>:<add> <del> with self.assertRaises(StreamCreationError) as cm: <15>:<add> # receive a second control stream <del> # receive a second control stream <16>:<add> h3_server.handle_event( <del> h3_server.handle_event( <17>:<add> StreamDataReceived( <del> StreamDataReceived( <18>:<del> stream_id=6, <19>:<add> stream_id=6, data=encode_uint_var(StreamType.CONTROL), end_stream=False <del> data=encode_uint_var(StreamType.CONTROL), <20>:<del> end_stream=False, <21>:<del> ) <23>:<add> ) <add> self.assertEqual( <add> quic_server.closed, <add> ( <add> ErrorCode.HTTP_STREAM_CREATION_ERROR, <add> "Only one control stream is allowed", <add> ), <add> ) <del> self.assertEqual(str(cm.exception), "Only one control stream is allowed")
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_stream_duplicate(self): <0> """ <1> We must only receive a single control stream. <2> """ <3> quic_server = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=False) <5> ) <6> h3_server = H3Connection(quic_server) <7> <8> # receive a first control stream <9> h3_server.handle_event( <10> StreamDataReceived( <11> stream_id=2, data=encode_uint_var(StreamType.CONTROL), end_stream=False <12> ) <13> ) <14> with self.assertRaises(StreamCreationError) as cm: <15> # receive a second control stream <16> h3_server.handle_event( <17> StreamDataReceived( <18> stream_id=6, <19> data=encode_uint_var(StreamType.CONTROL), <20> end_stream=False, <21> ) <22> ) <23> self.assertEqual(str(cm.exception), "Only one control stream is allowed") <24>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_h3 FakeQuicConnection(configuration) ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ + if isinstance(event, StreamDataReceived) and not self._is_done: - if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() + try: + if stream_id % 4 == 0: - if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_request_or_push_data( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) - ) + elif stream_is_unidirectional(stream_id): - elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) + except ProtocolError as exc: + self._is_done = True + self._quic.close( + error_code=exc.error_code, reason_phrase=exc.reason_phrase ) return [] ===========changed ref 1=========== # module: tests.test_h3 class FakeQuicConnection: + def close(self, error_code, reason_phrase): + self.closed = (error_code, reason_phrase) + ===========changed ref 2=========== # module: tests.test_h3 class FakeQuicConnection: def __init__(self, configuration): + self.closed = None self.configuration = configuration self.stream_queue = [] self._events = [] self._next_stream_bidi = 0 if configuration.is_client else 1 self._next_stream_uni = 2 if configuration.is_client else 3 ===========changed ref 3=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_max_push_id_from_server(self): """ A client should not receive MAX_PUSH_ID on the control stream. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(UnexpectedFrame) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=3, - stream_id=3, + data=encode_uint_var(StreamType.CONTROL) - data=encode_uint_var(StreamType.CONTROL) + + encode_frame(FrameType.MAX_PUSH_ID, b""), - + encode_frame(FrameType.MAX_PUSH_ID, b""), + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, + (ErrorCode.HTTP_UNEXPECTED_FRAME, "Servers must not send MAX_PUSH_ID"), + ) - self.assertEqual(str(cm.exception), "Servers must not send MAX_PUSH_ID") ===========changed ref 4=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_headers(self): """ We should not receive HEADERS on the control stream. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) - with self.assertRaises(WrongStream) as cm: + h3_server.handle_event( - h3_server.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=2, - stream_id=2, + data=encode_uint_var(StreamType.CONTROL) - data=encode_uint_var(StreamType.CONTROL) + + encode_frame(FrameType.HEADERS, b""), - + encode_frame(FrameType.HEADERS, b""), + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_server.closed, + (ErrorCode.HTTP_WRONG_STREAM, "Invalid frame type on control stream"), + ) - self.assertEqual(str(cm.exception), "Invalid frame type on control stream") ===========changed ref 5=========== # module: aioquic.h3.connection class H3Connection: def __init__(self, quic: QuicConnection): self._max_table_capacity = 0x100 self._blocked_streams = 0x10 self._is_client = quic.configuration.is_client + self._is_done = False self._quic = quic self._decoder = pylsqpack.Decoder( self._max_table_capacity, self._blocked_streams ) self._encoder = pylsqpack.Encoder() self._stream: Dict[int, H3Stream] = {} self._max_push_id: Optional[int] = 8 if self._is_client else None self._next_push_id: int = 0 self._local_control_stream_id: Optional[int] = None self._local_decoder_stream_id: Optional[int] = None self._local_encoder_stream_id: Optional[int] = None self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None self._init_connection()
tests.test_h3/H3ConnectionTest.test_handle_push_frame_wrong_frame_type
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<8>:<del> with self.assertRaises(WrongStream) as cm: <9>:<add> h3_client.handle_event( <del> h3_client.handle_event( <10>:<add> StreamDataReceived( <del> StreamDataReceived( <11>:<add> stream_id=15, <del> stream_id=15, <12>:<add> data=encode_uint_var(StreamType.PUSH) <del> data=encode_uint_var(StreamType.PUSH) <13>:<add> + encode_uint_var(0) # push ID <del> + encode_uint_var(0) # push ID <14>:<add> + encode_frame(FrameType.SETTINGS, b""), <del> + encode_frame(FrameType.SETTINGS, b""), <15>:<add> end_stream=False, <del> end_stream=False, <16>:<del> ) <18>:<add> ) <add> self.assertEqual( <add> quic_client.closed, <add> (ErrorCode.HTTP_WRONG_STREAM, "Invalid frame type on push stream"), <add> ) <del> self.assertEqual(str(cm.exception), "Invalid frame type on push stream")
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_push_frame_wrong_frame_type(self): <0> """ <1> We should not received SETTINGS on a push stream. <2> """ <3> quic_client = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=True) <5> ) <6> h3_client = H3Connection(quic_client) <7> <8> with self.assertRaises(WrongStream) as cm: <9> h3_client.handle_event( <10> StreamDataReceived( <11> stream_id=15, <12> data=encode_uint_var(StreamType.PUSH) <13> + encode_uint_var(0) # push ID <14> + encode_frame(FrameType.SETTINGS, b""), <15> end_stream=False, <16> ) <17> ) <18> self.assertEqual(str(cm.exception), "Invalid frame type on push stream") <19>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_h3 FakeQuicConnection(configuration) at: tests.test_h3.FakeQuicConnection.__init__ self.closed = None at: tests.test_h3.FakeQuicConnection.close self.closed = (error_code, reason_phrase) at: tests.test_h3.H3ConnectionTest.test_handle_control_stream_duplicate quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ + if isinstance(event, StreamDataReceived) and not self._is_done: - if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() + try: + if stream_id % 4 == 0: - if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_request_or_push_data( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) - ) + elif stream_is_unidirectional(stream_id): - elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) + except ProtocolError as exc: + self._is_done = True + self._quic.close( + error_code=exc.error_code, reason_phrase=exc.reason_phrase ) return [] ===========changed ref 1=========== # module: tests.test_h3 class FakeQuicConnection: + def close(self, error_code, reason_phrase): + self.closed = (error_code, reason_phrase) + ===========changed ref 2=========== # module: tests.test_h3 class FakeQuicConnection: def __init__(self, configuration): + self.closed = None self.configuration = configuration self.stream_queue = [] self._events = [] self._next_stream_bidi = 0 if configuration.is_client else 1 self._next_stream_uni = 2 if configuration.is_client else 3 ===========changed ref 3=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_max_push_id_from_server(self): """ A client should not receive MAX_PUSH_ID on the control stream. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(UnexpectedFrame) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=3, - stream_id=3, + data=encode_uint_var(StreamType.CONTROL) - data=encode_uint_var(StreamType.CONTROL) + + encode_frame(FrameType.MAX_PUSH_ID, b""), - + encode_frame(FrameType.MAX_PUSH_ID, b""), + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, + (ErrorCode.HTTP_UNEXPECTED_FRAME, "Servers must not send MAX_PUSH_ID"), + ) - self.assertEqual(str(cm.exception), "Servers must not send MAX_PUSH_ID") ===========changed ref 4=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_headers(self): """ We should not receive HEADERS on the control stream. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) - with self.assertRaises(WrongStream) as cm: + h3_server.handle_event( - h3_server.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=2, - stream_id=2, + data=encode_uint_var(StreamType.CONTROL) - data=encode_uint_var(StreamType.CONTROL) + + encode_frame(FrameType.HEADERS, b""), - + encode_frame(FrameType.HEADERS, b""), + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_server.closed, + (ErrorCode.HTTP_WRONG_STREAM, "Invalid frame type on control stream"), + ) - self.assertEqual(str(cm.exception), "Invalid frame type on control stream")
tests.test_h3/H3ConnectionTest.test_handle_qpack_decoder_duplicate
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<8>:<add> # receive a first decoder stream <15>:<add> <add> # receive a second decoder stream <del> with self.assertRaises(StreamCreationError) as cm: <16>:<add> h3_client.handle_event( <del> h3_client.handle_event( <17>:<add> StreamDataReceived( <del> StreamDataReceived( <18>:<add> stream_id=15, <del> stream_id=15, <19>:<add> data=encode_uint_var(StreamType.QPACK_DECODER), <del> data=encode_uint_var(StreamType.QPACK_DECODER), <20>:<add> end_stream=False, <del> end_stream=False, <21>:<del> ) <23>:<add> ) <add> self.assertEqual( <add> quic_client.closed, <add> ( <add> ErrorCode.HTTP_STREAM_CREATION_ERROR, <add> "Only one QPACK decoder stream is allowed", <add> ), <add> ) <del> self.assertEqual(str(cm.exception), "Only one QPACK decoder stream is allowed")
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_decoder_duplicate(self): <0> """ <1> We must only receive a single QPACK decoder stream. <2> """ <3> quic_client = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=True) <5> ) <6> h3_client = H3Connection(quic_client) <7> <8> h3_client.handle_event( <9> StreamDataReceived( <10> stream_id=11, <11> data=encode_uint_var(StreamType.QPACK_DECODER), <12> end_stream=False, <13> ) <14> ) <15> with self.assertRaises(StreamCreationError) as cm: <16> h3_client.handle_event( <17> StreamDataReceived( <18> stream_id=15, <19> data=encode_uint_var(StreamType.QPACK_DECODER), <20> end_stream=False, <21> ) <22> ) <23> self.assertEqual(str(cm.exception), "Only one QPACK decoder stream is allowed") <24>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) encode_frame(frame_type: int, frame_data: bytes) -> bytes H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_h3 FakeQuicConnection(configuration) at: tests.test_h3.FakeQuicConnection.__init__ self.closed = None at: tests.test_h3.FakeQuicConnection.close self.closed = (error_code, reason_phrase) ===========unchanged ref 1=========== at: tests.test_h3.H3ConnectionTest.test_handle_push_frame_wrong_frame_type quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ + if isinstance(event, StreamDataReceived) and not self._is_done: - if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() + try: + if stream_id % 4 == 0: - if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_request_or_push_data( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) - ) + elif stream_is_unidirectional(stream_id): - elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) + except ProtocolError as exc: + self._is_done = True + self._quic.close( + error_code=exc.error_code, reason_phrase=exc.reason_phrase ) return [] ===========changed ref 1=========== # module: tests.test_h3 class FakeQuicConnection: + def close(self, error_code, reason_phrase): + self.closed = (error_code, reason_phrase) + ===========changed ref 2=========== # module: tests.test_h3 class FakeQuicConnection: def __init__(self, configuration): + self.closed = None self.configuration = configuration self.stream_queue = [] self._events = [] self._next_stream_bidi = 0 if configuration.is_client else 1 self._next_stream_uni = 2 if configuration.is_client else 3 ===========changed ref 3=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_push_frame_wrong_frame_type(self): """ We should not received SETTINGS on a push stream. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(WrongStream) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=15, - stream_id=15, + data=encode_uint_var(StreamType.PUSH) - data=encode_uint_var(StreamType.PUSH) + + encode_uint_var(0) # push ID - + encode_uint_var(0) # push ID + + encode_frame(FrameType.SETTINGS, b""), - + encode_frame(FrameType.SETTINGS, b""), + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, + (ErrorCode.HTTP_WRONG_STREAM, "Invalid frame type on push stream"), + ) - self.assertEqual(str(cm.exception), "Invalid frame type on push stream") ===========changed ref 4=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_control_frame_max_push_id_from_server(self): """ A client should not receive MAX_PUSH_ID on the control stream. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(UnexpectedFrame) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=3, - stream_id=3, + data=encode_uint_var(StreamType.CONTROL) - data=encode_uint_var(StreamType.CONTROL) + + encode_frame(FrameType.MAX_PUSH_ID, b""), - + encode_frame(FrameType.MAX_PUSH_ID, b""), + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, + (ErrorCode.HTTP_UNEXPECTED_FRAME, "Servers must not send MAX_PUSH_ID"), + ) - self.assertEqual(str(cm.exception), "Servers must not send MAX_PUSH_ID")
tests.test_h3/H3ConnectionTest.test_handle_qpack_decoder_stream_error
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<8>:<del> with self.assertRaises(QpackDecoderStreamError) as cm: <9>:<add> h3_client.handle_event( <del> h3_client.handle_event( <10>:<add> StreamDataReceived( <del> StreamDataReceived( <11>:<add> stream_id=11, <del> stream_id=11, <12>:<add> data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", <del> data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", <13>:<add> end_stream=False, <del> end_stream=False, <14>:<del> ) <16>:<add> ) <add> self.assertEqual( <add> quic_client.closed, (ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR, "") <add> ) <del> self.assertEqual(str(cm.exception), "")
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_decoder_stream_error(self): <0> """ <1> Receiving garbage on the QPACK decoder stream triggers an exception. <2> """ <3> quic_client = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=True) <5> ) <6> h3_client = H3Connection(quic_client) <7> <8> with self.assertRaises(QpackDecoderStreamError) as cm: <9> h3_client.handle_event( <10> StreamDataReceived( <11> stream_id=11, <12> data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", <13> end_stream=False, <14> ) <15> ) <16> self.assertEqual(str(cm.exception), "") <17>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_h3.FakeQuicConnection.__init__ self.closed = None at: tests.test_h3.FakeQuicConnection.close self.closed = (error_code, reason_phrase) at: tests.test_h3.H3ConnectionTest.test_handle_qpack_decoder_duplicate quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ + if isinstance(event, StreamDataReceived) and not self._is_done: - if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() + try: + if stream_id % 4 == 0: - if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_request_or_push_data( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) - ) + elif stream_is_unidirectional(stream_id): - elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) + except ProtocolError as exc: + self._is_done = True + self._quic.close( + error_code=exc.error_code, reason_phrase=exc.reason_phrase ) return [] ===========changed ref 1=========== # module: tests.test_h3 class FakeQuicConnection: + def close(self, error_code, reason_phrase): + self.closed = (error_code, reason_phrase) + ===========changed ref 2=========== # module: tests.test_h3 class FakeQuicConnection: def __init__(self, configuration): + self.closed = None self.configuration = configuration self.stream_queue = [] self._events = [] self._next_stream_bidi = 0 if configuration.is_client else 1 self._next_stream_uni = 2 if configuration.is_client else 3 ===========changed ref 3=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_push_frame_wrong_frame_type(self): """ We should not received SETTINGS on a push stream. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(WrongStream) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=15, - stream_id=15, + data=encode_uint_var(StreamType.PUSH) - data=encode_uint_var(StreamType.PUSH) + + encode_uint_var(0) # push ID - + encode_uint_var(0) # push ID + + encode_frame(FrameType.SETTINGS, b""), - + encode_frame(FrameType.SETTINGS, b""), + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, + (ErrorCode.HTTP_WRONG_STREAM, "Invalid frame type on push stream"), + ) - self.assertEqual(str(cm.exception), "Invalid frame type on push stream") ===========changed ref 4=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_decoder_duplicate(self): """ We must only receive a single QPACK decoder stream. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) + # receive a first decoder stream h3_client.handle_event( StreamDataReceived( stream_id=11, data=encode_uint_var(StreamType.QPACK_DECODER), end_stream=False, ) ) + + # receive a second decoder stream - with self.assertRaises(StreamCreationError) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=15, - stream_id=15, + data=encode_uint_var(StreamType.QPACK_DECODER), - data=encode_uint_var(StreamType.QPACK_DECODER), + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, + ( + ErrorCode.HTTP_STREAM_CREATION_ERROR, + "Only one QPACK decoder stream is allowed", + ), + ) - self.assertEqual(str(cm.exception), "Only one QPACK decoder stream is allowed")
tests.test_h3/H3ConnectionTest.test_handle_qpack_encoder_duplicate
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<8>:<add> # receive a first encoder stream <15>:<add> <add> # receive a second encoder stream <del> with self.assertRaises(StreamCreationError) as cm: <16>:<add> h3_client.handle_event( <del> h3_client.handle_event( <17>:<add> StreamDataReceived( <del> StreamDataReceived( <18>:<add> stream_id=15, <del> stream_id=15, <19>:<add> data=encode_uint_var(StreamType.QPACK_ENCODER), <del> data=encode_uint_var(StreamType.QPACK_ENCODER), <20>:<add> end_stream=False, <del> end_stream=False, <21>:<del> ) <23>:<add> ) <add> self.assertEqual( <add> quic_client.closed, <add> ( <add> ErrorCode.HTTP_STREAM_CREATION_ERROR, <add> "Only one QPACK encoder stream is allowed", <add> ), <add> ) <del> self.assertEqual(str(cm.exception), "Only one QPACK encoder stream is allowed")
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_encoder_duplicate(self): <0> """ <1> We must only receive a single QPACK encoder stream. <2> """ <3> quic_client = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=True) <5> ) <6> h3_client = H3Connection(quic_client) <7> <8> h3_client.handle_event( <9> StreamDataReceived( <10> stream_id=11, <11> data=encode_uint_var(StreamType.QPACK_ENCODER), <12> end_stream=False, <13> ) <14> ) <15> with self.assertRaises(StreamCreationError) as cm: <16> h3_client.handle_event( <17> StreamDataReceived( <18> stream_id=15, <19> data=encode_uint_var(StreamType.QPACK_ENCODER), <20> end_stream=False, <21> ) <22> ) <23> self.assertEqual(str(cm.exception), "Only one QPACK encoder stream is allowed") <24>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_h3 FakeQuicConnection(configuration) at: tests.test_h3.FakeQuicConnection.__init__ self.closed = None at: tests.test_h3.FakeQuicConnection.close self.closed = (error_code, reason_phrase) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ + if isinstance(event, StreamDataReceived) and not self._is_done: - if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() + try: + if stream_id % 4 == 0: - if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_request_or_push_data( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) - ) + elif stream_is_unidirectional(stream_id): - elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) + except ProtocolError as exc: + self._is_done = True + self._quic.close( + error_code=exc.error_code, reason_phrase=exc.reason_phrase ) return [] ===========changed ref 1=========== # module: tests.test_h3 class FakeQuicConnection: + def close(self, error_code, reason_phrase): + self.closed = (error_code, reason_phrase) + ===========changed ref 2=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_decoder_stream_error(self): """ Receiving garbage on the QPACK decoder stream triggers an exception. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(QpackDecoderStreamError) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=11, - stream_id=11, + data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", - data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, (ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR, "") + ) - self.assertEqual(str(cm.exception), "") ===========changed ref 3=========== # module: tests.test_h3 class FakeQuicConnection: def __init__(self, configuration): + self.closed = None self.configuration = configuration self.stream_queue = [] self._events = [] self._next_stream_bidi = 0 if configuration.is_client else 1 self._next_stream_uni = 2 if configuration.is_client else 3 ===========changed ref 4=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_push_frame_wrong_frame_type(self): """ We should not received SETTINGS on a push stream. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(WrongStream) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=15, - stream_id=15, + data=encode_uint_var(StreamType.PUSH) - data=encode_uint_var(StreamType.PUSH) + + encode_uint_var(0) # push ID - + encode_uint_var(0) # push ID + + encode_frame(FrameType.SETTINGS, b""), - + encode_frame(FrameType.SETTINGS, b""), + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, + (ErrorCode.HTTP_WRONG_STREAM, "Invalid frame type on push stream"), + ) - self.assertEqual(str(cm.exception), "Invalid frame type on push stream")
tests.test_h3/H3ConnectionTest.test_handle_qpack_encoder_stream_error
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<8>:<del> with self.assertRaises(QpackEncoderStreamError) as cm: <9>:<add> h3_client.handle_event( <del> h3_client.handle_event( <10>:<add> StreamDataReceived( <del> StreamDataReceived( <11>:<add> stream_id=7, <del> stream_id=7, <12>:<add> data=encode_uint_var(StreamType.QPACK_ENCODER) + b"\x00", <del> data=encode_uint_var(StreamType.QPACK_ENCODER) + b"\x00", <13>:<add> end_stream=False, <del> end_stream=False, <14>:<del> ) <16>:<add> ) <add> self.assertEqual( <add> quic_client.closed, (ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR, "") <add> ) <del> self.assertEqual(str(cm.exception), "")
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_encoder_stream_error(self): <0> """ <1> Receiving garbage on the QPACK encoder stream triggers an exception. <2> """ <3> quic_client = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=True) <5> ) <6> h3_client = H3Connection(quic_client) <7> <8> with self.assertRaises(QpackEncoderStreamError) as cm: <9> h3_client.handle_event( <10> StreamDataReceived( <11> stream_id=7, <12> data=encode_uint_var(StreamType.QPACK_ENCODER) + b"\x00", <13> end_stream=False, <14> ) <15> ) <16> self.assertEqual(str(cm.exception), "") <17>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_h3.H3ConnectionTest.test_handle_qpack_encoder_duplicate h3_client = H3Connection(quic_client) ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ + if isinstance(event, StreamDataReceived) and not self._is_done: - if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() + try: + if stream_id % 4 == 0: - if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_request_or_push_data( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) - ) + elif stream_is_unidirectional(stream_id): - elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) + except ProtocolError as exc: + self._is_done = True + self._quic.close( + error_code=exc.error_code, reason_phrase=exc.reason_phrase ) return [] ===========changed ref 1=========== # module: tests.test_h3 class FakeQuicConnection: + def close(self, error_code, reason_phrase): + self.closed = (error_code, reason_phrase) + ===========changed ref 2=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_decoder_stream_error(self): """ Receiving garbage on the QPACK decoder stream triggers an exception. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(QpackDecoderStreamError) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=11, - stream_id=11, + data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", - data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, (ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR, "") + ) - self.assertEqual(str(cm.exception), "") ===========changed ref 3=========== # module: tests.test_h3 class FakeQuicConnection: def __init__(self, configuration): + self.closed = None self.configuration = configuration self.stream_queue = [] self._events = [] self._next_stream_bidi = 0 if configuration.is_client else 1 self._next_stream_uni = 2 if configuration.is_client else 3 ===========changed ref 4=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_encoder_duplicate(self): """ We must only receive a single QPACK encoder stream. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) + # receive a first encoder stream h3_client.handle_event( StreamDataReceived( stream_id=11, data=encode_uint_var(StreamType.QPACK_ENCODER), end_stream=False, ) ) + + # receive a second encoder stream - with self.assertRaises(StreamCreationError) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=15, - stream_id=15, + data=encode_uint_var(StreamType.QPACK_ENCODER), - data=encode_uint_var(StreamType.QPACK_ENCODER), + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, + ( + ErrorCode.HTTP_STREAM_CREATION_ERROR, + "Only one QPACK encoder stream is allowed", + ), + ) - self.assertEqual(str(cm.exception), "Only one QPACK encoder stream is allowed") ===========changed ref 5=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_push_frame_wrong_frame_type(self): """ We should not received SETTINGS on a push stream. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(WrongStream) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=15, - stream_id=15, + data=encode_uint_var(StreamType.PUSH) - data=encode_uint_var(StreamType.PUSH) + + encode_uint_var(0) # push ID - + encode_uint_var(0) # push ID + + encode_frame(FrameType.SETTINGS, b""), - + encode_frame(FrameType.SETTINGS, b""), + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, + (ErrorCode.HTTP_WRONG_STREAM, "Invalid frame type on push stream"), + ) - self.assertEqual(str(cm.exception), "Invalid frame type on push stream")
tests.test_h3/H3ConnectionTest.test_handle_request_frame_bad_headers
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<8>:<del> with self.assertRaises(QpackDecompressionFailed) as cm: <9>:<add> h3_server.handle_event( <del> h3_server.handle_event( <10>:<add> StreamDataReceived( <del> StreamDataReceived( <11>:<del> stream_id=0, <12>:<add> stream_id=0, data=encode_frame(FrameType.HEADERS, b""), end_stream=False <del> data=encode_frame(FrameType.HEADERS, b""), <13>:<del> end_stream=False, <14>:<del> ) <16>:<add> ) <add> self.assertEqual( <add> quic_server.closed, (ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED, "") <add> ) <del> self.assertEqual(str(cm.exception), "")
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_bad_headers(self): <0> """ <1> We should not receive HEADERS which cannot be decoded. <2> """ <3> quic_server = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=False) <5> ) <6> h3_server = H3Connection(quic_server) <7> <8> with self.assertRaises(QpackDecompressionFailed) as cm: <9> h3_server.handle_event( <10> StreamDataReceived( <11> stream_id=0, <12> data=encode_frame(FrameType.HEADERS, b""), <13> end_stream=False, <14> ) <15> ) <16> self.assertEqual(str(cm.exception), "") <17>
===========unchanged ref 0=========== at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_h3 FakeQuicConnection(configuration) at: tests.test_h3.FakeQuicConnection.__init__ self.closed = None at: tests.test_h3.FakeQuicConnection.close self.closed = (error_code, reason_phrase) at: tests.test_h3.H3ConnectionTest.test_handle_qpack_encoder_duplicate quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ + if isinstance(event, StreamDataReceived) and not self._is_done: - if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() + try: + if stream_id % 4 == 0: - if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_request_or_push_data( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) - ) + elif stream_is_unidirectional(stream_id): - elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) + except ProtocolError as exc: + self._is_done = True + self._quic.close( + error_code=exc.error_code, reason_phrase=exc.reason_phrase ) return [] ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_encoder_stream_error(self): """ Receiving garbage on the QPACK encoder stream triggers an exception. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(QpackEncoderStreamError) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=7, - stream_id=7, + data=encode_uint_var(StreamType.QPACK_ENCODER) + b"\x00", - data=encode_uint_var(StreamType.QPACK_ENCODER) + b"\x00", + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, (ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR, "") + ) - self.assertEqual(str(cm.exception), "") ===========changed ref 2=========== # module: tests.test_h3 class FakeQuicConnection: + def close(self, error_code, reason_phrase): + self.closed = (error_code, reason_phrase) + ===========changed ref 3=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_decoder_stream_error(self): """ Receiving garbage on the QPACK decoder stream triggers an exception. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(QpackDecoderStreamError) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=11, - stream_id=11, + data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", - data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, (ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR, "") + ) - self.assertEqual(str(cm.exception), "") ===========changed ref 4=========== # module: tests.test_h3 class FakeQuicConnection: def __init__(self, configuration): + self.closed = None self.configuration = configuration self.stream_queue = [] self._events = [] self._next_stream_bidi = 0 if configuration.is_client else 1 self._next_stream_uni = 2 if configuration.is_client else 3
tests.test_h3/H3ConnectionTest.test_handle_request_frame_data_before_headers
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<8>:<del> with self.assertRaises(UnexpectedFrame) as cm: <9>:<add> h3_server.handle_event( <del> h3_server.handle_event( <10>:<add> StreamDataReceived( <del> StreamDataReceived( <11>:<del> stream_id=0, <12>:<add> stream_id=0, data=encode_frame(FrameType.DATA, b""), end_stream=False <del> data=encode_frame(FrameType.DATA, b""), <13>:<del> end_stream=False, <14>:<del> ) <16>:<add> ) <add> self.assertEqual( <add> quic_server.closed, <add> ( <add> ErrorCode.HTTP_UNEXPECTED_FRAME, <add> "DATA frame is not allowed in this state", <add> ), <add> ) <del> self.assertEqual(str(cm.exception), "DATA frame is not allowed in this state")
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_data_before_headers(self): <0> """ <1> We should not receive DATA before receiving headers. <2> """ <3> quic_server = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=False) <5> ) <6> h3_server = H3Connection(quic_server) <7> <8> with self.assertRaises(UnexpectedFrame) as cm: <9> h3_server.handle_event( <10> StreamDataReceived( <11> stream_id=0, <12> data=encode_frame(FrameType.DATA, b""), <13> end_stream=False, <14> ) <15> ) <16> self.assertEqual(str(cm.exception), "DATA frame is not allowed in this state") <17>
===========unchanged ref 0=========== at: aioquic.buffer encode_uint_var(value: int) -> bytes at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: tests.test_h3 FakeQuicConnection(configuration) at: tests.test_h3.FakeQuicConnection.__init__ self.closed = None at: tests.test_h3.FakeQuicConnection.close self.closed = (error_code, reason_phrase) at: tests.test_h3.H3ConnectionTest.test_handle_qpack_encoder_stream_error quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ + if isinstance(event, StreamDataReceived) and not self._is_done: - if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() + try: + if stream_id % 4 == 0: - if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_request_or_push_data( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) - ) + elif stream_is_unidirectional(stream_id): - elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) + except ProtocolError as exc: + self._is_done = True + self._quic.close( + error_code=exc.error_code, reason_phrase=exc.reason_phrase ) return [] ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_bad_headers(self): """ We should not receive HEADERS which cannot be decoded. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) - with self.assertRaises(QpackDecompressionFailed) as cm: + h3_server.handle_event( - h3_server.handle_event( + StreamDataReceived( - StreamDataReceived( - stream_id=0, + stream_id=0, data=encode_frame(FrameType.HEADERS, b""), end_stream=False - data=encode_frame(FrameType.HEADERS, b""), - end_stream=False, - ) ) + ) + self.assertEqual( + quic_server.closed, (ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED, "") + ) - self.assertEqual(str(cm.exception), "") ===========changed ref 2=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_encoder_stream_error(self): """ Receiving garbage on the QPACK encoder stream triggers an exception. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(QpackEncoderStreamError) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=7, - stream_id=7, + data=encode_uint_var(StreamType.QPACK_ENCODER) + b"\x00", - data=encode_uint_var(StreamType.QPACK_ENCODER) + b"\x00", + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, (ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR, "") + ) - self.assertEqual(str(cm.exception), "") ===========changed ref 3=========== # module: tests.test_h3 class FakeQuicConnection: + def close(self, error_code, reason_phrase): + self.closed = (error_code, reason_phrase) + ===========changed ref 4=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_decoder_stream_error(self): """ Receiving garbage on the QPACK decoder stream triggers an exception. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(QpackDecoderStreamError) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=11, - stream_id=11, + data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", - data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, (ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR, "") + ) - self.assertEqual(str(cm.exception), "") ===========changed ref 5=========== # module: tests.test_h3 class FakeQuicConnection: def __init__(self, configuration): + self.closed = None self.configuration = configuration self.stream_queue = [] self._events = [] self._next_stream_bidi = 0 if configuration.is_client else 1 self._next_stream_uni = 2 if configuration.is_client else 3
tests.test_h3/H3ConnectionTest.test_handle_request_frame_headers_after_trailers
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<28>:<del> with self.assertRaises(UnexpectedFrame) as cm: <29>:<add> h3_server.handle_event( <del> h3_server.handle_event( <30>:<add> StreamDataReceived( <del> StreamDataReceived( <31>:<del> stream_id=0, <32>:<add> stream_id=0, data=encode_frame(FrameType.HEADERS, b""), end_stream=False <del> data=encode_frame(FrameType.HEADERS, b""), <33>:<del> end_stream=False, <34>:<del> ) <36>:<add> ) <37>:<add> quic_server.closed, <add> ( <add> ErrorCode.HTTP_UNEXPECTED_FRAME, <add> "HEADERS frame is not allowed in this state", <del> str(cm.exception), "HEADERS frame is not allowed in this state" <38>:<add> ),
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_headers_after_trailers(self): <0> """ <1> We should not receive HEADERS after receiving trailers. <2> """ <3> quic_client = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=True) <5> ) <6> quic_server = FakeQuicConnection( <7> configuration=QuicConfiguration(is_client=False) <8> ) <9> <10> h3_client = H3Connection(quic_client) <11> h3_server = H3Connection(quic_server) <12> <13> stream_id = quic_client.get_next_available_stream_id() <14> h3_client.send_headers( <15> stream_id=stream_id, <16> headers=[ <17> (b":method", b"GET"), <18> (b":scheme", b"https"), <19> (b":authority", b"localhost"), <20> (b":path", b"/"), <21> ], <22> ) <23> h3_client.send_headers( <24> stream_id=stream_id, headers=[(b"x-some-trailer", b"foo")], end_stream=True <25> ) <26> h3_transfer(quic_client, h3_server) <27> <28> with self.assertRaises(UnexpectedFrame) as cm: <29> h3_server.handle_event( <30> StreamDataReceived( <31> stream_id=0, <32> data=encode_frame(FrameType.HEADERS, b""), <33> end_stream=False, <34> ) <35> ) <36> self.assertEqual( <37> str(cm.exception), "HEADERS frame is not allowed in this state" <38> ) <39>
===========unchanged ref 0=========== at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) encode_frame(frame_type: int, frame_data: bytes) -> bytes H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.events StreamDataReceived(data: bytes, end_stream: bool, stream_id: int) at: tests.test_h3 FakeQuicConnection(configuration) at: tests.test_h3.FakeQuicConnection.__init__ self.closed = None at: tests.test_h3.FakeQuicConnection.close self.closed = (error_code, reason_phrase) at: tests.test_h3.H3ConnectionTest.test_handle_request_frame_bad_headers quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) ===========unchanged ref 1=========== at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ + if isinstance(event, StreamDataReceived) and not self._is_done: - if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() + try: + if stream_id % 4 == 0: - if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_request_or_push_data( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) - ) + elif stream_is_unidirectional(stream_id): - elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) + except ProtocolError as exc: + self._is_done = True + self._quic.close( + error_code=exc.error_code, reason_phrase=exc.reason_phrase ) return [] ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_data_before_headers(self): """ We should not receive DATA before receiving headers. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) - with self.assertRaises(UnexpectedFrame) as cm: + h3_server.handle_event( - h3_server.handle_event( + StreamDataReceived( - StreamDataReceived( - stream_id=0, + stream_id=0, data=encode_frame(FrameType.DATA, b""), end_stream=False - data=encode_frame(FrameType.DATA, b""), - end_stream=False, - ) ) + ) + self.assertEqual( + quic_server.closed, + ( + ErrorCode.HTTP_UNEXPECTED_FRAME, + "DATA frame is not allowed in this state", + ), + ) - self.assertEqual(str(cm.exception), "DATA frame is not allowed in this state") ===========changed ref 2=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_bad_headers(self): """ We should not receive HEADERS which cannot be decoded. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) - with self.assertRaises(QpackDecompressionFailed) as cm: + h3_server.handle_event( - h3_server.handle_event( + StreamDataReceived( - StreamDataReceived( - stream_id=0, + stream_id=0, data=encode_frame(FrameType.HEADERS, b""), end_stream=False - data=encode_frame(FrameType.HEADERS, b""), - end_stream=False, - ) ) + ) + self.assertEqual( + quic_server.closed, (ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED, "") + ) - self.assertEqual(str(cm.exception), "") ===========changed ref 3=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_encoder_stream_error(self): """ Receiving garbage on the QPACK encoder stream triggers an exception. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(QpackEncoderStreamError) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=7, - stream_id=7, + data=encode_uint_var(StreamType.QPACK_ENCODER) + b"\x00", - data=encode_uint_var(StreamType.QPACK_ENCODER) + b"\x00", + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, (ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR, "") + ) - self.assertEqual(str(cm.exception), "") ===========changed ref 4=========== # module: tests.test_h3 class FakeQuicConnection: + def close(self, error_code, reason_phrase): + self.closed = (error_code, reason_phrase) +
tests.test_h3/H3ConnectionTest.test_handle_request_frame_push_promise_from_client
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<8>:<del> with self.assertRaises(UnexpectedFrame) as cm: <9>:<add> h3_server.handle_event( <del> h3_server.handle_event( <10>:<add> StreamDataReceived( <del> StreamDataReceived( <11>:<add> stream_id=0, <del> stream_id=0, <12>:<add> data=encode_frame(FrameType.PUSH_PROMISE, b""), <del> data=encode_frame(FrameType.PUSH_PROMISE, b""), <13>:<add> end_stream=False, <del> end_stream=False, <14>:<del> ) <16>:<add> ) <add> self.assertEqual( <add> quic_server.closed, <add> (ErrorCode.HTTP_UNEXPECTED_FRAME, "Clients must not send PUSH_PROMISE"), <add> ) <del> self.assertEqual(str(cm.exception), "Clients must not send PUSH_PROMISE")
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_push_promise_from_client(self): <0> """ <1> A server should not receive PUSH_PROMISE on a request stream. <2> """ <3> quic_server = FakeQuicConnection( <4> configuration=QuicConfiguration(is_client=False) <5> ) <6> h3_server = H3Connection(quic_server) <7> <8> with self.assertRaises(UnexpectedFrame) as cm: <9> h3_server.handle_event( <10> StreamDataReceived( <11> stream_id=0, <12> data=encode_frame(FrameType.PUSH_PROMISE, b""), <13> end_stream=False, <14> ) <15> ) <16> self.assertEqual(str(cm.exception), "Clients must not send PUSH_PROMISE") <17>
===========unchanged ref 0=========== at: aioquic.h3.connection H3Connection(quic: QuicConnection) at: aioquic.h3.connection.H3Connection handle_event(event: QuicEvent) -> List[H3Event] send_headers(stream_id: int, headers: Headers, end_stream: bool=False) -> None at: tests.test_h3 h3_transfer(quic_sender, h3_receiver) at: tests.test_h3.FakeQuicConnection get_next_available_stream_id(is_unidirectional=False) at: tests.test_h3.H3ConnectionTest.test_handle_request_frame_headers_after_trailers quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_client = H3Connection(quic_client) ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: def handle_event(self, event: QuicEvent) -> List[H3Event]: """ Handle a QUIC event and return a list of HTTP events. :param event: The QUIC event to handle. """ + if isinstance(event, StreamDataReceived) and not self._is_done: - if isinstance(event, StreamDataReceived): stream_id = event.stream_id if stream_id not in self._stream: self._stream[stream_id] = H3Stream() + try: + if stream_id % 4 == 0: - if stream_id % 4 == 0: + return self._receive_request_or_push_data( - return self._receive_request_or_push_data( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) - ) + elif stream_is_unidirectional(stream_id): - elif stream_is_unidirectional(stream_id): + return self._receive_stream_data_uni( - return self._receive_stream_data_uni( + stream_id, event.data, event.end_stream - stream_id, event.data, event.end_stream + ) + except ProtocolError as exc: + self._is_done = True + self._quic.close( + error_code=exc.error_code, reason_phrase=exc.reason_phrase ) return [] ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_data_before_headers(self): """ We should not receive DATA before receiving headers. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) - with self.assertRaises(UnexpectedFrame) as cm: + h3_server.handle_event( - h3_server.handle_event( + StreamDataReceived( - StreamDataReceived( - stream_id=0, + stream_id=0, data=encode_frame(FrameType.DATA, b""), end_stream=False - data=encode_frame(FrameType.DATA, b""), - end_stream=False, - ) ) + ) + self.assertEqual( + quic_server.closed, + ( + ErrorCode.HTTP_UNEXPECTED_FRAME, + "DATA frame is not allowed in this state", + ), + ) - self.assertEqual(str(cm.exception), "DATA frame is not allowed in this state") ===========changed ref 2=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_bad_headers(self): """ We should not receive HEADERS which cannot be decoded. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) - with self.assertRaises(QpackDecompressionFailed) as cm: + h3_server.handle_event( - h3_server.handle_event( + StreamDataReceived( - StreamDataReceived( - stream_id=0, + stream_id=0, data=encode_frame(FrameType.HEADERS, b""), end_stream=False - data=encode_frame(FrameType.HEADERS, b""), - end_stream=False, - ) ) + ) + self.assertEqual( + quic_server.closed, (ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED, "") + ) - self.assertEqual(str(cm.exception), "") ===========changed ref 3=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_encoder_stream_error(self): """ Receiving garbage on the QPACK encoder stream triggers an exception. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(QpackEncoderStreamError) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=7, - stream_id=7, + data=encode_uint_var(StreamType.QPACK_ENCODER) + b"\x00", - data=encode_uint_var(StreamType.QPACK_ENCODER) + b"\x00", + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, (ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR, "") + ) - self.assertEqual(str(cm.exception), "") ===========changed ref 4=========== # module: tests.test_h3 class FakeQuicConnection: + def close(self, error_code, reason_phrase): + self.closed = (error_code, reason_phrase) + ===========changed ref 5=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_decoder_stream_error(self): """ Receiving garbage on the QPACK decoder stream triggers an exception. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(QpackDecoderStreamError) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=11, - stream_id=11, + data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", - data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, (ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR, "") + ) - self.assertEqual(str(cm.exception), "")
tests.test_h3/H3ConnectionTest.test_handle_request_frame_wrong_frame_type
Modified
aiortc~aioquic
ef10cb76ba76a4d6423b00dbfeb3656819e50c8b
[http3] handle protocol errors
<5>:<del> with self.assertRaises(WrongStream) as cm: <6>:<add> h3_server.handle_event( <del> h3_server.handle_event( <7>:<add> StreamDataReceived( <del> StreamDataReceived( <8>:<add> stream_id=0, <del> stream_id=0, <9>:<add> data=encode_frame(FrameType.SETTINGS, b""), <del> data=encode_frame(FrameType.SETTINGS, b""), <10>:<add> end_stream=False, <del> end_stream=False, <11>:<del> ) <13>:<add> ) <add> self.assertEqual( <add> quic_server.closed, <add> (ErrorCode.HTTP_WRONG_STREAM, "Invalid frame type on request stream"), <add> ) <del> self.assertEqual(str(cm.exception), "Invalid frame type on request stream")
# module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_wrong_frame_type(self): <0> quic_server = FakeQuicConnection( <1> configuration=QuicConfiguration(is_client=False) <2> ) <3> h3_server = H3Connection(quic_server) <4> <5> with self.assertRaises(WrongStream) as cm: <6> h3_server.handle_event( <7> StreamDataReceived( <8> stream_id=0, <9> data=encode_frame(FrameType.SETTINGS, b""), <10> end_stream=False, <11> ) <12> ) <13> self.assertEqual(str(cm.exception), "Invalid frame type on request stream") <14>
===========unchanged ref 0=========== at: aioquic.h3.connection ErrorCode(x: Union[str, bytes, bytearray], base: int) ErrorCode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) encode_frame(frame_type: int, frame_data: bytes) -> bytes at: tests.test_h3.FakeQuicConnection.__init__ self.closed = None at: tests.test_h3.FakeQuicConnection.close self.closed = (error_code, reason_phrase) at: tests.test_h3.H3ConnectionTest.test_handle_request_frame_headers_after_trailers quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) at: unittest.case.TestCase assertEqual(first: Any, second: Any, msg: Any=...) -> None ===========changed ref 0=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_push_promise_from_client(self): """ A server should not receive PUSH_PROMISE on a request stream. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) - with self.assertRaises(UnexpectedFrame) as cm: + h3_server.handle_event( - h3_server.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=0, - stream_id=0, + data=encode_frame(FrameType.PUSH_PROMISE, b""), - data=encode_frame(FrameType.PUSH_PROMISE, b""), + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_server.closed, + (ErrorCode.HTTP_UNEXPECTED_FRAME, "Clients must not send PUSH_PROMISE"), + ) - self.assertEqual(str(cm.exception), "Clients must not send PUSH_PROMISE") ===========changed ref 1=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_data_before_headers(self): """ We should not receive DATA before receiving headers. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) - with self.assertRaises(UnexpectedFrame) as cm: + h3_server.handle_event( - h3_server.handle_event( + StreamDataReceived( - StreamDataReceived( - stream_id=0, + stream_id=0, data=encode_frame(FrameType.DATA, b""), end_stream=False - data=encode_frame(FrameType.DATA, b""), - end_stream=False, - ) ) + ) + self.assertEqual( + quic_server.closed, + ( + ErrorCode.HTTP_UNEXPECTED_FRAME, + "DATA frame is not allowed in this state", + ), + ) - self.assertEqual(str(cm.exception), "DATA frame is not allowed in this state") ===========changed ref 2=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_request_frame_bad_headers(self): """ We should not receive HEADERS which cannot be decoded. """ quic_server = FakeQuicConnection( configuration=QuicConfiguration(is_client=False) ) h3_server = H3Connection(quic_server) - with self.assertRaises(QpackDecompressionFailed) as cm: + h3_server.handle_event( - h3_server.handle_event( + StreamDataReceived( - StreamDataReceived( - stream_id=0, + stream_id=0, data=encode_frame(FrameType.HEADERS, b""), end_stream=False - data=encode_frame(FrameType.HEADERS, b""), - end_stream=False, - ) ) + ) + self.assertEqual( + quic_server.closed, (ErrorCode.HTTP_QPACK_DECOMPRESSION_FAILED, "") + ) - self.assertEqual(str(cm.exception), "") ===========changed ref 3=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_encoder_stream_error(self): """ Receiving garbage on the QPACK encoder stream triggers an exception. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(QpackEncoderStreamError) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=7, - stream_id=7, + data=encode_uint_var(StreamType.QPACK_ENCODER) + b"\x00", - data=encode_uint_var(StreamType.QPACK_ENCODER) + b"\x00", + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, (ErrorCode.HTTP_QPACK_ENCODER_STREAM_ERROR, "") + ) - self.assertEqual(str(cm.exception), "") ===========changed ref 4=========== # module: tests.test_h3 class FakeQuicConnection: + def close(self, error_code, reason_phrase): + self.closed = (error_code, reason_phrase) + ===========changed ref 5=========== # module: tests.test_h3 class H3ConnectionTest(TestCase): def test_handle_qpack_decoder_stream_error(self): """ Receiving garbage on the QPACK decoder stream triggers an exception. """ quic_client = FakeQuicConnection( configuration=QuicConfiguration(is_client=True) ) h3_client = H3Connection(quic_client) - with self.assertRaises(QpackDecoderStreamError) as cm: + h3_client.handle_event( - h3_client.handle_event( + StreamDataReceived( - StreamDataReceived( + stream_id=11, - stream_id=11, + data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", - data=encode_uint_var(StreamType.QPACK_DECODER) + b"\x00", + end_stream=False, - end_stream=False, - ) ) + ) + self.assertEqual( + quic_client.closed, (ErrorCode.HTTP_QPACK_DECODER_STREAM_ERROR, "") + ) - self.assertEqual(str(cm.exception), "") ===========changed ref 6=========== # module: tests.test_h3 class FakeQuicConnection: def __init__(self, configuration): + self.closed = None self.configuration = configuration self.stream_queue = [] self._events = [] self._next_stream_bidi = 0 if configuration.is_client else 1 self._next_stream_uni = 2 if configuration.is_client else 3
docs.http_client/http_client
Modified
aiortc~aioquic
11951421d2d76d3393f237b8d806c63ffa23a592
[docs] update HTTP client example to include ALPN (fixes: #28)
<0>:<add> configuration = QuicConfiguration(alpn_protocols=["hq-22"]) <add> <add> async with connect(host, port, configuration=configuration) as connection: <del> async with connect(host, port) as connection:
# module: docs.http_client def http_client(host, port): <0> async with connect(host, port) as connection: <1> reader, writer = await connection.create_stream() <2> writer.write(b"GET /\r\n") <3> writer.write_eof() <4> <5> response = await reader.read() <6> sys.stdout.buffer.write(response) <7>
===========unchanged ref 0=========== at: aioquic.asyncio.client connect(host: str, port: int, *, configuration: Optional[QuicConfiguration]=None, create_protocol: Optional[Callable]=QuicConnectionProtocol, session_ticket_handler: Optional[SessionTicketHandler]=None, stream_handler: Optional[QuicStreamHandler]=None) -> AsyncGenerator[QuicConnectionProtocol, None] connect(*args, **kwds) at: aioquic.asyncio.protocol.QuicConnectionProtocol create_stream(is_unidirectional: bool=False) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter] at: aioquic.quic.configuration QuicConfiguration(alpn_protocols: Optional[List[str]]=None, certificate: Any=None, connection_id_length: int=8, idle_timeout: float=60.0, is_client: bool=True, private_key: Any=None, quic_logger: Optional[QuicLogger]=None, secrets_log_file: TextIO=None, server_name: Optional[str]=None, session_ticket: Optional[SessionTicket]=None, supported_versions: List[int]=field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )) at: aioquic.quic.configuration.QuicConfiguration alpn_protocols: Optional[List[str]] = None certificate: Any = None connection_id_length: int = 8 idle_timeout: float = 60.0 is_client: bool = True private_key: Any = None quic_logger: Optional[QuicLogger] = None secrets_log_file: TextIO = None server_name: Optional[str] = None session_ticket: Optional[SessionTicket] = None supported_versions: List[int] = field( default_factory=lambda: [QuicProtocolVersion.DRAFT_22] )
aioquic.h3.connection/H3Connection._decode_headers
Modified
aiortc~aioquic
e568f02b492ee76af486b79b1babef6880140564
[http3] de-duplicate some code to process unblocked headers
<2>:<add> <add> This is called with frame_data=None when a stream becomes unblocked. <4>:<add> if frame_data is None: <add> decoder, headers = self._decoder.resume_header(stream_id) <add> else: <add> decoder, headers = self._decoder.feed_header(stream_id, frame_data) <del> decoder, headers = self._decoder.feed_header(stream_id, frame_data)
# module: aioquic.h3.connection class H3Connection: + def _decode_headers(self, stream_id: int, frame_data: Optional[bytes]) -> Headers: - def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers: <0> """ <1> Decode a HEADERS block and send decoder updates on the decoder stream. <2> """ <3> try: <4> decoder, headers = self._decoder.feed_header(stream_id, frame_data) <5> self._quic.send_stream_data(self._local_decoder_stream_id, decoder) <6> except pylsqpack.DecompressionFailed as exc: <7> raise QpackDecompressionFailed() from exc <8> <9> return headers <10>
===========unchanged ref 0=========== at: aioquic.h3.connection.H3Connection.__init__ self._decoder = pylsqpack.Decoder( self._max_table_capacity, self._blocked_streams ) at: aioquic.h3.events Headers = List[Tuple[bytes, bytes]]
aioquic.h3.connection/H3Connection._receive_stream_data_uni
Modified
aiortc~aioquic
e568f02b492ee76af486b79b1babef6880140564
[http3] de-duplicate some code to process unblocked headers
# module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: <0> http_events: List[H3Event] = [] <1> <2> stream = self._stream[stream_id] <3> stream.buffer += data <4> if stream_ended: <5> stream.ended = True <6> <7> buf = Buffer(data=stream.buffer) <8> consumed = 0 <9> unblocked_streams: Set[int] = set() <10> <11> while stream.stream_type == StreamType.PUSH or not buf.eof(): <12> # fetch stream type for unidirectional streams <13> if stream.stream_type is None: <14> try: <15> stream.stream_type = buf.pull_uint_var() <16> except BufferReadError: <17> break <18> consumed = buf.tell() <19> <20> # check unicity <21> if stream.stream_type == StreamType.CONTROL: <22> if self._peer_control_stream_id is not None: <23> raise StreamCreationError("Only one control stream is allowed") <24> self._peer_control_stream_id = stream_id <25> elif stream.stream_type == StreamType.QPACK_DECODER: <26> if self._peer_decoder_stream_id is not None: <27> raise StreamCreationError( <28> "Only one QPACK decoder stream is allowed" <29> ) <30> self._peer_decoder_stream_id = stream_id <31> elif stream.stream_type == StreamType.QPACK_ENCODER: <32> if self._peer_encoder_stream_id is not None: <33> raise StreamCreationError( <34> "Only one QPACK encoder stream is allowed" <35> ) <36> self._peer_encoder_stream_id = stream_id <37> <38> if stream.stream_type == StreamType.CONTROL: <39> # fetch next frame <40> try: <41> frame_type = buf.pull_uint_var</s>
===========below chunk 0=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 1 frame_length = buf.pull_uint_var() frame_data = buf.pull_bytes(frame_length) except BufferReadError: break consumed = buf.tell() self._handle_control_frame(frame_type, frame_data) elif stream.stream_type == StreamType.PUSH: # fetch push id if stream.push_id is None: try: stream.push_id = buf.pull_uint_var() except BufferReadError: break consumed = buf.tell() # remove processed data from buffer stream.buffer = stream.buffer[consumed:] return self._receive_request_or_push_data(stream_id, b"", stream_ended) elif stream.stream_type == StreamType.QPACK_DECODER: # feed unframed data to decoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() try: self._encoder.feed_decoder(data) except pylsqpack.DecoderStreamError as exc: raise QpackDecoderStreamError() from exc elif stream.stream_type == StreamType.QPACK_ENCODER: # feed unframed data to encoder data = buf.pull_bytes(buf.capacity - buf.tell()) consumed = buf.tell() try: unblocked_streams.update(self._decoder.feed_encoder(data)) except pylsqpack.EncoderStreamError as exc: raise QpackEncoderStreamError() from exc else: # unknown stream type, discard data buf.seek(buf.capacity) consumed = buf.tell() # remove processed data from buffer stream.buffer = stream.buffer[consumed:] </s> ===========below chunk 1=========== # module: aioquic.h3.connection class H3Connection: def _receive_stream_data_uni( self, stream_id: int, data: bytes, stream_ended: bool ) -> List[H3Event]: # offset: 2 <s> = buf.tell() # remove processed data from buffer stream.buffer = stream.buffer[consumed:] # process unblocked streams for stream_id in unblocked_streams: stream = self._stream[stream_id] # decode headers decoder, headers = self._decoder.resume_header(stream_id) self._quic.send_stream_data(self._local_decoder_stream_id, decoder) stream.blocked = False # update state and emit headers if stream.headers_state == HeadersState.INITIAL: stream.headers_state = HeadersState.AFTER_HEADERS else: stream.headers_state = HeadersState.AFTER_TRAILERS http_events.append( HeadersReceived( headers=headers, stream_id=stream_id, stream_ended=stream.ended and not stream.buffer, ) ) # resume processing if stream.buffer: http_events.extend( self._receive_request_or_push_data(stream_id, b"", stream.ended) ) return http_events ===========unchanged ref 0=========== at: aioquic._buffer BufferReadError(*args: object) Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer eof() -> bool seek(pos: int) -> None tell() -> int pull_bytes(length: int) -> bytes pull_uint_var() -> int at: aioquic.h3.connection FrameType(x: Union[str, bytes, bytearray], base: int) FrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) StreamType(x: Union[str, bytes, bytearray], base: int) QpackDecoderStreamError(reason_phrase: str="") QpackEncoderStreamError(reason_phrase: str="") StreamCreationError(reason_phrase: str="") at: aioquic.h3.connection.H3Connection _handle_control_frame(frame_type: int, frame_data: bytes) -> None _receive_request_or_push_data(stream_id: int, data: bytes, stream_ended: bool) -> List[H3Event] at: aioquic.h3.connection.H3Connection.__init__ self._decoder = pylsqpack.Decoder( self._max_table_capacity, self._blocked_streams ) self._encoder = pylsqpack.Encoder() self._stream: Dict[int, H3Stream] = {} self._peer_control_stream_id: Optional[int] = None self._peer_decoder_stream_id: Optional[int] = None self._peer_encoder_stream_id: Optional[int] = None at: aioquic.h3.connection.H3Connection._receive_request_or_push_data http_events: List[H3Event] = [] ===========unchanged ref 1=========== stream = self._stream[stream_id] consumed = buf.tell() consumed = 0 at: aioquic.h3.connection.H3Stream.__init__ self.blocked = False self.buffer = b"" self.ended = False self.push_id: Optional[int] = None self.stream_type: Optional[int] = None at: aioquic.h3.events H3Event() at: typing List = _alias(list, 1, inst=False, name='List') Set = _alias(set, 1, inst=False, name='Set') ===========changed ref 0=========== # module: aioquic.h3.connection class H3Connection: + def _decode_headers(self, stream_id: int, frame_data: Optional[bytes]) -> Headers: - def _decode_headers(self, stream_id: int, frame_data: bytes) -> Headers: """ Decode a HEADERS block and send decoder updates on the decoder stream. + + This is called with frame_data=None when a stream becomes unblocked. """ try: + if frame_data is None: + decoder, headers = self._decoder.resume_header(stream_id) + else: + decoder, headers = self._decoder.feed_header(stream_id, frame_data) - decoder, headers = self._decoder.feed_header(stream_id, frame_data) self._quic.send_stream_data(self._local_decoder_stream_id, decoder) except pylsqpack.DecompressionFailed as exc: raise QpackDecompressionFailed() from exc return headers
aioquic.quic.connection/QuicConnection._handle_reset_stream_frame
Modified
aiortc~aioquic
5a39e632e294f65d5596d4c69d512107890c47ca
[quic] add StreamReset.error_code to report reset cause
<25>:<add> self._events.append( <add> events.StreamReset(error_code=error_code, stream_id=stream_id) <add> ) <del> self._events.append(events.StreamReset(stream_id=stream_id))
# module: aioquic.quic.connection class QuicConnection: def _handle_reset_stream_frame( self, context: QuicReceiveContext, frame_type: int, buf: Buffer ) -> None: <0> """ <1> Handle a RESET_STREAM frame. <2> """ <3> stream_id = buf.pull_uint_var() <4> error_code = buf.pull_uint_var() <5> final_size = buf.pull_uint_var() <6> <7> # log frame <8> if self._quic_logger is not None: <9> context.quic_logger_frames.append( <10> self._quic_logger.encode_reset_stream_frame( <11> error_code=error_code, final_size=final_size, stream_id=stream_id <12> ) <13> ) <14> <15> # check stream direction <16> self._assert_stream_can_receive(frame_type, stream_id) <17> <18> self._logger.info( <19> "Stream %d reset by peer (error code %d, final size %d)", <20> stream_id, <21> error_code, <22> final_size, <23> ) <24> # stream = self._get_or_create_stream(frame_type, stream_id) <25> self._events.append(events.StreamReset(stream_id=stream_id)) <26>
===========unchanged ref 0=========== at: aioquic._buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic._buffer.Buffer pull_uint_var() -> int at: aioquic.quic.connection QuicReceiveContext(epoch: tls.Epoch, host_cid: bytes, network_path: QuicNetworkPath, quic_logger_frames: Optional[List[Any]], time: float) at: aioquic.quic.connection.QuicConnection _assert_stream_can_receive(frame_type: int, stream_id: int) -> None at: aioquic.quic.connection.QuicConnection.__init__ self._events: Deque[events.QuicEvent] = deque() self._quic_logger: Optional[QuicLoggerTrace] = None self._quic_logger = configuration.quic_logger.start_trace( is_client=configuration.is_client, odcid=logger_connection_id ) self._logger = QuicConnectionAdapter( logger, {"id": dump_cid(logger_connection_id)} ) at: aioquic.quic.connection.QuicConnection._close_end self._quic_logger = None at: aioquic.quic.connection.QuicReceiveContext epoch: tls.Epoch host_cid: bytes network_path: QuicNetworkPath quic_logger_frames: Optional[List[Any]] time: float at: aioquic.quic.logger.QuicLoggerTrace encode_reset_stream_frame(error_code: int, final_size: int, stream_id: int) -> Dict at: collections.deque append(x: _T) -> None at: logging.LoggerAdapter logger: Logger extra: Mapping[str, Any] ===========unchanged ref 1=========== info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
tests.test_connection/QuicConnectionTest.test_handle_reset_stream_frame
Modified
aiortc~aioquic
5a39e632e294f65d5596d4c69d512107890c47ca
[quic] add StreamReset.error_code to report reset cause
<3>:<add> consume_events(client) <8>:<add> Buffer(data=binascii.unhexlify("000100")), <del> Buffer(data=binascii.unhexlify("001100")),
# module: tests.test_connection class QuicConnectionTest(TestCase): def test_handle_reset_stream_frame(self): <0> with client_and_server() as (client, server): <1> # client creates bidirectional stream 0 <2> client.send_stream_data(stream_id=0, data=b"hello") <3> <4> # client receives RESET_STREAM <5> client._handle_reset_stream_frame( <6> client_receive_context(client), <7> QuicFrameType.RESET_STREAM, <8> Buffer(data=binascii.unhexlify("001100")), <9> ) <10>
===========unchanged ref 0=========== at: aioquic._buffer Buffer(capacity: Optional[int]=0, data: Optional[bytes]=None) at: aioquic.quic.packet QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...) QuicFrameType(x: Union[str, bytes, bytearray], base: int) at: binascii unhexlify(hexstr: _Ascii, /) -> bytes at: tests.test_connection client_receive_context(client, epoch=tls.Epoch.ONE_RTT) consume_events(connection) client_and_server(client_kwargs={}, client_options={}, client_patch=lambda x: None, handshake=True, server_kwargs={}, server_options={}, server_patch=lambda x: None, transport_options={}) ===========changed ref 0=========== # module: aioquic.quic.events @dataclass class StreamReset(QuicEvent): """ The StreamReset event is fired when the remote peer resets a stream. """ + error_code: int + "The error code that triggered the reset." + stream_id: int "The ID of the stream that was reset." ===========changed ref 1=========== # module: aioquic.quic.connection class QuicConnection: def _handle_reset_stream_frame( self, context: QuicReceiveContext, frame_type: int, buf: Buffer ) -> None: """ Handle a RESET_STREAM frame. """ stream_id = buf.pull_uint_var() error_code = buf.pull_uint_var() final_size = buf.pull_uint_var() # log frame if self._quic_logger is not None: context.quic_logger_frames.append( self._quic_logger.encode_reset_stream_frame( error_code=error_code, final_size=final_size, stream_id=stream_id ) ) # check stream direction self._assert_stream_can_receive(frame_type, stream_id) self._logger.info( "Stream %d reset by peer (error code %d, final size %d)", stream_id, error_code, final_size, ) # stream = self._get_or_create_stream(frame_type, stream_id) + self._events.append( + events.StreamReset(error_code=error_code, stream_id=stream_id) + ) - self._events.append(events.StreamReset(stream_id=stream_id))
aioquic.h3.connection/H3Stream.__init__
Modified
aiortc~aioquic
44c20c190cf84f2bacad0299e3848fd2cc2a11b7
[http3] add some initial QLOG support for HTTP/3 events
<1>:<add> self.blocked_frame_size: Optional[int] = None
# module: aioquic.h3.connection class H3Stream: def __init__(self) -> None: <0> self.blocked = False <1> self.buffer = b"" <2> self.ended = False <3> self.frame_size: Optional[int] = None <4> self.frame_type: Optional[int] = None <5> self.headers_state: HeadersState = HeadersState.INITIAL <6> self.push_id: Optional[int] = None <7> self.stream_type: Optional[int] = None <8>
===========unchanged ref 0=========== at: aioquic.h3.events Headers = List[Tuple[bytes, bytes]] at: typing List = _alias(list, 1, inst=False, name='List') Dict = _alias(dict, 2, inst=False, name='Dict') ===========changed ref 0=========== # module: aioquic.h3.connection + def qlog_encode_data_frame(byte_length: int, stream_id: int) -> Dict: + return { + "byte_length": str(byte_length), + "frame": {"frame_type": "data"}, + "stream_id": str(stream_id), + } +