diff options
author | Grant Gayed <grant_gayed@ca.ibm.com> | 2011-10-17 15:33:30 -0400 |
---|---|---|
committer | Grant Gayed <grant_gayed@ca.ibm.com> | 2011-10-17 15:34:40 -0400 |
commit | 016dc8e9d43c2ce1a2b2df6c6d7ccc20e421936e (patch) | |
tree | 85a8f85c75b90eab41516ab12d0f078f5f75debe | |
parent | 3d13668fc8f67ff4fa0a1a63646005afad14ca02 (diff) | |
download | eclipse.platform.swt-016dc8e9d43c2ce1a2b2df6c6d7ccc20e421936e.tar.gz eclipse.platform.swt-016dc8e9d43c2ce1a2b2df6c6d7ccc20e421936e.tar.xz eclipse.platform.swt-016dc8e9d43c2ce1a2b2df6c6d7ccc20e421936e.zip |
Bug 332259 - Post requests always uses
application/x-www-form-urlencoded content-type
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java | 31 | ||||
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java | 24 |
2 files changed, 44 insertions, 11 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java index 150635f476..bea10f2751 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java @@ -83,7 +83,8 @@ class Mozilla extends WebBrowser { static final char SEPARATOR_OS = System.getProperty ("file.separator").charAt (0); //$NON-NLS-1$ static final String ABOUT_BLANK = "about:blank"; //$NON-NLS-1$ static final String DISPOSE_LISTENER_HOOKED = "org.eclipse.swt.browser.Mozilla.disposeListenerHooked"; //$NON-NLS-1$ - static final String HEADER_CONTENTTYPE = "Content-Type"; //$NON-NLS-1 + static final String HEADER_CONTENTLENGTH = "content-length"; //$NON-NLS-1 + static final String HEADER_CONTENTTYPE = "content-type"; //$NON-NLS-1 static final String MIMETYPE_FORMURLENCODED = "application/x-www-form-urlencoded"; //$NON-NLS-1$ static final String PREFIX_JAVASCRIPT = "javascript:"; //$NON-NLS-1$ static final String PREFERENCE_CHARSET = "intl.charset.default"; //$NON-NLS-1$ @@ -2819,12 +2820,30 @@ public boolean setUrl (String url, String postData, String[] headers) { postDataStream = new nsIMIMEInputStream (result[0]); rc = postDataStream.SetData (dataStream.getAddress ()); if (rc != XPCOM.NS_OK) error (rc); - rc = postDataStream.SetAddContentLength (1); - if (rc != XPCOM.NS_OK) error (rc); - byte[] name = MozillaDelegate.wcsToMbcs (null, HEADER_CONTENTTYPE, true); - byte[] value = MozillaDelegate.wcsToMbcs (null, MIMETYPE_FORMURLENCODED, true); - rc = postDataStream.AddHeader (name, value); + + boolean foundLength = false; + boolean foundType = false; + if (headers != null) { + for (int i = 0; i < headers.length; i++) { + int index = headers[i].indexOf (':'); + if (index != -1) { + String name = headers[i].substring (0, index).trim ().toLowerCase (); + if (name.equals (HEADER_CONTENTLENGTH)) { + foundLength = true; + } else if (name.equals (HEADER_CONTENTTYPE)) { + foundType = true; + } + } + } + } + rc = postDataStream.SetAddContentLength (foundLength ? 0 : 1); if (rc != XPCOM.NS_OK) error (rc); + if (!foundType) { + byte[] name = MozillaDelegate.wcsToMbcs (null, HEADER_CONTENTTYPE, true); + byte[] value = MozillaDelegate.wcsToMbcs (null, MIMETYPE_FORMURLENCODED, true); + rc = postDataStream.AddHeader (name, value); + if (rc != XPCOM.NS_OK) error (rc); + } } result[0] = 0; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java b/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java index 952c776dc1..c473e5299c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java +++ b/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java @@ -39,8 +39,9 @@ class WebKit extends WebBrowser { static final String ABOUT_BLANK = "about:blank"; //$NON-NLS-1$ static final String CHARSET_UTF8 = "UTF-8"; //$NON-NLS-1$ static final String CLASSNAME_EXTERNAL = "External"; //$NON-NLS-1$ - static final String ENCODING_FORM = "Content-Type: application/x-www-form-urlencoded"; //$NON-NLS-1$ static final String FUNCTIONNAME_CALLJAVA = "callJava"; //$NON-NLS-1$ + static final String HEADER_CONTENTTYPE = "content-type"; //$NON-NLS-1$ + static final String MIMETYPE_FORMURLENCODED = "application/x-www-form-urlencoded"; //$NON-NLS-1$ static final String OBJECTNAME_EXTERNAL = "external"; //$NON-NLS-1$ static final String PROPERTY_LENGTH = "length"; //$NON-NLS-1$ static final String PROPERTY_PROXYHOST = "network.proxy_host"; //$NON-NLS-1$ @@ -1748,10 +1749,23 @@ int /*long*/ webkit_resource_request_starting (int /*long*/ web_view, int /*long WebKitGTK.soup_message_body_flatten (body); if (headers == null) headers = new String[0]; - String[] temp = new String[headers.length + 1]; - System.arraycopy (headers, 0, temp, 0, headers.length); - temp[headers.length] = ENCODING_FORM; - headers = temp; + boolean found = false; + for (int i = 0; i < headers.length; i++) { + int index = headers[i].indexOf (':'); + if (index != -1) { + String name = headers[i].substring (0, index).trim ().toLowerCase (); + if (name.equals (HEADER_CONTENTTYPE)) { + found = true; + break; + } + } + } + if (!found) { + String[] temp = new String[headers.length + 1]; + System.arraycopy (headers, 0, temp, 0, headers.length); + temp[headers.length] = HEADER_CONTENTTYPE + ':' + MIMETYPE_FORMURLENCODED; + headers = temp; + } postData = null; } |