mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-28 16:28:33 +03:00
http_json_api / es9p: Add User-Agent header
ES9+ (And ES11) require the use of User-Agent, while ES2+ not. Change-Id: Iffe64d82087940a82fbfa73bf5d2b7e864ae5d67
This commit is contained in:
@@ -74,6 +74,7 @@ class Es9PlusApiFunction(JsonHttpApiFunction):
|
|||||||
# ES9+ InitiateAuthentication function (SGP.22 section 6.5.2.6)
|
# ES9+ InitiateAuthentication function (SGP.22 section 6.5.2.6)
|
||||||
class InitiateAuthentication(Es9PlusApiFunction):
|
class InitiateAuthentication(Es9PlusApiFunction):
|
||||||
path = '/gsma/rsp2/es9plus/initiateAuthentication'
|
path = '/gsma/rsp2/es9plus/initiateAuthentication'
|
||||||
|
extra_http_req_headers = { 'User-Agent': 'gsma-rsp-lpad' }
|
||||||
input_params = {
|
input_params = {
|
||||||
'euiccChallenge': ApiParamBase64,
|
'euiccChallenge': ApiParamBase64,
|
||||||
'euiccInfo1': param.EuiccInfo1,
|
'euiccInfo1': param.EuiccInfo1,
|
||||||
@@ -94,6 +95,7 @@ class InitiateAuthentication(Es9PlusApiFunction):
|
|||||||
# ES9+ GetBoundProfilePackage function (SGP.22 section 6.5.2.7)
|
# ES9+ GetBoundProfilePackage function (SGP.22 section 6.5.2.7)
|
||||||
class GetBoundProfilePackage(Es9PlusApiFunction):
|
class GetBoundProfilePackage(Es9PlusApiFunction):
|
||||||
path = '/gsma/rsp2/es9plus/getBoundProfilePackage'
|
path = '/gsma/rsp2/es9plus/getBoundProfilePackage'
|
||||||
|
extra_http_req_headers = { 'User-Agent': 'gsma-rsp-lpad' }
|
||||||
input_params = {
|
input_params = {
|
||||||
'transactionId': param.TransactionId,
|
'transactionId': param.TransactionId,
|
||||||
'prepareDownloadResponse': param.PrepareDownloadResponse,
|
'prepareDownloadResponse': param.PrepareDownloadResponse,
|
||||||
@@ -109,6 +111,7 @@ class GetBoundProfilePackage(Es9PlusApiFunction):
|
|||||||
# ES9+ AuthenticateClient function (SGP.22 section 6.5.2.8)
|
# ES9+ AuthenticateClient function (SGP.22 section 6.5.2.8)
|
||||||
class AuthenticateClient(Es9PlusApiFunction):
|
class AuthenticateClient(Es9PlusApiFunction):
|
||||||
path= '/gsma/rsp2/es9plus/authenticateClient'
|
path= '/gsma/rsp2/es9plus/authenticateClient'
|
||||||
|
extra_http_req_headers = { 'User-Agent': 'gsma-rsp-lpad' }
|
||||||
input_params = {
|
input_params = {
|
||||||
'transactionId': param.TransactionId,
|
'transactionId': param.TransactionId,
|
||||||
'authenticateServerResponse': param.AuthenticateServerResponse,
|
'authenticateServerResponse': param.AuthenticateServerResponse,
|
||||||
@@ -128,6 +131,7 @@ class AuthenticateClient(Es9PlusApiFunction):
|
|||||||
# ES9+ HandleNotification function (SGP.22 section 6.5.2.9)
|
# ES9+ HandleNotification function (SGP.22 section 6.5.2.9)
|
||||||
class HandleNotification(Es9PlusApiFunction):
|
class HandleNotification(Es9PlusApiFunction):
|
||||||
path = '/gsma/rsp2/es9plus/handleNotification'
|
path = '/gsma/rsp2/es9plus/handleNotification'
|
||||||
|
extra_http_req_headers = { 'User-Agent': 'gsma-rsp-lpad' }
|
||||||
input_params = {
|
input_params = {
|
||||||
'pendingNotification': param.PendingNotification,
|
'pendingNotification': param.PendingNotification,
|
||||||
}
|
}
|
||||||
@@ -136,6 +140,7 @@ class HandleNotification(Es9PlusApiFunction):
|
|||||||
# ES9+ CancelSession function (SGP.22 section 6.5.2.10)
|
# ES9+ CancelSession function (SGP.22 section 6.5.2.10)
|
||||||
class CancelSession(Es9PlusApiFunction):
|
class CancelSession(Es9PlusApiFunction):
|
||||||
path = '/gsma/rsp2/es9plus/cancelSession'
|
path = '/gsma/rsp2/es9plus/cancelSession'
|
||||||
|
extra_http_req_headers = { 'User-Agent': 'gsma-rsp-lpad' }
|
||||||
input_params = {
|
input_params = {
|
||||||
'transactionId': param.TransactionId,
|
'transactionId': param.TransactionId,
|
||||||
'cancelSessionResponse': param.CancelSessionResponse,
|
'cancelSessionResponse': param.CancelSessionResponse,
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ class JsonHttpApiFunction(abc.ABC):
|
|||||||
expected_http_status = 200
|
expected_http_status = 200
|
||||||
# the HTTP method used (GET, OPTIONS, HEAD, POST, PUT, PATCH or DELETE)
|
# the HTTP method used (GET, OPTIONS, HEAD, POST, PUT, PATCH or DELETE)
|
||||||
http_method = 'POST'
|
http_method = 'POST'
|
||||||
|
extra_http_req_headers = {}
|
||||||
|
|
||||||
def __init__(self, url_prefix: str, func_req_id: str, session: requests.Session):
|
def __init__(self, url_prefix: str, func_req_id: str, session: requests.Session):
|
||||||
self.url_prefix = url_prefix
|
self.url_prefix = url_prefix
|
||||||
@@ -232,19 +233,20 @@ class JsonHttpApiFunction(abc.ABC):
|
|||||||
is returned as json-deserialized dict."""
|
is returned as json-deserialized dict."""
|
||||||
url = self.url_prefix + self.path
|
url = self.url_prefix + self.path
|
||||||
encoded = json.dumps(self.encode(data, func_call_id))
|
encoded = json.dumps(self.encode(data, func_call_id))
|
||||||
headers = {
|
req_headers = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-Admin-Protocol': 'gsma/rsp/v2.5.0',
|
'X-Admin-Protocol': 'gsma/rsp/v2.5.0',
|
||||||
}
|
}
|
||||||
|
req_headers.update(self.extra_http_req_headers)
|
||||||
|
|
||||||
logger.debug("HTTP REQ %s - '%s'" % (url, encoded))
|
logger.debug("HTTP REQ %s - hdr: %s '%s'" % (url, req_headers, encoded))
|
||||||
response = self.session.request(self.http_method, url, data=encoded, headers=headers, timeout=timeout)
|
response = self.session.request(self.http_method, url, data=encoded, headers=req_headers, timeout=timeout)
|
||||||
logger.debug("HTTP RSP-STS: [%u] hdr: %s" % (response.status_code, response.headers))
|
logger.debug("HTTP RSP-STS: [%u] hdr: %s" % (response.status_code, response.headers))
|
||||||
logger.debug("HTTP RSP: %s" % (response.content))
|
logger.debug("HTTP RSP: %s" % (response.content))
|
||||||
|
|
||||||
if response.status_code != self.expected_http_status:
|
if response.status_code != self.expected_http_status:
|
||||||
raise HttpStatusError(response)
|
raise HttpStatusError(response)
|
||||||
if not response.headers.get('Content-Type').startswith(headers['Content-Type']):
|
if not response.headers.get('Content-Type').startswith(req_headers['Content-Type']):
|
||||||
raise HttpHeaderError(response)
|
raise HttpHeaderError(response)
|
||||||
if not response.headers.get('X-Admin-Protocol', 'gsma/rsp/v2.unknown').startswith('gsma/rsp/v2.'):
|
if not response.headers.get('X-Admin-Protocol', 'gsma/rsp/v2.unknown').startswith('gsma/rsp/v2.'):
|
||||||
raise HttpHeaderError(response)
|
raise HttpHeaderError(response)
|
||||||
|
|||||||
Reference in New Issue
Block a user