// send server hello void sendServerHello(SSL& ssl, BufferOutput buffer) { if (ssl.getSecurity().get_resuming()) ssl.verifyState(clientKeyExchangeComplete); else ssl.verifyState(clientHelloComplete); if (ssl.GetError()) return; ServerHello sh(ssl.getSecurity().get_connection().version_, ssl.getSecurity().get_connection().compression_); RecordLayerHeader rlHeader; HandShakeHeader hsHeader; mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer); buildServerHello(ssl, sh); ssl.set_random(sh.get_random(), server_end); buildHeaders(ssl, hsHeader, rlHeader, sh); buildOutput(*out.get(), rlHeader, hsHeader, sh); hashHandShake(ssl, *out.get()); if (buffer == buffered) ssl.addBuffer(out.release()); else ssl.Send(out->get_buffer(), out->get_size()); }
RefPtr<FetchRequest> FetchRequest::create(ScriptExecutionContext& context, FetchRequest& input, const Dictionary& init, ExceptionCode& ec) { if (input.isDisturbed()) { ec = TypeError; return nullptr; } FetchRequest::InternalRequest internalRequest(input.m_internalRequest); if (!buildOptions(internalRequest, context, init)) { ec = TypeError; return nullptr; } RefPtr<FetchHeaders> headers = buildHeaders(init, internalRequest, input.m_headers.ptr()); if (!headers) { ec = TypeError; return nullptr; } FetchBody body = buildBody(init, *headers, &input.m_body); if (!validateBodyAndMethod(body, internalRequest)) { ec = TypeError; return nullptr; } if (!input.m_body.isEmpty()) input.setDisturbed(); return adoptRef(*new FetchRequest(context, WTFMove(body), headers.releaseNonNull(), WTFMove(internalRequest))); }
RefPtr<FetchRequest> FetchRequest::create(ScriptExecutionContext& context, const String& url, const Dictionary& init, ExceptionCode& ec) { // FIXME: Tighten the URL parsing algorithm according https://url.spec.whatwg.org/#concept-url-parser. URL requestURL = context.completeURL(url); if (!requestURL.isValid() || !requestURL.user().isEmpty() || !requestURL.pass().isEmpty()) { ec = TypeError; return nullptr; } FetchRequest::InternalRequest internalRequest; internalRequest.options.setMode(FetchOptions::Mode::Cors); internalRequest.options.setCredentials(FetchOptions::Credentials::Omit); internalRequest.referrer = ASCIILiteral("client"); internalRequest.request.setURL(requestURL); if (!buildOptions(internalRequest, context, init)) { ec = TypeError; return nullptr; } RefPtr<FetchHeaders> headers = buildHeaders(init, internalRequest); if (!headers) { ec = TypeError; return nullptr; } FetchBody body = buildBody(init, *headers); if (!validateBodyAndMethod(body, internalRequest)) { ec = TypeError; return nullptr; } return adoptRef(*new FetchRequest(context, WTFMove(body), headers.releaseNonNull(), WTFMove(internalRequest))); }
void WebServer::HTTPResponse::sendChunkHead() { if (m_dataSent) { ESP_LOGE(LOG_TAG, "HTTPResponse: Chunk headers already sent! Attempt to send again/more."); } m_dataSent = true; mg_send_head(m_nc, m_status, -1, buildHeaders().c_str()); } // sendChunkHead
/** * @brief Send data to the HTTP caller. * Send the data to the HTTP caller. No further data should be sent after this call. * @param [in] pData The data to be sent to the HTTP caller. * @param [in] length The length of the data to be sent. * @return N/A. */ void WebServer::HTTPResponse::sendData(const uint8_t* pData, size_t length) { if (m_dataSent) { ESP_LOGE(LOG_TAG, "HTTPResponse: Data already sent! Attempt to send again/more."); return; } m_dataSent = true; mg_send_head(m_nc, m_status, length, buildHeaders().c_str()); mg_send(m_nc, pData, length); m_nc->flags |= MG_F_SEND_AND_CLOSE; } // sendData
// send certificate void sendCertificate(SSL& ssl, BufferOutput buffer) { if (ssl.GetError()) return; Certificate cert(ssl.getCrypto().get_certManager().get_cert()); RecordLayerHeader rlHeader; HandShakeHeader hsHeader; mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer); buildHeaders(ssl, hsHeader, rlHeader, cert); buildOutput(*out.get(), rlHeader, hsHeader, cert); hashHandShake(ssl, *out.get()); if (buffer == buffered) ssl.addBuffer(out.release()); else ssl.Send(out->get_buffer(), out->get_size()); }
// send server hello done void sendServerHelloDone(SSL& ssl, BufferOutput buffer) { if (ssl.GetError()) return; ServerHelloDone shd; RecordLayerHeader rlHeader; HandShakeHeader hsHeader; mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer); buildHeaders(ssl, hsHeader, rlHeader, shd); buildOutput(*out.get(), rlHeader, hsHeader, shd); hashHandShake(ssl, *out.get()); if (buffer == buffered) ssl.addBuffer(out.release()); else ssl.Send(out->get_buffer(), out->get_size()); }
// send client_hello, no buffering void sendClientHello(SSL& ssl) { ssl.verifyState(serverNull); if (ssl.GetError()) return; ClientHello ch(ssl.getSecurity().get_connection().version_, ssl.getSecurity().get_connection().compression_); RecordLayerHeader rlHeader; HandShakeHeader hsHeader; output_buffer out; buildClientHello(ssl, ch); ssl.set_random(ch.get_random(), client_end); buildHeaders(ssl, hsHeader, rlHeader, ch); buildOutput(out, rlHeader, hsHeader, ch); hashHandShake(ssl, out); ssl.Send(out.get_buffer(), out.get_size()); }
// send client key exchange void sendClientKeyExchange(SSL& ssl, BufferOutput buffer) { ssl.verifyState(serverHelloDoneComplete); if (ssl.GetError()) return; ClientKeyExchange ck(ssl); ck.build(ssl); ssl.makeMasterSecret(); RecordLayerHeader rlHeader; HandShakeHeader hsHeader; mySTL::auto_ptr<output_buffer> out(NEW_YS output_buffer); buildHeaders(ssl, hsHeader, rlHeader, ck); buildOutput(*out.get(), rlHeader, hsHeader, ck); hashHandShake(ssl, *out.get()); if (buffer == buffered) ssl.addBuffer(out.release()); else ssl.Send(out->get_buffer(), out->get_size()); }