File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " uquik" ,
3- "version" : " 1.0.22 " ,
3+ "version" : " 1.0.23 " ,
44 "description" : " uQuik HTTP(S) framework" ,
55 "main" : " index.js" ,
66 "scripts" : {
Original file line number Diff line number Diff line change 11// eslint-disable-next-line no-unused-vars
22const { Readable, Writable } = require ( 'readable-stream' )
3+ const path = require ( 'path' )
34// eslint-disable-next-line no-unused-vars
45const Server = require ( './Server' ) // lgtm [js/unused-local-variable]
56const cookie = require ( './helpers/cookie' )
@@ -461,6 +462,23 @@ class Response extends Writable {
461462 }
462463 }
463464
465+ /**
466+ * Writes approriate headers to signify that file at path has been attached.
467+ *
468+ * @param {String } path
469+ * @param {String= } name
470+ * @returns {Response }
471+ */
472+ attachment ( filePath , name ) {
473+ if ( filePath ) {
474+ const fileName = name || path . basename ( filePath )
475+ this . header ( 'Content-Disposition' , `attachment; filename="${ fileName } "` ) . type ( path . extname ( fileName ) )
476+ } else {
477+ this . header ( 'Content-Disposition' , 'attachment' )
478+ }
479+ return this
480+ }
481+
464482 /**
465483 * Instantly aborts/closes current request without writing a status response code.
466484 * Use this only in extreme situations to abort a request where a proper response is not neccessary.
You can’t perform that action at this time.
0 commit comments