Skip to content
Myr

Raise KeyError if header isn't found in Headers (#324)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Gaurav Dhameeja · committed by Seth Michael Larson · parent 6b97b2e · Browse files · 4 files+15 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+15 added−6 removed

  • tests:+9 added−0 removed
  • other:+6 added−6 removed

4 files+15 added−6 removed

modified:httpx/dispatch/http2.py+1 added-1 removed
2 unmodified lines
34import h2.connection5import h2.events67from ..concurrency.base import BaseStream, ConcurrencyBackend, TimeoutFlag, BaseEvent7from ..concurrency.base import BaseEvent, BaseStream, ConcurrencyBackend, TimeoutFlag8from ..config import TimeoutConfig, TimeoutTypes9from ..models import AsyncRequest, AsyncResponse10from ..utils import get_logger11
213 unmodified lines
modified:httpx/middleware.py+3 added-4 removed
145 unmodified lines
146147 if url.origin != request.url.origin:148 # Strip Authorization headers when responses are redirected away from149 # the origin.150 del headers["Authorization"]150 headers.pop("Authorization", None)151 headers["Host"] = url.authority152153 if method != request.method and method == "GET":154 # If we've switch to a 'GET' request, then strip any headers which155 # are only relevant to the request body.156 del headers["Content-Length"]157 del headers["Transfer-Encoding"]158156 headers.pop("Content-Length", None)157 headers.pop("Transfer-Encoding", None)158 return headers159160 def redirect_content(self, request: AsyncRequest, method: str) -> bytes:161 """
7 unmodified lines
modified:httpx/models.py+2 added-1 removed
471 unmodified lines
472 pop_indexes = []473 for idx, (item_key, _) in enumerate(self._list):474 if item_key == del_key:475 pop_indexes.append(idx)476 if not pop_indexes:477 raise KeyError(key)478479 for idx in reversed(pop_indexes):480 del self._list[idx]481
143 unmodified lines
625 else:626 assert hasattr(data, "__aiter__")627 self.is_streaming = True628 self.content_aiter = data627629 self.prepare()630631 async def read(self) -> bytes:632 """
605 unmodified lines
modified:tests/client/test_headers.py+9 added
1#!/usr/bin/env python323import json45import pytest67from httpx import (8 AsyncDispatcher,9 AsyncRequest,10 AsyncResponse,
1 unmodified line
12 Client,13 TimeoutTypes,14 VerifyTypes,15 __version__,16 models,17)181920class MockDispatch(AsyncDispatcher):
103 unmodified lines
124 "host": "example.org",125 "user-agent": "python-myclient/0.2.1",126 }127 }128129130def test_header_does_not_exist():131 headers = models.Headers({"foo": "bar"})132 with pytest.raises(KeyError):133 del headers["baz"]