@@ -118,37 +118,6 @@ static RefPtr<Document> create_gemini_document(const ByteBuffer& data, const URL
118
118
return parse_html_document (markdown_document->render_to_html (), url);
119
119
}
120
120
121
- String encoding_from_content_type (const String& content_type)
122
- {
123
- auto offset = content_type.index_of (" charset=" );
124
- if (offset.has_value ())
125
- return content_type.substring (offset.value () + 8 , content_type.length () - offset.value () - 8 ).to_lowercase ();
126
-
127
- return " utf-8" ;
128
- }
129
-
130
- String mime_type_from_content_type (const String& content_type)
131
- {
132
- auto offset = content_type.index_of (" ;" );
133
- if (offset.has_value ())
134
- return content_type.substring (0 , offset.value ()).to_lowercase ();
135
-
136
- return content_type;
137
- }
138
-
139
- static String guess_mime_type_based_on_filename (const URL& url)
140
- {
141
- if (url.path ().ends_with (" .png" ))
142
- return " image/png" ;
143
- if (url.path ().ends_with (" .gif" ))
144
- return " image/gif" ;
145
- if (url.path ().ends_with (" .md" ))
146
- return " text/markdown" ;
147
- if (url.path ().ends_with (" .html" ) || url.path ().ends_with (" .htm" ))
148
- return " text/html" ;
149
- return " text/plain" ;
150
- }
151
-
152
121
RefPtr<Document> FrameLoader::create_document_from_mime_type (const ByteBuffer& data, const URL& url, const String& mime_type, const String& encoding)
153
122
{
154
123
if (mime_type.starts_with (" image/" ))
@@ -250,21 +219,8 @@ void FrameLoader::resource_did_load()
250
219
return ;
251
220
}
252
221
253
- String encoding = " utf-8" ;
254
- String mime_type;
255
-
256
- auto content_type = resource ()->response_headers ().get (" Content-Type" );
257
- if (content_type.has_value ()) {
258
- dbg () << " Content-Type header: _" << content_type.value () << " _" ;
259
- encoding = encoding_from_content_type (content_type.value ());
260
- mime_type = mime_type_from_content_type (content_type.value ());
261
- } else {
262
- dbg () << " No Content-Type header to go on! Guessing based on filename..." ;
263
- mime_type = guess_mime_type_based_on_filename (url);
264
- }
265
-
266
- dbg () << " I believe this content has MIME type '" << mime_type << " ', encoding '" << encoding << " '" ;
267
- auto document = create_document_from_mime_type (resource ()->encoded_data (), url, mime_type, encoding);
222
+ dbg () << " I believe this content has MIME type '" << resource ()->mime_type () << " ', encoding '" << resource ()->encoding () << " '" ;
223
+ auto document = create_document_from_mime_type (resource ()->encoded_data (), url, resource ()->mime_type (), resource ()->encoding ());
268
224
ASSERT (document);
269
225
frame ().set_document (document);
270
226
0 commit comments