当前位置: 首页>>代码示例>>Python>>正文


Python IRequest.setHeader方法代码示例

本文整理汇总了Python中nevow.inevow.IRequest.setHeader方法的典型用法代码示例。如果您正苦于以下问题:Python IRequest.setHeader方法的具体用法?Python IRequest.setHeader怎么用?Python IRequest.setHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nevow.inevow.IRequest的用法示例。


在下文中一共展示了IRequest.setHeader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render_POST

# 需要导入模块: from nevow.inevow import IRequest [as 别名]
# 或者: from nevow.inevow.IRequest import setHeader [as 别名]
 def render_POST(self, ctx):
     req = IRequest(ctx)
     log.msg(format="User reports incident through web page: %(details)s",
             details=get_arg(req, "details", ""),
             level=log.WEIRD, umid="LkD9Pw")
     req.setHeader("content-type", "text/plain")
     return "Thank you for your report!"
开发者ID:drewp,项目名称:tahoe-lafs,代码行数:9,代码来源:root.py

示例2: renderHTTP

# 需要导入模块: from nevow.inevow import IRequest [as 别名]
# 或者: from nevow.inevow.IRequest import setHeader [as 别名]
 def renderHTTP(self, ctx):
     req = IRequest(ctx)
     if req.method == 'GET':
         req.setHeader('Content-Type', 'text/plain')
         return 'PUT data here to create an object.'
     elif req.method == 'PUT':
         return self.handlePUT(req)
     else:
         req.setResponseCode(http.NOT_ALLOWED)
         req.setHeader('Content-Type', 'text/plain')
         return 'Method not allowed'
开发者ID:fusionapp,项目名称:entropy,代码行数:13,代码来源:store.py

示例3: simple

# 需要导入模块: from nevow.inevow import IRequest [as 别名]
# 或者: from nevow.inevow.IRequest import setHeader [as 别名]
 def simple(self, ctx, text, code=http.BAD_REQUEST):
     req = IRequest(ctx)
     req.setResponseCode(code)
     #req.responseHeaders.setRawHeaders("content-encoding", [])
     #req.responseHeaders.setRawHeaders("content-disposition", [])
     req.setHeader("content-type", "text/plain;charset=utf-8")
     if isinstance(text, unicode):
         text = text.encode("utf-8")
     req.setHeader("content-length", str(len(text)))
     req.write(text)
     # TODO: consider putting the requested URL here
     req.finishRequest(False)
开发者ID:gnusosa,项目名称:tahoe-lafs,代码行数:14,代码来源:common.py

示例4: render_OPTIONS

# 需要导入模块: from nevow.inevow import IRequest [as 别名]
# 或者: from nevow.inevow.IRequest import setHeader [as 别名]
    def render_OPTIONS(self, ctx):
        """
        Handle HTTP OPTIONS request by adding appropriate headers.

        :param ctx: client transaction from which request is extracted
        :returns: str (empty)
        """
        req = IRequest(ctx)
        req.setHeader("server", "Tahoe-LAFS gateway")
        methods = ', '.join([m[7:] for m in dir(self) if m.startswith('render_')])
        req.setHeader("allow", methods)
        req.setHeader("public", methods)
        req.setHeader("compliance", "rfc=2068, rfc=2616")
        req.setHeader("content-length", 0)
        return ""
开发者ID:tahoe-lafs,项目名称:tahoe-lafs,代码行数:17,代码来源:common.py

示例5: text_plain

# 需要导入模块: from nevow.inevow import IRequest [as 别名]
# 或者: from nevow.inevow.IRequest import setHeader [as 别名]
def text_plain(text, ctx):
    req = IRequest(ctx)
    req.setHeader("content-type", "text/plain")
    req.setHeader("content-length", len(text))
    return text
开发者ID:gnusosa,项目名称:tahoe-lafs,代码行数:7,代码来源:common.py

示例6: renderHTTP

# 需要导入模块: from nevow.inevow import IRequest [as 别名]
# 或者: from nevow.inevow.IRequest import setHeader [as 别名]
    def renderHTTP(self, ctx):
        req = IRequest(ctx)
        gte = static.getTypeAndEncoding
        ctype, encoding = gte(self.filename,
                              static.File.contentTypes,
                              static.File.contentEncodings,
                              defaultType="text/plain")
        req.setHeader("content-type", ctype)
        if encoding:
            req.setHeader("content-encoding", encoding)

        if boolean_of_arg(get_arg(req, "save", "False")):
            # tell the browser to save the file rather display it we don't
            # try to encode the filename, instead we echo back the exact same
            # bytes we were given in the URL. See the comment in
            # FileNodeHandler.render_GET for the sad details.
            req.setHeader("content-disposition",
                          'attachment; filename="%s"' % self.filename)

        filesize = self.filenode.get_size()
        assert isinstance(filesize, (int,long)), filesize
        first, size = 0, None
        contentsize = filesize
        req.setHeader("accept-ranges", "bytes")

        # TODO: for mutable files, use the roothash. For LIT, hash the data.
        # or maybe just use the URI for CHK and LIT.
        rangeheader = req.getHeader('range')
        if rangeheader:
            ranges = self.parse_range_header(rangeheader)

            # ranges = None means the header didn't parse, so ignore
            # the header as if it didn't exist.  If is more than one
            # range, then just return the first for now, until we can
            # generate multipart/byteranges.
            if ranges is not None:
                first, last = ranges[0]

                if first >= filesize:
                    raise WebError('First beyond end of file',
                                   http.REQUESTED_RANGE_NOT_SATISFIABLE)
                else:
                    first = max(0, first)
                    last = min(filesize-1, last)

                    req.setResponseCode(http.PARTIAL_CONTENT)
                    req.setHeader('content-range',"bytes %s-%s/%s" %
                                  (str(first), str(last),
                                   str(filesize)))
                    contentsize = last - first + 1
                    size = contentsize

        req.setHeader("content-length", b"%d" % contentsize)
        if req.method == "HEAD":
            return ""

        finished = []
        def _request_finished(ign):
            finished.append(True)
        req.notifyFinish().addBoth(_request_finished)

        d = self.filenode.read(req, first, size)

        def _finished(ign):
            if not finished:
                req.finish()
        def _error(f):
            lp = log.msg("error during GET", facility="tahoe.webish", failure=f,
                         level=log.UNUSUAL, umid="xSiF3w")
            if finished:
                log.msg("but it's too late to tell them", parent=lp,
                        level=log.UNUSUAL, umid="j1xIbw")
                return
            req._tahoe_request_had_error = f # for HTTP-style logging
            if req.startedWriting:
                # The content-type is already set, and the response code has
                # already been sent, so we can't provide a clean error
                # indication. We can emit text (which a browser might
                # interpret as something else), and if we sent a Size header,
                # they might notice that we've truncated the data. Keep the
                # error message small to improve the chances of having our
                # error response be shorter than the intended results.
                #
                # We don't have a lot of options, unfortunately.
                req.write("problem during download\n")
                req.finish()
            else:
                # We haven't written anything yet, so we can provide a
                # sensible error message.
                eh = MyExceptionHandler()
                eh.renderHTTP_exception(ctx, f)
        d.addCallbacks(_finished, _error)
        return req.deferred
开发者ID:tahoe-lafs,项目名称:tahoe-lafs,代码行数:95,代码来源:filenode.py


注:本文中的nevow.inevow.IRequest.setHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。