Skip to content

Commit c15b7b3

Browse files
Make httpbin extension compatible with Werkzeug 3.x (#39)
1 parent 9c397ad commit c15b7b3

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

httpbin/localstack_httpbin/extension.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import logging
22
from typing import Optional
33

4-
from localstack import config, constants
4+
from localstack import config
55
from localstack.config import get_edge_url
66
from localstack.extensions.api import Extension, http
77
from localstack.utils.net import get_free_tcp_port
8+
from localstack.utils.urls import localstack_host
89

910
from localstack_httpbin.server import HttpbinServer
1011

@@ -28,15 +29,13 @@ def on_extension_load(self):
2829

2930
def on_platform_start(self):
3031
from localstack_httpbin.vendor.httpbin import core
31-
core.template['host'] = f"{self.get_public_hostname()}:{config.get_edge_port_http()}"
32-
32+
core.template['host'] = f"{self.get_public_hostname()}:{localstack_host().port}"
3333
self.server = HttpbinServer(get_free_tcp_port())
3434
LOG.debug("starting httpbin on %s", self.server.url)
3535
self.server.start()
3636

3737
def get_public_hostname(self) -> str:
38-
# FIXME: reconcile with LOCALSTACK_HOST, but this should be accessible via the host
39-
return f"{self.hostname_prefix}{constants.LOCALHOST_HOSTNAME}"
38+
return f"{self.hostname_prefix}{localstack_host().host}"
4039

4140
def on_platform_ready(self):
4241
LOG.info("Serving httpbin on %s", get_edge_url(localstack_hostname=self.get_public_hostname()))

httpbin/localstack_httpbin/vendor/httpbin/helpers.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
import time
1414
import os
1515
from hashlib import md5, sha256, sha512
16-
from werkzeug.http import parse_authorization_header
17-
from werkzeug.datastructures import WWWAuthenticate
16+
from werkzeug.datastructures import WWWAuthenticate, Authorization
1817

1918
from flask import request, make_response
2019
from six.moves.urllib.parse import urlparse, urlunparse
@@ -356,7 +355,7 @@ def check_digest_auth(user, passwd):
356355
"""Check user authentication using HTTP Digest auth"""
357356

358357
if request.headers.get('Authorization'):
359-
credentials = parse_authorization_header(request.headers.get('Authorization'))
358+
credentials = Authorization.from_header(request.headers.get('Authorization'))
360359
if not credentials:
361360
return
362361
request_uri = request.script_root + request.path

0 commit comments

Comments
 (0)