Skip to content

Commit

Permalink
Support custom http_session (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
OriHoch authored and roll committed Apr 11, 2019
1 parent 36d1fb6 commit 29a9e34
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions datapackage/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import json
import warnings
import cchardet
import requests
from copy import deepcopy
from tableschema import Table, Storage
from six.moves.urllib.parse import urljoin
from six.moves.urllib.request import Request, urlopen
from six.moves.urllib.request import urlopen
from .profile import Profile
from . import exceptions
from . import helpers
Expand Down Expand Up @@ -206,8 +207,13 @@ def raw_iter(self, stream=False):
if self.multipart:
filelike = _MultipartSource(self.source, remote=self.remote)
elif self.remote:
request = Request(self.source, headers=config.HTTP_HEADERS)
filelike = urlopen(request)
if self.__table_options.get('http_session'):
http_session = self.__table_options['http_session']
else:
http_session = requests.Session()
http_session.headers = config.HTTP_HEADERS
res = http_session.get(self.source, stream=True)
filelike = res.raw
else:
filelike = io.open(self.source, 'rb')

Expand Down

0 comments on commit 29a9e34

Please sign in to comment.