INDY10的IDHttpServer应答客户端
INDY10的IDHttpServer应答客户端
首先贴源码:
procedure TIdHTTPResponseInfo.WriteContent;
begin
if not HeaderHasBeenWritten then begin
WriteHeader;
end; // RLebeau 11/23/2014: Per RFC 2616 Section 4.3:
//
// For response messages, whether or not a message-body is included with
// a message is dependent on both the request method and the response
// status code (section 6.1.1). All responses to the HEAD request method
// MUST NOT include a message-body, even though the presence of entity-
// header fields might lead one to believe they do. All 1xx
// (informational), 204 (no content), and 304 (not modified) responses
// MUST NOT include a message-body. All other responses do include a
// message-body, although it MAY be of zero length. if not (
(FRequestInfo.CommandType = hcHEAD) or
((ResponseNo div 100) = 1) or
(ResponseNo = 204) or
(ResponseNo = 304)
) then
begin
// Always check ContentText first
if ContentText <> '' then begin
FConnection.IOHandler.Write(ContentText, CharsetToEncoding(CharSet));
end
else if Assigned(ContentStream) then begin
ContentStream.Position := 0;
FConnection.IOHandler.Write(ContentStream);
end
else begin
FConnection.IOHandler.WriteLn('<HTML><BODY><B>' + IntToStr(ResponseNo) + ' ' + ResponseText {Do not Localize}
+ '</B></BODY></HTML>', CharsetToEncoding(CharSet)); {Do not Localize}
end;
end; // Clear All - This signifies that WriteConent has been called.
ContentText := ''; {Do not Localize}
ReleaseContentStream;
end;
一共可以应答客户端3种内容:
1)ContentText不为空字串,则发送字符串
2)ContentStream对象存在,则发送流
3)不是上面2种情况,则发送的是HTML。
最后会自动清空应答的字串或释放流,这也是为什么我们手动释放流反而会报“非法访问”错误:
ContentText := '';
ReleaseContentStream;
INDY10的IDHttpServer应答客户端的更多相关文章
- indy10的idhttpServer应答字符串
indy10的idhttpServer应答字符串 先看应答字符串的代码: procedure TIdIOHandler.Write(const AOut: string; AByteEncoding: ...
- indy10的idHttpServer发送流
indy10的idHttpServer发送流 先看源码: procedure TIdIOHandler.Write(AStream: TStream; ASize: TIdStreamSize = 0 ...
- 【Hadoop学习】中:HDFS、shell操作、客户端API操作、数据流、1NN、2NN原理、DataNode配置
一.概述 1.背景.定义.使用场景(一次写入.不支持修改) 2.优(容错)缺点(延迟.不支持小文件.不支持修改) 3.组成架构 NameNode:Master,管理命名空间.配置策略 DataNode ...
- redis.conf配置详细解析
# redis 配置文件示例 # 当你需要为某个配置项指定内存大小的时候,必须要带上单位, # 通常的格式就是 1k 5gb 4m 等酱紫: # # 1k => 1000 bytes # 1kb ...
- [个人翻译]Redis 集群教程(上)
官方原文地址:https://redis.io/topics/cluster-tutorial 水平有限,如果您在阅读过程中发现有翻译的不合理的地方,请留言,我会尽快修改,谢谢. 这是 ...
- HDFS 与 GFS 的设计差异
后端分布式系列」前面关于 HDFS 的一些文章介绍了它的整体架构和一些关键部件的设计实现要点. 我们知道 HDFS 最早是根据 GFS(Google File System)的论文概念模型来设计实现的 ...
- TCP协议
TCP是一个面向连接的协议,在发送数据之前,必须在双方之间建立一条连接. TCP首部 TCP数据封装在IP数据报中 TCP包首部 下面简单说明部分字段的作用: 端口号:通讯双方由IP地址和端口号标识. ...
- redis.conf配置详细翻译解析
# redis 配置文件示例 # 当你需要为某个配置项指定内存大小的时候,必须要带上单位, # 通常的格式就是 1k 5gb 4m 等酱紫: # # 1k => 1000 bytes # 1kb ...
- (转)Web性能优化方案
第一章 打开网站慢现状分析 在公司访问部署在IDC机房的VIP网站时会感觉很慢.是什么原因造成的?为了缩短页面的响应时间,改进我们的用户体验,我们需要知道用户的时间花在等待什么东西上. 可以跟踪一下我 ...
随机推荐
- elasticsearch安装marvel插件
Marvel插件要在Elasticsearch和Kibana中同时安装.Step 1: Install Marvel into Elasticsearch: bin/plugin install li ...
- 公司软raid问题
RAID的技术介绍: stripe width(条带宽度):RAID中的磁盘数,就是组成这个stripe的磁盘数.如,4个磁盘组成的RAID 0,条带宽度就是4. stripe depth(条带深度) ...
- SQL Server 连接池 (ADO.NET) MSDN
连接到数据库服务器通常由几个需要很长时间的步骤组成. 必须建立物理通道(例如套接字或命名管道),必须与服务器进行初次握手,必须分析连接字符串信息,必须由服务器对连接进行身份验证,必须运行检查以便在当前 ...
- TypeError: Object of type 'int64' is not JSON serializable
错误类型:TypeError: Object of type 'int64' is not JSON serializable 错误场景:对Numpy和Pandas结果进行json.dumps报错 错 ...
- mysql索引 B+tree
一.B+tree示意图 二.为什么要用索引 1.索引能极大减少存储引擎需要扫描的数据量:因为索引有序所以可以快速查找并且不用全表查找: 2.索引可以把随机IO变为顺序IO:因为B+tree在数据中保存 ...
- 网络图片转换到本地并转换成base64位
/** * 网络图片转换到本地并转换成base64位 * @param $url * @return string */ public function imgzhuanhuan($url) { // ...
- linux(CentOS) 下mysql自动备份
1.创建并编辑文件 /usr/sbin/bakmysql.sh,命令: vi /usr/sbin/bakmysql.sh 内容如下: db_user="root" db_passw ...
- 插件bootstrap-table
基于Metronic的Bootstrap开发框架经验总结(16)-- 使用插件bootstrap-table实现表格记录的查询.分页.排序等处理 在业务系统开发中,对表格记录的查询.分页.排序等处理是 ...
- Angular 2.0--1
Angular 2.0 从0到1 (五) 第一节:Angular 2.0 从0到1 (一)第二节:Angular 2.0 从0到1 (二)第三节:Angular 2.0 从0到1 (三)第四节:Ang ...
- free命令中buffers和caches的区别
一.命令 1 2 3 4 5 [root@localhost ~]# free -m total used free shared bu ...