Rewind reading to the beginning.
()
| 132 | |
| 133 | // Rewind reading to the beginning. |
| 134 | func (bw *bodyWrapper) Rewind() { |
| 135 | bw.mu.Lock() |
| 136 | defer bw.mu.Unlock() |
| 137 | |
| 138 | // Rewind is no-op if disabled. |
| 139 | if bw.isRewindDisabled { |
| 140 | return |
| 141 | } |
| 142 | |
| 143 | // Rewind is no-op until first read operation. |
| 144 | if !bw.isReadBefore { |
| 145 | return |
| 146 | } |
| 147 | |
| 148 | // If HTTP response is not fully read yet, do it now. |
| 149 | // If error occurs, it will be reported next read operation. |
| 150 | if !bw.isFullyRead { |
| 151 | _ = bw.httpReadFull() |
| 152 | } |
| 153 | |
| 154 | // Reset memory reader. |
| 155 | bw.memReader = bytes.NewReader(bw.memBytes) |
| 156 | } |
| 157 | |
| 158 | // Create new reader to retrieve body contents. |
| 159 | // New reader always reads body from the beginning. |