回复批量请求:使用合适的handler解析:handler接受字段:multipart/mixed首先根据response字段获取content-type:content-type字段,以;分隔:mediatype:multipart/mixed返回一个JSONobject,包括mediaType和boundary属性:批请求处理器是batchParser:执行下一行readBatch方法:boundary的例子:batchresponse_16aba97e-4311-41a4-8c64-302727d1d02ereadBatch具体处理逻辑是基于字符串匹配,即使用indexOf查找边界字符String:readline的实现是读取单行:读取batch首部的header字段:媒体类型必须与硬编码值一致:第一个请求count的数据containedinapplication/httpbatchhasbeenreadSuccess:读取成功,dispatch:count的media-type为text/plain:返回false,responsebody有值,data未定义:有4个可用handlers:text/plain负责读取response.body.textParser的逻辑最简单,直接将body字段返回给response.data:读取第二部分:这部分的content-type是json,所以使用jsonhandler:if(handlerAccepts(handler,cType)){varreadContext=createReadWriteContext(cType,version,context,handler);readContext.response=响应;response.data=parseCallback(handler,body,readContext);返回响应.data!==undefined;}上面代码的语义是只有当一个handler通过函数handlerAccepts的filter时,它才能调用parseCallback并将解析结果传递给response.data.jsonhandler使用JSON.parsenativeAPI对json进行序列化操作数据。成功序列化json数据:最后返回的response是一个数组:调用最外层successhandler:批量请求的回调函数,函数内部_submitBatchRequest:更多Jerry原创文章,尽在:《汪子熙》:
