from abc import ABCMeta, abstractmethod
from typing import Optional, Dict

from ._HttpClient import HttpClient


class DefaultHttpClient(HttpClient):
    __metaclass__ = ABCMeta

    def __init__(self, http_client, base_url, default_headers=None):
        # type: (HttpClient, str, Optional[Dict[str, str]]) -> None
        super(DefaultHttpClient, self).__init__()
        self.http_client = http_client
        self.base_url = base_url
        self.default_headers = default_headers

    @abstractmethod
    def send(self, request):
        request.url = self.base_url + request.url
        if self.default_headers is not None:
            for header in self.default_headers.keys():
                if header not in request.headers:
                    request.headers[header] = self.default_headers[header]
        self.http_client.send(request)
