// This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/.
use glean::net::{PingUploadRequest, PingUploader, UploadResult}; use once_cell::sync::OnceCell; use std::sync::Once; use url::Url; use viaduct::{Error::*, Request};
impl PingUploader for ViaductUploader { /// Uploads a ping to a server. /// /// # Arguments /// /// * `upload_request` - the ping and its metadata to upload. fn upload(&self, upload_request: PingUploadRequest) -> UploadResult {
log::trace!("FOG Ping Uploader uploading to {}", upload_request.url);
// SAFETY NOTE: Safe because it returns a primitive by value. ifunsafe { FOG_TooLateToSend() } {
log::trace!("Attempted to send ping too late into shutdown."); return UploadResult::done();
}
let debug_tagged = upload_request
.headers
.iter()
.any(|(name, _)| name == "X-Debug-ID"); let localhost_port = static_prefs::pref!("telemetry.fog.test.localhost_port"); if localhost_port < 0
|| (localhost_port == 0 && !debug_tagged && cfg!(feature = "disable_upload"))
{
log::info!("FOG Ping uploader faking success"); return UploadResult::http_status(200);
}
// Localhost-destined pings are sent without OHTTP, // even if configured to use OHTTP. let result = if localhost_port == 0 && should_ohttp_upload(&upload_request) {
ohttp_upload(upload_request)
} else {
viaduct_upload(upload_request)
};
log::trace!( "FOG Ping Uploader completed uploading (Result {:?})",
result
);
match result {
Ok(result) => result,
Err(ViaductUploaderError::Viaduct(ve)) => match ve {
NonTlsUrl | UrlError(_) => UploadResult::unrecoverable_failure(),
RequestHeaderError(_)
| BackendError(_)
| NetworkError(_)
| BackendNotInitialized
| SetBackendError => UploadResult::recoverable_failure(),
},
Err(
ViaductUploaderError::Bhttp(_)
| ViaductUploaderError::Ohttp(_)
| ViaductUploaderError::Fatal,
) => UploadResult::unrecoverable_failure(),
}
}
}
log::trace!("FOG ohttp uploader uploading to {}", parsed_relay_url);
const OHTTP_MESSAGE_CONTENT_TYPE: &str = "message/ohttp-req"; let req = Request::post(parsed_relay_url)
.header(
viaduct::header_names::CONTENT_TYPE,
OHTTP_MESSAGE_CONTENT_TYPE,
)?
.body(capsule); let res = req.send()?;
if res.status == 200 { // This just tells us the HTTP went well. Check OHTTP's status. let binary_response = ohttp_response.decapsulate(&res.body)?; letmut cursor = std::io::Cursor::new(binary_response); let bhttp_message = bhttp::Message::read_bhttp(&mut cursor)?; let res = bhttp_message
.control()
.status()
.ok_or(ViaductUploaderError::Fatal)?;
Ok(UploadResult::http_status(res as i32))
} else {
Ok(UploadResult::http_status(res.status as i32))
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.