Skip to content

Commit 3aa491e

Browse files
committed
Add Accept header
Fedora infra needs it (otherwise packit is treated like any other AI bot and it is given back the Anubis page).
1 parent 95aee6a commit 3aa491e

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎ogr/services/pagure/project.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def _call_project_api_raw(
137137
method: Optional[str] = None,
138138
params: Optional[dict] = None,
139139
data: Optional[dict] = None,
140+
header: Optional[dict] = None,
140141
) -> RequestResponse:
141142
"""
142143
Call project API endpoint.
@@ -152,6 +153,7 @@ def _call_project_api_raw(
152153
method: Method of the HTTP request, e.g. `"GET"`, `"POST"`, etc.
153154
params: HTTP(S) query parameters in form of a dictionary.
154155
data: Data to be sent in form of a dictionary.
156+
header: HTTP request header, dict that will update default headers
155157
156158
Returns:
157159
`RequestResponse` object containing response.
@@ -167,6 +169,7 @@ def _call_project_api_raw(
167169
method=method,
168170
params=params,
169171
data=data,
172+
header=header,
170173
)
171174

172175
def _get_project_url(self, *args, add_fork_part=True, add_api_endpoint_part=True):
@@ -464,12 +467,15 @@ def change_token(self, new_token: str) -> None:
464467

465468
def get_file_content(self, path: str, ref=None) -> str:
466469
ref = ref or self.default_branch
470+
# This method is used for retrieving packit.yaml
471+
header = {"Accept": "application/yaml"}
467472
result = self._call_project_api_raw(
468473
"raw",
469474
ref,
470475
"f",
471476
path,
472477
add_api_endpoint_part=False,
478+
header=header,
473479
)
474480

475481
if not result or result.status_code == HTTPStatus.NOT_FOUND:

‎ogr/services/pagure/service.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def __init__(
5959
self.session.mount("https://", adapter)
6060

6161
self.header = {"Authorization": "token " + self._token} if self._token else {}
62+
# By default ogr deals with Pagure API -> json
63+
self.header["Accept"] = "application/json"
6264

6365
if user_agent:
6466
self.header |= {"User-Agent": user_agent}
@@ -193,6 +195,7 @@ def call_api_raw(
193195
url: str,
194196
method: Optional[str] = None,
195197
params: Optional[dict] = None,
198+
header: Optional[dict] = None,
196199
data=None,
197200
):
198201
"""
@@ -202,6 +205,7 @@ def call_api_raw(
202205
url: URL to be called.
203206
method: Method of the HTTP request, e.g. `"GET"`, `"POST"`, etc.
204207
params: HTTP(S) query parameters in form of a dictionary.
208+
header: HTTP request header, dict that will update default headers
205209
data: Data to be sent in form of a dictionary.
206210
207211
Returns:
@@ -216,6 +220,7 @@ def call_api_raw(
216220
url=url,
217221
params=params,
218222
data=data,
223+
header=header,
219224
)
220225

221226
except requests.exceptions.ConnectionError as er:
@@ -257,14 +262,17 @@ def get_raw_request(
257262
ValueError, if JSON cannot be retrieved.
258263
"""
259264

265+
updated_header = self.header.update(header)
266+
260267
response = self.session.request(
261268
method=method,
262269
url=url,
263270
params=params,
264-
headers=header or self.header,
271+
headers=updated_header,
265272
data=data,
266273
verify=not self.insecure,
267274
)
275+
logger.debug(f"Ogr sent request with following headers: {updated_header}")
268276

269277
json_output = None
270278
try:

0 commit comments

Comments
 (0)