MCPcopy Create free account
hub / github.com/azadkuh/qhttp / headersComplete

Method headersComplete

src/qhttpserverconnection.cpp:127–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125}
126
127int
128QHttpConnectionPrivate::headersComplete(http_parser* parser) {
129 if ( ilastRequest == nullptr )
130 return 0;
131
132 ilastRequest->d_func()->iurl = QUrl(itempUrl);
133
134 // set method
135 ilastRequest->d_func()->imethod =
136 static_cast<THttpMethod>(parser->method);
137
138 // set version
139 ilastRequest->d_func()->iversion = QString("%1.%2")
140 .arg(parser->http_major)
141 .arg(parser->http_minor);
142
143 // Insert last remaining header
144 ilastRequest->d_func()->iheaders.insert(
145 itempHeaderField.toLower(),
146 itempHeaderValue.toLower()
147 );
148
149 // set client information
150 if ( isocket.ibackendType == ETcpSocket ) {
151 ilastRequest->d_func()->iremoteAddress = isocket.itcpSocket->peerAddress().toString();
152 ilastRequest->d_func()->iremotePort = isocket.itcpSocket->peerPort();
153
154 } else if ( isocket.ibackendType == ELocalSocket ) {
155 ilastRequest->d_func()->iremoteAddress = isocket.ilocalSocket->fullServerName();
156 ilastRequest->d_func()->iremotePort = 0; // not used in local sockets
157 }
158
159 if ( ilastResponse )
160 ilastResponse->deleteLater();
161 ilastResponse = new QHttpResponse(q_func());
162
163 if ( parser->http_major < 1 || parser->http_minor < 1 )
164 ilastResponse->d_func()->ikeepAlive = false;
165
166 // close the connection if response was the last packet
167 QObject::connect(ilastResponse, &QHttpResponse::done, [this](bool wasTheLastPacket){
168 ikeepAlive = !wasTheLastPacket;
169 if ( wasTheLastPacket ) {
170 isocket.flush();
171 isocket.close();
172 }
173 });
174
175 // we are good to go!
176 if ( ihandler )
177 ihandler(ilastRequest, ilastResponse);
178 else
179 emit q_ptr->newRequest(ilastRequest, ilastResponse);
180
181 return 0;
182}
183
184int

Callers

nothing calls this directly

Calls 3

toStringMethod · 0.80
flushMethod · 0.80
closeMethod · 0.80

Tested by

no test coverage detected