From df280375ee0f90ef883c184c95962485e7fd0fc1 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 11 Oct 2019 10:36:12 +0900 Subject: [PATCH] fix: do not manually parse content-type --- shell/browser/net/atom_url_loader_factory.cc | 5 ++--- spec-main/api-protocol-spec.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/shell/browser/net/atom_url_loader_factory.cc b/shell/browser/net/atom_url_loader_factory.cc index fb6e1a627ef05..a864270044a8d 100644 --- a/shell/browser/net/atom_url_loader_factory.cc +++ b/shell/browser/net/atom_url_loader_factory.cc @@ -123,9 +123,8 @@ network::ResourceResponseHead ToResponseHead(const mate::Dictionary& dict) { } // Some apps are passing content-type via headers, which is not accepted // in NetworkService. - if (base::ToLowerASCII(iter.first) == "content-type" && - iter.second.is_string()) { - head.mime_type = iter.second.GetString(); + if (base::ToLowerASCII(iter.first) == "content-type") { + head.headers->GetMimeTypeAndCharset(&head.mime_type, &head.charset); has_content_type = true; } } diff --git a/spec-main/api-protocol-spec.ts b/spec-main/api-protocol-spec.ts index 525c90848af5f..67c38936aaaee 100644 --- a/spec-main/api-protocol-spec.ts +++ b/spec-main/api-protocol-spec.ts @@ -469,6 +469,18 @@ describe('protocol module', () => { expect(r.data).to.have.property('value').that.is.equal(1) }) + it('can set content-type with charset', async () => { + await interceptStringProtocol('http', (request, callback) => { + callback({ + mimeType: 'application/json; charset=UTF-8', + data: '{"value": 1}' + }) + }) + const r = await ajax('http://fake-host') + expect(r.data).to.be.an('object') + expect(r.data).to.have.property('value').that.is.equal(1) + }) + it('can receive post data', async () => { await interceptStringProtocol('http', (request, callback) => { const uploadData = request.uploadData[0].bytes.toString()