Skip to content

Commit

Permalink
Workaround for issue #54 (HTTP 100 Continue problem): Clear pending r…
Browse files Browse the repository at this point in the history
…eceive buffer before sending error response
  • Loading branch information
proycon committed Sep 13, 2017
1 parent e990c93 commit 00c4a05
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions clam/clamservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,7 @@ def addinputfile_nofile(project, credentials=None):
def addinputfile(project, filename, credentials=None): #pylint: disable=too-many-return-statements
"""Add a new input file, this invokes the actual uploader"""

printdebug('Addinputfile: Initialising' )

user, oauth_access_token = parsecredentials(credentials) #pylint: disable=unused-variable
response = Project.create(project, user)
Expand Down
5 changes: 4 additions & 1 deletion clam/common/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def set_password_function(self, f):
def error_handler(self, f):
@wraps(f)
def decorated(*args, **kwargs):
flask.request.data #clear receive buffer of pending data
res = f(*args, **kwargs)
if (sys.version >= '3' and isinstance(res, str)) or (sys.version < '3' and isinstance(res,unicode)): #pylint: disable=undefined-variable
res = flask.make_response(res)
Expand All @@ -72,13 +73,15 @@ def decorated(*args, **kwargs):
def require_login(self, f):
@wraps(f)
def decorated(*args, **kwargs):
self.printdebug("Handling HTTP Authentication (Basic/Digest)")
auth = flask.request.authorization
# We need to ignore authentication headers for OPTIONS to avoid
# unwanted interactions with CORS.
# Chrome and Firefox issue a preflight OPTIONS request to check
# Access-Control-* headers, and will fail if it returns 401.
if flask.request.method != 'OPTIONS':
if not auth:
self.printdebug("No authentication header supplied")
return self.auth_error_callback()
username = self.username(**self.settings)
self.printdebug("Obtained username: " + username)
Expand All @@ -96,6 +99,7 @@ def decorated(*args, **kwargs):
kwargs['credentials'] = username
else:
#add username as parameter to the wrapped function
self.printdebug("Handling preflight OPTIONS request (no authentication)")
kwargs['credentials'] = 'anonymous'
return f(*args,**kwargs)
return decorated
Expand Down Expand Up @@ -449,4 +453,3 @@ def cleanup(self):
if os.path.getmtime(noncefile) + self.expiration > t:
os.unlink(noncefile)


2 changes: 1 addition & 1 deletion clam/common/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import clam.common.util
import clam.common.viewers

VERSION = '2.1.14'
VERSION = '2.2'

#dirs for services shipped with CLAM itself
CONFIGDIR = os.path.abspath(os.path.dirname(__file__) + '/../config/')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def read(fname):

setup(
name = "CLAM",
version = "2.1.14", #also change in clam.common.data.VERSION
version = "2.2", #also change in clam.common.data.VERSION
author = "Maarten van Gompel",
author_email = "proycon@anaproy.nl",
description = ("Turns command-line NLP tools into fully-fledged RESTful webservices with an auto-generated web-interface for human end-users."),
Expand Down

0 comments on commit 00c4a05

Please sign in to comment.