Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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