前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >go http transfer.go学习

go http transfer.go学习

原创
作者头像
IT工作者
发布2022-07-28 09:48:12
2220
发布2022-07-28 09:48:12
举报
文章被收录于专栏:程序技术知识

整个的transfer.go做了很多操作 ,可以把它理解为http的内部处理或者转换操作

先看几个关键结构体的定义

transferWriter 是为了实现用户可操作填值的头信息处理的数据结构

代码语言:javascript
复制
type transferWriter struct {
    Method           string
    Body             io.Reade
    BodyCloser       io.Close
    ResponseToHEAD   bool
    ContentLength    int64 // -1 means unknown, 0 means exactly none
    Close            bool
    TransferEncoding []string
    Trailer          Heade
    IsResponse       bool
}

transferReade

代码语言:javascript
复制
type transferReader struct {
    // Input
    Header        Heade
    StatusCode    int
    RequestMethod string
    ProtoMajor    int
    ProtoMinor    int
    // Output
    Body             io.ReadClose
    ContentLength    int64
    TransferEncoding []string
    Close            bool
    Trailer          Heade
}

body定义

代码语言:javascript
复制
type body struct {
    src          io.Reade
    hdr          interface{}   // non-nil (Response or Request) value means read traile
    r            *bufio.Reader // underlying wire-format reader for the traile
    closing      bool          // is the connection to be closed after reading body?
    doEarlyClose bool          // whether Close should stop early

    mu         sync.Mutex // guards following, and calls to Read and Close
    sawEOF     bool
    closed     bool
    earlyClose bool   // Close called and we didn't read to the end of src
    onHitEOF   func() // if non-nil, func to call when EOF is Read
}

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档