Skip to content

HTTP archive support project

Josh Matthews edited this page Sep 25, 2017 · 4 revisions

Implement support for creating HTTP archive files from Servo sessions

Background information: Major browsers support creating HTTP archive files which can be analyzed by other tools. Adding native support for this feature to Servo will allow us to compare our network performance more precisely against other browsers.

Tracking issue: https://github.com/servo/servo/issues/4004 (please ask questions here)

Initial steps:

  • email the mozilla.dev.servo mailing list (be sure to subscribe to it first!) introducing your group and asking any necessary questions
  • add the rust-har library as a dependency of the net_traits component
  • define an enum that represents either a filename or an IpcSender that can send a vector of har::Log values
  • using the new enum, add a new optional member to ResourceChannelManager that is initialized via create_resource_threads
  • modify the CoreResourceMsg::Exit message to contain an optional vector of har::Page values
  • add a command line flag that controls whether to store HAR data. The flag should accept a filename argument.
  • using this new global option, pass an appropriate argument when calling new_resource_threads in create_constellation
  • when processing the CoreResourseMsg::Exit message, send an empty vector or write an empty vector as JSON to an appropriate file depending on the member variable that was added earlier

Subsequent steps:

  • Store a vector of har::Page in Constellation
    • when a new pipeline is created (Constellation::new_pipeline), add an entry to this vector using the pipeline ID as the page's unique id
  • Store a vector of har::Entry values in CoreResourceManager, wrapped inside Arc and Mutex types to allow other threads to manipulate the vector
    • add a Arc<Mutex<Vec<har::Entry>>> member to the FetchContext structure, and initialize it from the resource manager's new field
    • in http_fetch, create a new har::Request instance based on the values available from the request variable
    • before step 5 of http_fetch, create a new har::Response value based on the values available from the response variable
    • create a new har::Entry value and append it to the vector stored in FetchContext, using the request's pipeline_id field as the pageref value to associate it with the pages stored in the Constellation
    • during Constellation::handle_shutdown as part of the CoreResourceMsg::Exit message send the vector of har::Page values
    • when the resource thread receives this message (CoreResourceManager::process_msg), if there is a vector present then combine the provided Page and member Entry values and process them according to the member variable (either sending them on the channel or writing them to a file)
  • add a unit test to ensure that the resource thread logs the HAR information correctly:
    • create a resource manager with an IpcSender as the HAR output
    • start an HTTP server and fetch a URL from it by sending a CoreResourceMsg::Fetch message to the resource manager
    • Once the fetch is complete, send the exit message to the resource manager with a har::Page value for the single fetch (acting as the Constellation)
    • assert that the expected har::Log value is received from the resource thread
Clone this wiki locally