Open Bug 1073271 Opened 10 years ago Updated 8 years ago

Do not load the whole attachment into memory before sending it to the browser

Categories

(Bugzilla :: Attachments & Requests, defect)

4.4.2
defect
Not set
normal

Tracking

()

People

(Reporter: dnozay, Unassigned)

Details

(Keywords: perf)

Attachments

(1 file)

see bug 906010, bug 1073241 and bug 1073246. Slurping the data in an attachment object will cause the process to use more memory. This may or may not be an issue based on size of the hardware and site configuration. snip from attachment.cgi: ====================================================================== # Display an attachment. sub view { my $attachment = get_attachment(); # At this point, Bugzilla->login has been called if it had to. my $contenttype = $attachment->contenttype; my $filename = $attachment->filename; # Bug 111522: allow overriding content-type manually in the posted form # params. if (defined $cgi->param('content_type')) { $contenttype = $attachment->_check_content_type($cgi->param('content_type')); } # Return the appropriate HTTP response headers. $attachment->datasize || ThrowUserError("attachment_removed"); $filename =~ s/^.*[\/\\]//; # escape quotes and backslashes in the filename, per RFCs 2045/822 $filename =~ s/\\/\\\\/g; # escape backslashes $filename =~ s/"/\\"/g; # escape quotes # Avoid line wrapping done by Encode, which we don't need for HTTP # headers. See discussion in bug 328628 for details. local $Encode::Encoding{'MIME-Q'}->{'bpl'} = 10000; $filename = encode('MIME-Q', $filename); my $disposition = Bugzilla->params->{'allow_attachment_display'} ? 'inline' : 'attachment'; # Don't send a charset header with attachments--they might not be UTF-8. # However, we do allow people to explicitly specify a charset if they # want. if ($contenttype !~ /\bcharset=/i) { # In order to prevent Apache from adding a charset, we have to send a # charset that's a single space. $cgi->charset(' '); if (Bugzilla->feature('detect_charset') && $contenttype =~ /^text\//) { my $encoding = detect_encoding($attachment->data); if ($encoding) { $cgi->charset(find_encoding($encoding)->mime_name); } } } print $cgi->header(-type=>"$contenttype; name=\"$filename\"", -content_disposition=> "$disposition; filename=\"$filename\"", -content_length => $attachment->datasize); disable_utf8(); print $attachment->data; } ====================================================================== rather than print, you could stream the file, esp. if file is local. I haven't played with it at all, so I don't know if this could work but you could use: http://search.cpan.org/~purdy/CGI-Application-Plugin-Stream-2.11/lib/CGI/Application/Plugin/Stream.pm
I have a patch for this. Taking!
Assignee: attach-and-request → LpSolit
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
OS: Mac OS X → All
Hardware: x86 → All
Summary: Attachment should be streamed / chunked. → Do not load the whole attachment into memory before sending it to the browser
Target Milestone: --- → Bugzilla 5.0
Keywords: perf
Target Milestone: Bugzilla 5.0 → ---
Attached patch patch, v1 (deleted) — Splinter Review
Attachment #8527198 - Flags: review?(dkl)
Comment on attachment 8527198 [details] [diff] [review] patch, v1 Review of attachment 8527198 [details] [diff] [review]: ----------------------------------------------------------------- r=dkl
Attachment #8527198 - Flags: review?(dkl) → review+
Flags: approval?
Comment on attachment 8527198 [details] [diff] [review] patch, v1 Review of attachment 8527198 [details] [diff] [review]: ----------------------------------------------------------------- overloading the property getter to conditionally print the data to the client is weird, especially since the getter doesn't set ->{data}, but that's what is returned to and printed by the caller. please create a separate method, called something like "print_data", and perform this work there. (ie. call $attachment->print_data() instead of print $attachment->data(1) )
Attachment #8527198 - Flags: review-
Flags: approval?
Assignee: LpSolit → attach-and-request
Status: ASSIGNED → NEW
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: