from ldt import settings
import httplib2
import re

def request_with_auth(url, method='GET'):
    h = httplib2.Http()
    web_auth = getattr(settings, "WEB_AUTH", {})
    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)

