mercurial/hgweb/webcommands.py
changeset 51834 3b8d92f71d92
parent 51830 454feddab720
child 51858 607e94e01851
equal deleted inserted replaced
51833:7933bcb02bfc 51834:3b8d92f71d92
  1281                     HTTP_NOT_FOUND, b'file(s) not found: %s' % file
  1281                     HTTP_NOT_FOUND, b'file(s) not found: %s' % file
  1282                 )
  1282                 )
  1283 
  1283 
  1284     mimetype, artype, extension, encoding = webutil.archivespecs[type_]
  1284     mimetype, artype, extension, encoding = webutil.archivespecs[type_]
  1285 
  1285 
  1286     web.res.headers[b'Content-Type'] = mimetype
       
  1287     web.res.headers[b'Content-Disposition'] = b'attachment; filename=%s%s' % (
       
  1288         name,
       
  1289         extension,
       
  1290     )
       
  1291 
       
  1292     if encoding:
       
  1293         web.res.headers[b'Content-Encoding'] = encoding
       
  1294 
       
  1295     web.res.setbodywillwrite()
       
  1296     if list(web.res.sendresponse()):
       
  1297         raise error.ProgrammingError(
       
  1298             b'sendresponse() should not emit data if writing later'
       
  1299         )
       
  1300 
       
  1301     if web.req.method == b'HEAD':
  1286     if web.req.method == b'HEAD':
  1302         return []
  1287         return []
  1303 
  1288 
  1304     bodyfh = web.res.getbodyfile()
  1289     def open_archive():
  1305 
  1290         """Open the output "file" for the archiver.
  1306     archival.archive(
  1291 
       
  1292         This function starts the streaming response. Error reporting
       
  1293         after this point will result in short writes without proper
       
  1294         diagnostics to the client.
       
  1295         """
       
  1296         web.res.headers[b'Content-Type'] = mimetype
       
  1297         web.res.headers[
       
  1298             b'Content-Disposition'
       
  1299         ] = b'attachment; filename=%s%s' % (
       
  1300             name,
       
  1301             extension,
       
  1302         )
       
  1303 
       
  1304         if encoding:
       
  1305             web.res.headers[b'Content-Encoding'] = encoding
       
  1306 
       
  1307         web.res.setbodywillwrite()
       
  1308         if list(web.res.sendresponse()):
       
  1309             raise error.ProgrammingError(
       
  1310                 b'sendresponse() should not emit data if writing later'
       
  1311             )
       
  1312 
       
  1313         return web.res.getbodyfile()
       
  1314 
       
  1315     total = archival.archive(
  1307         web.repo,
  1316         web.repo,
  1308         bodyfh,
  1317         open_archive,
  1309         cnode,
  1318         cnode,
  1310         artype,
  1319         artype,
  1311         prefix=name,
  1320         prefix=name,
  1312         match=match,
  1321         match=match,
  1313         subrepos=web.configbool(b"web", b"archivesubrepos"),
  1322         subrepos=web.configbool(b"web", b"archivesubrepos"),
  1314     )
  1323     )
       
  1324     if total == 0:
       
  1325         raise ErrorResponse(HTTP_NOT_FOUND, b'no files found in changeset')
  1315 
  1326 
  1316     return []
  1327     return []
  1317 
  1328 
  1318 
  1329 
  1319 @webcommand(b'static')
  1330 @webcommand(b'static')