Skip to content

Commit

Permalink
Fix: Set accept header back to application/vnd.github+json for steams
Browse files Browse the repository at this point in the history
Actually revert c3f857c and use
application/vnd.github+json as accept header for streaming requests too.

It seems that GitHub changed their API in this regard and expects
application/vnd.github+json again instead of application/octet-stream.
  • Loading branch information
bjoernricks committed Mar 1, 2023
1 parent 0209a1b commit feed458
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 11 additions & 4 deletions pontos/github/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ def __init__(
def _request_headers(
self,
*,
accept: Optional[str] = DEFAULT_ACCEPT_HEADER,
accept: Optional[str] = None,
content_type: Optional[str] = None,
content_length: Optional[int] = None,
) -> Headers:
"""
Get the default request headers
"""
headers = {
"Accept": accept,
"Accept": accept or DEFAULT_ACCEPT_HEADER,
"X-GitHub-Api-Version": GITHUB_API_VERSION,
}
if self.token:
Expand Down Expand Up @@ -248,14 +248,21 @@ async def patch(
url, params=params, headers=headers, json=data, content=content
)

def stream(self, api: str) -> AsyncContextManager[httpx.Response]:
def stream(
self,
api: str,
*,
accept: Optional[str] = None,
) -> AsyncContextManager[httpx.Response]:
"""
Stream data from a GitHub API
Args:
api: API path to use for the post request
accept: Expected content type in the response.
Default "application/octet-stream".
"""
headers = self._request_headers(accept=ACCEPT_HEADER_OCTET_STREAM)
headers = self._request_headers(accept=accept)
url = self._request_url(api)
return self._client.stream(
"GET", url, headers=headers, follow_redirects=True
Expand Down
5 changes: 2 additions & 3 deletions tests/github/api/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from unittest.mock import MagicMock, call, patch

from pontos.github.api.client import (
ACCEPT_HEADER_OCTET_STREAM,
DEFAULT_ACCEPT_HEADER,
GITHUB_API_VERSION,
GitHubAsyncRESTClient,
Expand Down Expand Up @@ -257,7 +256,7 @@ async def test_stream(self):
"GET",
f"{DEFAULT_GITHUB_API_URL}/foo/bar",
headers={
"Accept": ACCEPT_HEADER_OCTET_STREAM,
"Accept": DEFAULT_ACCEPT_HEADER,
"Authorization": "token token",
"X-GitHub-Api-Version": GITHUB_API_VERSION,
},
Expand All @@ -277,7 +276,7 @@ async def test_stream_url(self):
"GET",
"https://github.com/foo/bar",
headers={
"Accept": ACCEPT_HEADER_OCTET_STREAM,
"Accept": DEFAULT_ACCEPT_HEADER,
"Authorization": "token token",
"X-GitHub-Api-Version": GITHUB_API_VERSION,
},
Expand Down

0 comments on commit feed458

Please sign in to comment.