Skip to content

Commit

Permalink
set out_size after checking if noshow, in which case it must be 0. En…
Browse files Browse the repository at this point in the history
…d headers on 204 in order to ensure the request returns
  • Loading branch information
acsant committed Nov 2, 2017
1 parent c7c0db5 commit c2a2552
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions dirpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,14 +681,6 @@ def save(self, opts): ####################################################
except Exception as e:
raise DirpyFatalError("Can't save image to disk: %s" % e)

# Seek to the end of the buffer so we can get our content
# size without allocating to a string (which we don't want
# to do if this is a HEAD request). Then seek back to the
# beginning so we can read the string later
self.out_buf.seek(0,os.SEEK_END)
self.out_size = self.out_buf.tell()
self.out_buf.seek(0)

# If the user has requested "noshow", we don't want to return the
# image back to them (presumably because we have saved it to disk
# and that is all they care about, so we don't have to waste
Expand All @@ -697,6 +689,14 @@ def save(self, opts): ####################################################
logger.debug("Not showing %s, as requested" % self.file_path)
self.out_buf = io.BytesIO()

# Seek to the end of the buffer so we can get our content
# size without allocating to a string (which we don't want
# to do if this is a HEAD request). Then seek back to the
# beginning so we can read the string later
self.out_buf.seek(0,os.SEEK_END)
self.out_size = self.out_buf.tell()
self.out_buf.seek(0)

# Put together some image metadata in JSON format
self.meta_data["g"]["out_width"] = self.out_x
self.meta_data["g"]["out_height"] = self.out_y
Expand Down Expand Up @@ -1009,11 +1009,13 @@ def http_worker(req, method="GET"): ##########################################
if result.http_code == 204:
req.send_response(204)
req.send_header("Dirpy-Data", result.yield_meta_data())
req.end_headers()
return
# Throw an error if required
elif result.http_msg is not None:
req.send_error(result.http_code, result.http_msg)
req.send_header("Dirpy-Data", result.yield_meta_data())
req.end_headers()
return

# Now fire off a response to our client
Expand Down

0 comments on commit c2a2552

Please sign in to comment.