Skip to content

Commit

Permalink
Dynamically set the hostname for all services in the WSDL
Browse files Browse the repository at this point in the history
  • Loading branch information
mittmannv8 authored Sep 1, 2023
2 parents f758168 + 1e72ba2 commit 8cc5149
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions fastapi_soap/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def __init__(self, *args, name: str, **kwargs) -> None:
'/', self._generate_wsdl, methods=['GET'], status_code=200
)

def _generate_wsdl(self):
wsdl = generate_wsdl(self._name, self._methods, url=self.prefix)
def _generate_wsdl(self, request: Request):
wsdl = generate_wsdl(self._name, self._methods, url=self.prefix, request=request)
return SoapResponse(dump_etree(wsdl), envelope_wrap=False)

def operation(
Expand Down
5 changes: 3 additions & 2 deletions fastapi_soap/wsdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from xml.etree import ElementTree as ET
from xml.etree.ElementTree import Element, SubElement, tostring

from fastapi import Request
from pydantic.fields import ModelField
from pydantic.typing import display_as_type
from pydantic_xml import BaseXmlModel, XmlElementInfo
Expand Down Expand Up @@ -99,7 +100,7 @@ def dump_etree(element: Element) -> str:


def generate_wsdl(
name: str, methods, url: str, documentation: str = ''
name: str, methods, url: str, request: Request, documentation: str = ''
) -> Element:
wsdl = Element('wsdl:definitions', nsmap, name=name)
SubElement(wsdl, 'wsdl:documentation').text = documentation
Expand Down Expand Up @@ -139,7 +140,7 @@ def generate_wsdl(
SubElement(
port_element,
'soap:address',
location=f'https://localhost:8000{url}/{method}',
location=f'{str(request.url.replace(query="", fragment="")).rstrip("/")}/{method}',
)

for action, model in models.items():
Expand Down

0 comments on commit 8cc5149

Please sign in to comment.