from ldt import settings
import httplib2
import re

def request_with_auth(url, method='GET'):
    h = httplib2.Http()
    web_auth = settings.WEB_AUTH if settings.WEB_AUTH else {}
    for key in web_auth:
        if re.search(key, url, re.IGNORECASE):
            h.add_credentials(web_auth[key].get('NAME', ''), web_auth[key].get('PASSWORD', ''), web_auth[key].get('DOMAIN', ''))
            break
            
    return h.request(url, method)

