Handled chunked requests when transfer-encoding is given.
(ctx context.Context, finalReq *[]byte, clientConn, destConn net.Conn, _ string)
| 183 | |
| 184 | // Handled chunked requests when transfer-encoding is given. |
| 185 | func (h *HTTP) chunkedRequest(ctx context.Context, finalReq *[]byte, clientConn, destConn net.Conn, _ string) error { |
| 186 | |
| 187 | for { |
| 188 | select { |
| 189 | case <-ctx.Done(): |
| 190 | return ctx.Err() |
| 191 | default: |
| 192 | //TODO: we have to implement a way to read the buffer chunk wise according to the chunk size (chunk size comes in hexadecimal) |
| 193 | // because it can happen that some chunks come after 5 seconds. |
| 194 | err := clientConn.SetReadDeadline(time.Now().Add(5 * time.Second)) |
| 195 | if err != nil { |
| 196 | utils.LogError(h.Logger, err, "failed to set the read deadline for the client conn") |
| 197 | return err |
| 198 | } |
| 199 | requestChunked, err := pUtil.ReadBytes(ctx, h.Logger, clientConn) |
| 200 | if err != nil { |
| 201 | if netErr, ok := err.(net.Error); ok && netErr.Timeout() { |
| 202 | break |
| 203 | } |
| 204 | utils.LogError(h.Logger, nil, "failed to read the response message from the destination server") |
| 205 | return err |
| 206 | } |
| 207 | |
| 208 | *finalReq = append(*finalReq, requestChunked...) |
| 209 | // destConn is nil in case of test mode. |
| 210 | if destConn != nil { |
| 211 | _, err = destConn.Write(requestChunked) |
| 212 | if err != nil { |
| 213 | if ctx.Err() != nil { |
| 214 | return ctx.Err() |
| 215 | } |
| 216 | utils.LogError(h.Logger, nil, "failed to write request message to the destination server") |
| 217 | return err |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | //check if the initial request is completed |
| 222 | if strings.HasSuffix(string(requestChunked), "0\r\n\r\n") { |
| 223 | return nil |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | func (h *HTTP) handleChunkedResponses(ctx context.Context, finalResp *[]byte, clientConn, destConn net.Conn, resp []byte) error { |
| 230 |
no test coverage detected