소스 검색

LibWeb/Fetch: Expose a minimised Content-Type to Resource Timing

See:
- https://github.com/whatwg/fetch/commit/931cd06
Jamie Mansfield 1 년 전
부모
커밋
951fbb1837
2개의 변경된 파일15개의 추가작업 그리고 1개의 파일을 삭제
  1. 12 1
      Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
  2. 3 0
      Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h

+ 12 - 1
Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp

@@ -24,6 +24,7 @@
 #include <LibWeb/Fetch/Infrastructure/FetchController.h>
 #include <LibWeb/Fetch/Infrastructure/FetchController.h>
 #include <LibWeb/Fetch/Infrastructure/FetchParams.h>
 #include <LibWeb/Fetch/Infrastructure/FetchParams.h>
 #include <LibWeb/Fetch/Infrastructure/FetchTimingInfo.h>
 #include <LibWeb/Fetch/Infrastructure/FetchTimingInfo.h>
+#include <LibWeb/Fetch/Infrastructure/HTTP/Headers.h>
 #include <LibWeb/Fetch/Infrastructure/HTTP/Methods.h>
 #include <LibWeb/Fetch/Infrastructure/HTTP/Methods.h>
 #include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
 #include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
 #include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
 #include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
@@ -600,7 +601,17 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
                 ? 0
                 ? 0
                 : response.status();
                 : response.status();
 
 
-            // FIXME: 7. If fetchParams’s request’s initiator type is not null, then mark resource timing given timingInfo,
+            // 7. If fetchParams’s request’s mode is not "navigate" or response’s has-cross-origin-redirects is false:
+            if (fetch_params.request()->mode() != Infrastructure::Request::Mode::Navigate || !response.has_cross_origin_redirects()) {
+                // 1. Let mimeType be the result of extracting a MIME type from response’s header list.
+                auto mime_type = response.header_list()->extract_mime_type();
+
+                // 2. If mimeType is non-null, then set bodyInfo’s content type to the result of minimizing a supported MIME type given mimeType.
+                if (mime_type.has_value())
+                    body_info.content_type = MimeSniff::minimise_a_supported_mime_type(mime_type.value());
+            }
+
+            // FIXME: 8. If fetchParams’s request’s initiator type is not null, then mark resource timing given timingInfo,
             //           request’s URL, request’s initiator type, global, cacheState, bodyInfo, and responseStatus.
             //           request’s URL, request’s initiator type, global, cacheState, bodyInfo, and responseStatus.
             (void)timing_info;
             (void)timing_info;
             (void)global;
             (void)global;

+ 3 - 0
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h

@@ -49,6 +49,9 @@ public:
         // https://fetch.spec.whatwg.org/#fetch-timing-info-decoded-body-size
         // https://fetch.spec.whatwg.org/#fetch-timing-info-decoded-body-size
         u64 decoded_size { 0 };
         u64 decoded_size { 0 };
 
 
+        // https://fetch.spec.whatwg.org/#response-body-info-content-type
+        String content_type {};
+
         bool operator==(BodyInfo const&) const = default;
         bool operator==(BodyInfo const&) const = default;
     };
     };