laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/pysim/+/37007?usp=email )

Change subject: http_json_api / es9p: Add User-Agent header
......................................................................

http_json_api / es9p: Add User-Agent header

ES9+ (And ES11) require the use of User-Agent, while ES2+ not.

Change-Id: Iffe64d82087940a82fbfa73bf5d2b7e864ae5d67
---
M pySim/esim/es9p.py
M pySim/esim/http_json_api.py
2 files changed, 22 insertions(+), 4 deletions(-)

Approvals:
  fixeria: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved
  osmith: Looks good to me, but someone else must approve
  Jenkins Builder: Verified




diff --git a/pySim/esim/es9p.py b/pySim/esim/es9p.py
index e923709..0315850 100644
--- a/pySim/esim/es9p.py
+++ b/pySim/esim/es9p.py
@@ -74,6 +74,7 @@
 # ES9+ InitiateAuthentication function (SGP.22 section 6.5.2.6)
 class InitiateAuthentication(Es9PlusApiFunction):
     path = '/gsma/rsp2/es9plus/initiateAuthentication'
+    extra_http_req_headers = { 'User-Agent': 'gsma-rsp-lpad' }
     input_params = {
         'euiccChallenge': ApiParamBase64,
         'euiccInfo1': param.EuiccInfo1,
@@ -94,6 +95,7 @@
 # ES9+ GetBoundProfilePackage function (SGP.22 section 6.5.2.7)
 class GetBoundProfilePackage(Es9PlusApiFunction):
     path = '/gsma/rsp2/es9plus/getBoundProfilePackage'
+    extra_http_req_headers = { 'User-Agent': 'gsma-rsp-lpad' }
     input_params = {
         'transactionId': param.TransactionId,
         'prepareDownloadResponse': param.PrepareDownloadResponse,
@@ -109,6 +111,7 @@
 # ES9+ AuthenticateClient function (SGP.22 section 6.5.2.8)
 class AuthenticateClient(Es9PlusApiFunction):
     path= '/gsma/rsp2/es9plus/authenticateClient'
+    extra_http_req_headers = { 'User-Agent': 'gsma-rsp-lpad' }
     input_params = {
         'transactionId': param.TransactionId,
         'authenticateServerResponse': param.AuthenticateServerResponse,
@@ -128,6 +131,7 @@
 # ES9+ HandleNotification function (SGP.22 section 6.5.2.9)
 class HandleNotification(Es9PlusApiFunction):
     path = '/gsma/rsp2/es9plus/handleNotification'
+    extra_http_req_headers = { 'User-Agent': 'gsma-rsp-lpad' }
     input_params = {
         'pendingNotification': param.PendingNotification,
       }
@@ -136,6 +140,7 @@
 # ES9+ CancelSession function (SGP.22 section 6.5.2.10)
 class CancelSession(Es9PlusApiFunction):
     path = '/gsma/rsp2/es9plus/cancelSession'
+    extra_http_req_headers = { 'User-Agent': 'gsma-rsp-lpad' }
     input_params = {
         'transactionId': param.TransactionId,
         'cancelSessionResponse': param.CancelSessionResponse,
diff --git a/pySim/esim/http_json_api.py b/pySim/esim/http_json_api.py
index d396b46..7d40f88 100644
--- a/pySim/esim/http_json_api.py
+++ b/pySim/esim/http_json_api.py
@@ -174,6 +174,7 @@
     expected_http_status = 200
     # the HTTP method used (GET, OPTIONS, HEAD, POST, PUT, PATCH or DELETE)
     http_method = 'POST'
+    extra_http_req_headers = {}

     def __init__(self, url_prefix: str, func_req_id: str, session: 
requests.Session):
         self.url_prefix = url_prefix
@@ -232,19 +233,20 @@
         is returned as json-deserialized dict."""
         url = self.url_prefix + self.path
         encoded = json.dumps(self.encode(data, func_call_id))
-        headers = {
+        req_headers = {
             'Content-Type': 'application/json',
             'X-Admin-Protocol': 'gsma/rsp/v2.5.0',
         }
+        req_headers.update(self.extra_http_req_headers)

-        logger.debug("HTTP REQ %s - '%s'" % (url, encoded))
-        response = self.session.request(self.http_method, url, data=encoded, 
headers=headers, timeout=timeout)
+        logger.debug("HTTP REQ %s - hdr: %s '%s'" % (url, req_headers, 
encoded))
+        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: %s" % (response.content))

         if response.status_code != self.expected_http_status:
             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)
         if not response.headers.get('X-Admin-Protocol', 
'gsma/rsp/v2.unknown').startswith('gsma/rsp/v2.'):
             raise HttpHeaderError(response)

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/37007?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Iffe64d82087940a82fbfa73bf5d2b7e864ae5d67
Gerrit-Change-Number: 37007
Gerrit-PatchSet: 4
Gerrit-Owner: laforge <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-MessageType: merged

Reply via email to