├── .env ├── .eslintignore ├── .gitignore ├── LICENCE.md ├── README.md ├── auto-imports.d.ts ├── babel.config.js ├── components.d.ts ├── jsconfig.json ├── package-lock.json ├── package.json ├── public ├── favicon.ico └── index.html ├── src ├── App.vue ├── assets │ ├── iconfont │ │ ├── iconfont.css │ │ └── iconfont.js │ └── logo.png ├── components │ ├── CurlDomainConfig.vue │ ├── CurlLocalRequest │ │ ├── CurlLocalRequest.vue │ │ ├── request │ │ │ ├── Request.vue │ │ │ ├── RequestBody.vue │ │ │ ├── RequestHeaders.vue │ │ │ ├── UlrArgs.vue │ │ │ └── UrlSend.vue │ │ └── response │ │ │ ├── Header.vue │ │ │ ├── Response.vue │ │ │ ├── ResponseBody.vue │ │ │ ├── ResponseBodyTip.vue │ │ │ └── ResponsePreview.vue │ └── ace │ │ ├── AceEditor.vue │ │ └── AceEditorOption.vue └── main.js ├── store └── index.js ├── utools ├── logo.png ├── plugin.json └── preload.js └── vue.config.js /.env: -------------------------------------------------------------------------------- 1 | VUE_APP_TITLE=My App 2 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | /src/assets/iconfont/iconfont.js 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | 6 | # local env files 7 | .env.local 8 | .env.*.local 9 | 10 | # Log files 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | pnpm-debug.log* 15 | 16 | # Editor directories and files 17 | .idea 18 | .vscode 19 | *.suo 20 | *.ntvs* 21 | *.njsproj 22 | *.sln 23 | *.sw? 24 | -------------------------------------------------------------------------------- /LICENCE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # utools-curl 2 | 3 | ## 一、插件介绍 4 | 5 | > 该插件是一款可以根据curl命令快速发起请求,并提供可视化界面进行参数更改、返回结果查看。 6 | 7 | ## 二、使用场景介绍 8 | 9 | > 在日常开发中,经常需要复制测试环境的curl在本地进行调试: 10 | 11 | #### 1. 传统方式需要五步 12 | 13 | 1. copy浏览器中的curl命令 14 | 2. 打开文本编辑器 15 | 3. 手动进行替换域名 16 | 4. 复制新curl命令 17 | 5. 命令行执行 18 | 19 | #### 2. 使用该插件现在只需两步 20 | 21 | 1. copy浏览器中的curl命令 22 | 2. 呼出utools,回车即可 23 | 24 | ## 三、插件使用说明 25 | 26 | 1. F12打开浏览器调试工具 > Network > 选中某条请求右键 > 27 | copy > copy as curl (bash) > 这样就得到了一条curl命令 28 | 2. alt+space > 呼出utools 29 | 3. 回车进入插件即可 30 | 31 | ## 四、插件效果图预览 32 | 33 | [点击查看大图](https://raw.githubusercontent.com/fffguo/picture-warehouse/main/github/utools-curl-preview.gif) 34 | 35 | ![效果预览](https://raw.githubusercontent.com/fffguo/picture-warehouse/main/github/utools-curl-preview.gif) 36 | 37 | ## Project setup 38 | 39 | ``` 40 | npm install 41 | ``` 42 | 43 | ### Compiles and hot-reloads for development 44 | 45 | ``` 46 | npm run serve 47 | ``` 48 | 49 | ### Compiles and minifies for production 50 | 51 | ``` 52 | npm run build 53 | ``` 54 | 55 | ### Lints and fixes files 56 | 57 | ``` 58 | npm run lint 59 | ``` 60 | 61 | ### Customize configuration 62 | 63 | See [Configuration Reference](https://cli.vuejs.org/config/). 64 | 65 | 66 | ## JetBrains OS licenses 67 | ``utools-curl`` had been being developed with `WebStorm` IDE under the **free JetBrains Open Source license(s)** granted by JetBrains s.r.o., hence I would like to express my thanks here. 68 | 69 | 70 | -------------------------------------------------------------------------------- /auto-imports.d.ts: -------------------------------------------------------------------------------- 1 | // Generated by 'unplugin-auto-import' 2 | // We suggest you to commit this file into source control 3 | declare global { 4 | const ElButton: typeof import('element-plus/es')['ElButton'] 5 | const ElCard: typeof import('element-plus/es')['ElCard'] 6 | const ElDescriptions: typeof import('element-plus/es')['ElDescriptions'] 7 | const ElDescriptionsItem: typeof import('element-plus/es')['ElDescriptionsItem'] 8 | const ElInput: typeof import('element-plus/es')['ElInput'] 9 | const ElOption: typeof import('element-plus/es')['ElOption'] 10 | const ElSelect: typeof import('element-plus/es')['ElSelect'] 11 | const ElTabPane: typeof import('element-plus/es')['ElTabPane'] 12 | const ElTabs: typeof import('element-plus/es')['ElTabs'] 13 | } 14 | export {} 15 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /components.d.ts: -------------------------------------------------------------------------------- 1 | // generated by unplugin-vue-components 2 | // We suggest you to commit this file into source control 3 | // Read more: https://github.com/vuejs/vue-next/pull/3399 4 | 5 | declare module 'vue' { 6 | export interface GlobalComponents { 7 | AceEditor: typeof import('./src/components/ace/AceEditor.vue')['default'] 8 | AceEditorOption: typeof import('./src/components/ace/AceEditorOption.vue')['default'] 9 | CurlDomainConfig: typeof import('./src/components/CurlDomainConfig.vue')['default'] 10 | CurlLocalRequest: typeof import('./src/components/CurlLocalRequest/CurlLocalRequest.vue')['default'] 11 | ElButton: typeof import('element-plus/es')['ElButton'] 12 | ElCard: typeof import('element-plus/es')['ElCard'] 13 | ElDescriptions: typeof import('element-plus/es')['ElDescriptions'] 14 | ElDescriptionsItem: typeof import('element-plus/es')['ElDescriptionsItem'] 15 | ElInput: typeof import('element-plus/es')['ElInput'] 16 | ElOption: typeof import('element-plus/es')['ElOption'] 17 | ElSelect: typeof import('element-plus/es')['ElSelect'] 18 | ElTabPane: typeof import('element-plus/es')['ElTabPane'] 19 | ElTabs: typeof import('element-plus/es')['ElTabs'] 20 | Header: typeof import('./src/components/CurlLocalRequest/response/Header.vue')['default'] 21 | Response: typeof import('./src/components/CurlLocalRequest/response/Response.vue')['default'] 22 | ResponseBody: typeof import('./src/components/CurlLocalRequest/response/ResponseBody.vue')['default'] 23 | ResponseBodyTip: typeof import('./src/components/CurlLocalRequest/response/ResponseBodyTip.vue')['default'] 24 | } 25 | } 26 | 27 | export { } 28 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "esnext", 5 | "baseUrl": "./", 6 | "moduleResolution": "node", 7 | "paths": { 8 | "@/*": [ 9 | "src/*" 10 | ] 11 | }, 12 | "lib": [ 13 | "esnext", 14 | "dom", 15 | "dom.iterable", 16 | "scripthost" 17 | ] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "utools-curl", 3 | "version": "1.9.2", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve --port 9090", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "ace": "^1.3.0", 12 | "core-js": "^3.8.3", 13 | "curl-string": "git+https://github.com/zvakanaka/curl-string.git", 14 | "element-plus": "^2.1.10", 15 | "parse-curl": "git+https://github.com/fffguo/parse-curl.js.git", 16 | "pretty-data": "^0.40.0", 17 | "vue": "^3.2.13", 18 | "vuex": "^4.0.2" 19 | }, 20 | "devDependencies": { 21 | "@babel/core": "^7.12.16", 22 | "@babel/eslint-parser": "^7.12.16", 23 | "@vue/cli-plugin-babel": "^5.0.4", 24 | "@vue/cli-plugin-eslint": "^5.0.4", 25 | "@vue/cli-service": "^5.0.4", 26 | "ace-builds": "^1.4.14", 27 | "copy-webpack-plugin": "^11.0.0", 28 | "eslint": "^7.32.0", 29 | "eslint-plugin-vue": "^8.0.3", 30 | "unplugin-element-plus": "^0.4.0", 31 | "utools-api-types": "^2.6.0" 32 | }, 33 | "eslintConfig": { 34 | "root": true, 35 | "env": { 36 | "node": true 37 | }, 38 | "extends": [ 39 | "plugin:vue/essential", 40 | "eslint:recommended" 41 | ], 42 | "parserOptions": { 43 | "parser": "@babel/eslint-parser" 44 | }, 45 | "rules": {} 46 | }, 47 | "browserslist": [ 48 | "> 1%", 49 | "last 2 versions", 50 | "not dead", 51 | "not ie 11" 52 | ] 53 | } 54 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fffguo/utools-curl/ccf7f8417ac229a1dde400b438e72be8f765a67b/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 15 |
16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 18 | 19 | 33 | -------------------------------------------------------------------------------- /src/assets/iconfont/iconfont.css: -------------------------------------------------------------------------------- 1 | .icon { 2 | width: 1em; 3 | height: 1em; 4 | vertical-align: -0.15em; 5 | fill: currentColor; 6 | overflow: hidden; 7 | } 8 | -------------------------------------------------------------------------------- /src/assets/iconfont/iconfont.js: -------------------------------------------------------------------------------- 1 | !function(t){var a,e,c,h,o,n='',i=(i=document.getElementsByTagName("script"))[i.length-1].getAttribute("data-injectcss"),l=function(t,a){a.parentNode.insertBefore(t,a)};if(i&&!t.__iconfont__svg__cssinject__){t.__iconfont__svg__cssinject__=!0;try{document.write("")}catch(t){console&&console.log(t)}}function d(){o||(o=!0,c())}function s(){try{h.documentElement.doScroll("left")}catch(t){return void setTimeout(s,50)}d()}a=function(){var t,a=document.createElement("div");a.innerHTML=n,n=null,(a=a.getElementsByTagName("svg")[0])&&(a.setAttribute("aria-hidden","true"),a.style.position="absolute",a.style.width=0,a.style.height=0,a.style.overflow="hidden",a=a,(t=document.body).firstChild?l(a,t.firstChild):t.appendChild(a))},document.addEventListener?~["complete","loaded","interactive"].indexOf(document.readyState)?setTimeout(a,0):(e=function(){document.removeEventListener("DOMContentLoaded",e,!1),a()},document.addEventListener("DOMContentLoaded",e,!1)):document.attachEvent&&(c=a,h=t.document,o=!1,s(),h.onreadystatechange=function(){"complete"==h.readyState&&(h.onreadystatechange=null,d())})}(window); -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fffguo/utools-curl/ccf7f8417ac229a1dde400b438e72be8f765a67b/src/assets/logo.png -------------------------------------------------------------------------------- /src/components/CurlDomainConfig.vue: -------------------------------------------------------------------------------- 1 | 53 | 198 | 199 | 210 | -------------------------------------------------------------------------------- /src/components/CurlLocalRequest/CurlLocalRequest.vue: -------------------------------------------------------------------------------- 1 | 10 | 66 | 67 | 99 | -------------------------------------------------------------------------------- /src/components/CurlLocalRequest/request/Request.vue: -------------------------------------------------------------------------------- 1 | 22 | 23 | 58 | 59 | 62 | -------------------------------------------------------------------------------- /src/components/CurlLocalRequest/request/RequestBody.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 20 | 21 | 24 | -------------------------------------------------------------------------------- /src/components/CurlLocalRequest/request/RequestHeaders.vue: -------------------------------------------------------------------------------- 1 | 30 | 31 | 111 | 112 | 115 | -------------------------------------------------------------------------------- /src/components/CurlLocalRequest/request/UlrArgs.vue: -------------------------------------------------------------------------------- 1 | 32 | 33 | 233 | 234 | 237 | -------------------------------------------------------------------------------- /src/components/CurlLocalRequest/request/UrlSend.vue: -------------------------------------------------------------------------------- 1 | 67 | 68 | 298 | 299 | 343 | -------------------------------------------------------------------------------- /src/components/CurlLocalRequest/response/Header.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 22 | 23 | 26 | -------------------------------------------------------------------------------- /src/components/CurlLocalRequest/response/Response.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 42 | 43 | 46 | -------------------------------------------------------------------------------- /src/components/CurlLocalRequest/response/ResponseBody.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 24 | 25 | 28 | -------------------------------------------------------------------------------- /src/components/CurlLocalRequest/response/ResponseBodyTip.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 49 | 50 | 68 | -------------------------------------------------------------------------------- /src/components/CurlLocalRequest/response/ResponsePreview.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 38 | 39 | -------------------------------------------------------------------------------- /src/components/ace/AceEditor.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 79 | 80 | 81 | 87 | z 88 | -------------------------------------------------------------------------------- /src/components/ace/AceEditorOption.vue: -------------------------------------------------------------------------------- 1 | 43 | 44 | 136 | 137 | 160 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import {createApp} from 'vue' 2 | import App from './App.vue' 3 | //elementPlus 4 | import ElementPlus from 'element-plus' 5 | import 'element-plus/dist/index.css' 6 | //ace编辑器 7 | import Ace from 'ace-builds' 8 | //vuex 9 | import store from './../store/index' 10 | // iconfont 11 | import * as IconFont from './assets/iconfont/iconfont' 12 | import './assets/iconfont/iconfont.css' 13 | 14 | const app = createApp(App) 15 | 16 | app.use(ElementPlus) 17 | .use(IconFont) 18 | .use(Ace) 19 | .use(store) 20 | .mount('#app') 21 | -------------------------------------------------------------------------------- /store/index.js: -------------------------------------------------------------------------------- 1 | import {createStore} from 'vuex' 2 | import {pd} from "pretty-data"; 3 | import {ElMessage} from "element-plus"; 4 | 5 | function parseBody(body) { 6 | let result = { 7 | body: body, 8 | mode: "ace/mode/json5", 9 | contentType: "JSON" 10 | } 11 | if (body === undefined || body === "") { 12 | return result; 13 | } 14 | try { 15 | result.body = pd.json(body) 16 | result.mode = "ace/mode/json5" 17 | result.contentType = "JSON" 18 | } catch (e) { 19 | try { 20 | result.body = pd.xml(body) 21 | result.mode = "ace/mode/xml" 22 | result.contentType = "XML" 23 | } catch (e) { 24 | result.body = body 25 | result.mode = "ace/mode/text" 26 | result.contentType = "TEXT" 27 | } 28 | } 29 | return result 30 | } 31 | 32 | export default createStore({ 33 | state: { 34 | //curl参数 35 | curl: { 36 | curlText: "", 37 | request: { 38 | url: "", 39 | initUrl: "",//原始url 40 | method: "GET", 41 | headers: [], 42 | body: "" 43 | }, 44 | response: { 45 | httpStatus: "未知", 46 | consumeTime: -1, 47 | headers: [], 48 | body: "", 49 | } 50 | }, 51 | //ace编辑器 52 | ace: { 53 | supportedLanguage: { 54 | json: "ace/mode/json5", 55 | xml: "ace/mode/xml", 56 | text: "ace/mode/text", 57 | }, 58 | responseBodyEditor: undefined, 59 | requestBodyEditor: undefined, 60 | requestBodyContentType: "JSON", 61 | responseBodyContentType: "JSON", 62 | requestBodyMode: "ace/mode/json5", 63 | }, 64 | //request dom节点 65 | dom: { 66 | loading: false, 67 | request: { 68 | startInit: false, 69 | activeTabName: "requestBody", 70 | requestHeaderTableRef: [], 71 | urlArgsTableRef: [], 72 | syncWithUrlToArgs: false, 73 | }, 74 | response: { 75 | show: false, 76 | activeTabName: "responseResult" 77 | } 78 | } 79 | }, 80 | mutations: { 81 | setCurlText(state, text) { 82 | state.curl.curlText = text 83 | }, 84 | setCurlRequest(state, curl) { 85 | if (curl === undefined) { 86 | return 87 | } 88 | state.curl.request.url = curl.url; 89 | state.curl.request.initUrl = curl.url 90 | state.curl.request.headers = curl.header 91 | state.curl.request.method = curl.method 92 | state.curl.request.body = curl.body 93 | let result = parseBody(curl.body) 94 | state.ace.requestBodyEditor.setValue(result.body, 1) 95 | state.ace.requestBodyEditor.getSession().setMode(result.mode) 96 | state.ace.requestBodyContentType = result.contentType 97 | state.ace.requestBodyMode = result.mode 98 | }, 99 | revertResponseTabActive(state) { 100 | state.dom.response.activeTabName = "responseResult" 101 | }, 102 | revertRequestTabActive(state) { 103 | state.dom.request.activeTabName = "requestBody"; 104 | }, 105 | showResponseTab(state) { 106 | state.dom.response.show = true 107 | }, 108 | initByCurlText(state, curl) { 109 | //构建request 110 | this.commit('setCurlRequest', curl) 111 | //初始化request 112 | state.dom.request.startInit = true 113 | 114 | //重设requestTab 115 | this.commit('revertRequestTabActive') 116 | //重设responseTab 117 | this.commit('revertResponseTabActive') 118 | //显示tab 119 | this.commit('showResponseTab') 120 | }, 121 | //发送请求 122 | sendRequest(state, curlArgs) { 123 | state.dom.loading = true 124 | 125 | //请求失败回调 126 | let errorCallback = function (_error) { 127 | ElMessage.error({ 128 | message: '请求失败', 129 | duration: 500, 130 | }) 131 | state.dom.loading = false 132 | state.curl.response.httpStatus = 500 133 | state.curl.response.consumeTime = -1 134 | state.curl.response.body = _error.toString() 135 | state.ace.responseBodyEditor.setValue(_error.toString(), 1) 136 | state.ace.responseBodyEditor.getSession().setMode("ace/mode/text") 137 | }; 138 | 139 | let startMs = new Date().valueOf() 140 | window.sendRequest(curlArgs, function (response) { 141 | state.curl.response.httpStatus = response.statusCode 142 | state.curl.response.headers = response.headers 143 | //请求结束 144 | let body = "" 145 | response.on('end', () => { 146 | state.curl.response.consumeTime = new Date().valueOf() - startMs 147 | state.dom.loading = false 148 | state.curl.response.body = body 149 | let result = parseBody(body) 150 | state.ace.responseBodyEditor.setValue(result.body, 1) 151 | state.ace.responseBodyEditor.getSession().setMode(result.mode) 152 | state.ace.responseBodyContentType = result.contentType 153 | }) 154 | //返回体,body过大会多次回调 155 | response.on('data', (data) => { 156 | body += data.toString(); 157 | }) 158 | //失败 159 | response.on('error', errorCallback) 160 | }, errorCallback) 161 | // 挂载 162 | window.curlVuex = state 163 | }, 164 | 165 | //取消发送请求 166 | cancelRequest(state) { 167 | state.dom.loading = false 168 | this.commit('revertResponseTabActive') 169 | this.commit('showResponseTab') 170 | state.ace.responseBodyEditor.setValue("", 1) 171 | state.ace.responseBodyEditor.getSession().setMode("ace/mode/json5") 172 | } 173 | 174 | }, 175 | actions: {}, 176 | getters: { 177 | //实时获取headers 178 | getRealTimeHeaders(state) { 179 | let headers = {} 180 | state.dom.request.requestHeaderTableRef.getSelectionRows() 181 | .filter(header => header !== undefined && header.key !== undefined && header.key !== "" && header.value !== undefined) 182 | .forEach(header => headers[header.key] = header.value); 183 | return headers; 184 | }, 185 | //实时获取body 186 | getRealTimeBody(state) { 187 | let body = state.ace.requestBodyEditor.getValue(); 188 | if (state.ace.requestBodyMode === state.ace.supportedLanguage.json) { 189 | if (body !== undefined && body !== "") { 190 | try { 191 | body = JSON.stringify(JSON.parse(body)); 192 | } catch (e) { 193 | return body; 194 | } 195 | } 196 | } 197 | return body 198 | } 199 | }, 200 | modules: {} 201 | }) 202 | -------------------------------------------------------------------------------- /utools/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fffguo/utools-curl/ccf7f8417ac229a1dde400b438e72be8f765a67b/utools/logo.png -------------------------------------------------------------------------------- /utools/plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "http://127.0.0.1:9090", 3 | "preload": "preload.js", 4 | "logo": "logo.png", 5 | "features": [ 6 | { 7 | "code": "curl_local_request", 8 | "explain": "快速替换本地域名并请求,方便debug解决问题", 9 | "cmds": [ 10 | { 11 | "type": "regex", 12 | "match": "/^(https?:\/\/|curl)/i", 13 | "label": "curl", 14 | "maxLength": 10000 15 | } 16 | ] 17 | }, 18 | { 19 | "code": "curl", 20 | "explain": "快速替换本地域名并请求,方便debug解决问题", 21 | "cmds": [ 22 | "curl" 23 | ] 24 | } 25 | ], 26 | "pluginSetting": { 27 | "single": true 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /utools/preload.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | const https = require('https'); 3 | require('url'); 4 | /* 5 | args 示例结构 6 | { 7 | "url": "/ci/releases?projectId=1497&page=0&pageSize=10&version=&user=&tag=", 8 | "method": "get", 9 | "headers":{ 10 | "Cookie": "SESSION=0b75cc03-d4be-4576-bd77-dd03fb46a0e4" 11 | } 12 | } 13 | callback参考:http://nodejs.cn/learn/the-nodejs-http-module#httpincomingmessage http.IncomingMessage 14 | */ 15 | // eslint-disable-next-line no-undef 16 | sendRequest = function (curl, callback, errorCallback) { 17 | try { 18 | console.log("原始请求curl:", curl); 19 | const myURL = new URL(curl.url); 20 | handleHeader(curl.headers, curl.body); 21 | const options = { 22 | hostname: myURL.hostname, 23 | port: myURL.port === "" ? (curl.url.startsWith('https') ? 443 : 80) : myURL.port, 24 | path: myURL.pathname + myURL.search, 25 | method: curl.method, 26 | headers: curl.headers, 27 | }; 28 | let request; 29 | if (curl.url.startsWith('https')) { 30 | request = https.request(options, callback); 31 | } else { 32 | request = http.request(options, callback); 33 | } 34 | if (curl.body !== undefined) { 35 | request.write(curl.body); 36 | } 37 | console.log("请求参数options:", options); 38 | console.log("body:", curl.body); 39 | request.on('error', errorCallback); 40 | request.end(); 41 | } catch (e) { 42 | console.log("sendRequest error:", e); 43 | errorCallback(e) 44 | } 45 | } 46 | 47 | let handleHeader = function (headers, body) { 48 | if (body) { 49 | headers['content-length'] = Buffer.byteLength(body) 50 | } 51 | }; 52 | 53 | // eslint-disable-next-line no-undef 54 | newURL = function (url) { 55 | return new URL(url); 56 | }; 57 | 58 | -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | const {defineConfig} = require('@vue/cli-service') 2 | 3 | const CopyWebpackPlugin = require("copy-webpack-plugin") 4 | module.exports = defineConfig({ 5 | transpileDependencies: true, 6 | outputDir: "./dist", //打包目录 7 | productionSourceMap: process.env.NODE_ENV === 'development', //排除.js.map 8 | 9 | configureWebpack: { 10 | plugins: [ 11 | require('unplugin-element-plus/webpack')({ 12 | // options 13 | }), 14 | new CopyWebpackPlugin({ 15 | patterns: [ 16 | { 17 | from: './utools/', 18 | to: './', 19 | //处理传输内容 20 | transform(content, absoluteFrom) { 21 | //plugin.json 替换属性 22 | if (absoluteFrom.endsWith("/plugin.json")) { 23 | let jsonContent = JSON.parse(content.toString()); 24 | //替换 25 | let result = JSON.stringify(jsonContent, function (key, value) { 26 | if (key === 'main') { 27 | value = 'index.html'; 28 | } 29 | return value; 30 | }); 31 | return Buffer.from(result); 32 | } 33 | return content; 34 | }, 35 | } 36 | ] 37 | }) 38 | ], 39 | }, 40 | publicPath: './', 41 | }) 42 | --------------------------------------------------------------------------------