MCPcopy Create free account
hub / github.com/aria2/aria2 / executeInternal

Method executeInternal

src/HttpSkipResponseCommand.cc:98–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98bool HttpSkipResponseCommand::executeInternal()
99{
100 if (getRequest()->getMethod() == Request::METHOD_HEAD ||
101 (totalLength_ == 0 && sinkFilterOnly_)) {
102 // If request method is HEAD or content-length header is present and
103 // it's value is 0, then pool socket for reuse.
104 // If content-length header is not present, then EOF is expected in the end.
105 // In this case, the content is thrown away and socket cannot be pooled.
106 if (getRequest()->getMethod() == Request::METHOD_HEAD ||
107 httpResponse_->getHttpHeader()->defined(HttpHeader::CONTENT_LENGTH)) {
108 poolConnection();
109 }
110 return processResponse();
111 }
112 bool eof = false;
113 try {
114 size_t bufSize;
115 if (getSocketRecvBuffer()->bufferEmpty()) {
116 eof = getSocketRecvBuffer()->recv() == 0 && !getSocket()->wantRead() &&
117 !getSocket()->wantWrite();
118 }
119 if (!eof) {
120 if (sinkFilterOnly_) {
121 if (totalLength_ > 0) {
122 bufSize = std::min(
123 totalLength_ - receivedBytes_,
124 static_cast<int64_t>(getSocketRecvBuffer()->getBufferLength()));
125 }
126 else {
127 bufSize = getSocketRecvBuffer()->getBufferLength();
128 }
129 receivedBytes_ += bufSize;
130 }
131 else {
132 // receivedBytes_ is not updated if transferEncoding is set.
133 // The return value is safely ignored here.
134 streamFilter_->transform(std::shared_ptr<BinaryStream>(),
135 std::shared_ptr<Segment>(),
136 getSocketRecvBuffer()->getBuffer(),
137 getSocketRecvBuffer()->getBufferLength());
138 bufSize = streamFilter_->getBytesProcessed();
139 }
140 getSocketRecvBuffer()->drain(bufSize);
141 }
142 if (totalLength_ != 0 && eof) {
143 throw DL_RETRY_EX(EX_GOT_EOF);
144 }
145 }
146 catch (RecoverableException& e) {
147 A2_LOG_DEBUG_EX(EX_EXCEPTION_CAUGHT, e)
148 return processResponse();
149 }
150
151 if (eof) {
152 // we may get EOF before non-sink streamFilter reports its
153 // completion. There are some broken servers to prevent
154 // streamFilter from completion. Since we just discard the
155 // response body anyway, so we assume that the response is

Callers

nothing calls this directly

Calls 12

bufferEmptyMethod · 0.80
recvMethod · 0.80
drainMethod · 0.80
definedMethod · 0.45
wantReadMethod · 0.45
wantWriteMethod · 0.45
getBufferLengthMethod · 0.45
transformMethod · 0.45
getBufferMethod · 0.45
getBytesProcessedMethod · 0.45
finishedMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected