Repository: electron/electron (language: cpp)

Issue:
[Bug]:  Inconclusive Parsing of Content-Disposition Header 
### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a bug report that matches the one I want to file, without success.

### Electron Version

30.0.0

### What operating system are you using?

Windows

### Operating System Version

Microsoft Windows [Version 10.0.19045.4291]

### What arch are you using?

x64

### Last Known Working Electron version

_No response_

### Expected Behavior

The "content-disposition" header shouldn't be modified and work as in Chromium. Please, take a look at the screenshots I've attached. The problem is in the function HttpResponseHeadersToV8 - https://github.com/electron/electron/blob/main/shell/browser/api/electron_api_web_request.cc#L93C22-L93C45

### Actual Behavior
![1a](https://github.com/electron/electron/assets/5815794/38dcc068-fd00-4c6d-a489-c1a46deeff0e)
![2a](https://github.com/electron/electron/assets/5815794/34925501-ae06-4d80-a506-2540f99581be)

### Testcase Gist URL

https://gist.github.com/gdavidkov/08a8edae420a5b30e9f855f0ebb75a63

### Additional Information

Ref: https://github.com/electron/electron/pull/25961
PR: https://github.com/electron/electron/pull/31669


Discussion / hints:
When I try to add the missing information to the header, I encounter the following problem:
![image](https://github.com/electron/electron/assets/5815794/52a48983-0962-4e7d-b96d-ac54a8ba8444)
![image](https://github.com/electron/electron/assets/5815794/52357763-4bc7-4018-9bac-4ca69b27ece1)

If the header is in not the correct format, the filename is empty. I think we should return the original header like in the Chromium.
![3a](https://github.com/electron/electron/assets/5815794/98362441-1f64-47c4-a2bd-367a1e28da89)
![4a](https://github.com/electron/electron/assets/5815794/f06282bb-05d1-48b2-9752-1b6d7f97c850)
![5](https://github.com/electron/electron/assets/5815794/7502b6a3-cbef-4873-823c-14b14e56098c)

This bug is happening due to a change that was made in this [pull request](https://github.com/electron/electron/pull/25961).  Unfortunately, if the onHeadersReceived is used and client code needs to modify headers, the original value of the constent-disposition header is lost.  Moreover the new value incorrectly includes a space before the word attachment and it drops the value of filename*, which is what should be used to avoid issues with filename encoding on the client side.

The PR should be undone.  Reference to similar [comment](https://github.com/electron/electron/issues/25628#issuecomment-1277780004)
This issue has been automatically marked as stale. **If this issue is still affecting you, please leave any comment** (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the [latest version of Electron](https://www.electronjs.org/releases/stable) or in the [beta](https://www.electronjs.org/releases/beta)—please include it with your comment!
Bump

Fix patch:
diff --git a/shell/browser/api/electron_api_web_request.cc b/shell/browser/api/electron_api_web_request.cc
index 0925f3438e791..e789fc3d3dfab 100644
--- a/shell/browser/api/electron_api_web_request.cc
+++ b/shell/browser/api/electron_api_web_request.cc
@@ -21,7 +21,6 @@
 #include "gin/dictionary.h"
 #include "gin/handle.h"
 #include "gin/object_template_builder.h"
-#include "net/http/http_content_disposition.h"
 #include "shell/browser/api/electron_api_session.h"
 #include "shell/browser/api/electron_api_web_contents.h"
 #include "shell/browser/api/electron_api_web_frame_main.h"
@@ -100,22 +99,6 @@ v8::Local<v8::Value> HttpResponseHeadersToV8(
     std::string key;
     std::string value;
     while (headers->EnumerateHeaderLines(&iter, &key, &value)) {
-      // Note that Web servers not developed with nodejs allow non-utf8
-      // characters in content-disposition's filename field. Use Chromium's
-      // HttpContentDisposition class to decode the correct encoding instead of
-      // arbitrarily converting it to UTF8. It should also be noted that if the
-      // encoding is not specified, HttpContentDisposition will transcode
-      // according to the system's encoding.
-      if (base::EqualsCaseInsensitiveASCII("Content-Disposition", key) &&
-          !value.empty()) {
-        net::HttpContentDisposition header(value, std::string());
-        std::string decodedFilename =
-            header.is_attachment() ? " attachment" : " inline";
-        // The filename must be encased in double quotes for serialization
-        // to happen correctly.
-        std::string filename = "\"" + header.filename() + "\"";
-        value = decodedFilename + "; filename=" + filename;
-      }
       response_headers.EnsureList(key)->Append(value);
     }
   }
diff --git a/spec/api-web-request-spec.ts b/spec/api-web-request-spec.ts
index e57c7a206300a..861ffcd256793 100644
--- a/spec/api-web-request-spec.ts
+++ b/spec/api-web-request-spec.ts
@@ -474,7 +474,7 @@ describe('webRequest module', () => {
 
     it('does not change content-disposition header by default', async () => {
       ses.webRequest.onHeadersReceived((details, callback) => {
-        expect(details.responseHeaders!['content-disposition']).to.deep.equal([' attachment; filename="aa中aa.txt"']);
+        expect(details.responseHeaders!['content-disposition']).to.deep.equal(['attachment; filename=aa中aa.txt']);
         callback({});
       });
       const { data, headers } = await ajax(defaultURL + 'contentDisposition');


Test patch: