mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 18:57:05 +08:00
feat: harden curl_parser, tolerate flags, improve output, and expand tests
- Pre-filter unknown flags before ArgParser; keep positional args. - Tolerate non-request flags: -v/--verbose, --connect-timeout, --retry, --output, --compressed, -i/--include, --globoff. - Auth: support --oauth2-bearer; map to - Authorization only if absent. - Cookies: parse -b/--cookie; accept -c/--cookie-jar (ignored for request). - URL: prefer first http(s) positional when --url missing; quote cleaning. - Data: merge data-urlencode → data-raw → data-binary → data; default POST when body/form present; HEAD remains HEAD. - Forms: parse -F entries; auto-set multipart Content-Type if missing. - Headers: robust -H parsing for multi-colon values. - toCurlString: deterministic order; fix continuation spacing; emit -d right after headers/form; place -k/-L at end. - Utils: normalize backslash-newlines/CRLF; remove stray '+'; shlex split. - Tests: add unknown flags, oauth2-bearer (and non-override), cookie-jar, verbose/timeout/retry/output tolerance, data merging order, HEAD+data, -A user-agent, -b filename. - Docs: add Dartdoc for utils; class docs present.
This commit is contained in:
@@ -117,9 +117,46 @@ void main() {
|
||||
-F "token=123"''',
|
||||
);
|
||||
});
|
||||
|
||||
test('form defaults header when absent', () {
|
||||
final curl = Curl(
|
||||
method: 'POST',
|
||||
uri: Uri.parse('https://api.apidash.dev/io/img'),
|
||||
form: true,
|
||||
formData: [
|
||||
FormDataModel(
|
||||
name: 'file',
|
||||
value: '/tmp/a.png',
|
||||
type: FormDataType.file,
|
||||
),
|
||||
],
|
||||
);
|
||||
// parse back to ensure header gets defaulted in parser
|
||||
final parsed = Curl.parse(curl.toCurlString());
|
||||
expect(parsed.form, isTrue);
|
||||
expect(
|
||||
parsed.headers?[kHeaderContentType] ??
|
||||
parsed.headers?['content-type'],
|
||||
'multipart/form-data');
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
group('Roundtrip with body', () {
|
||||
test('toCurlString includes body when present', () {
|
||||
final curl = Curl(
|
||||
method: 'POST',
|
||||
uri: Uri.parse('https://api.apidash.dev/submit'),
|
||||
data: 'a=1&b=2',
|
||||
);
|
||||
final s = curl.toCurlString();
|
||||
final back = Curl.parse(s);
|
||||
expect(back.method, 'POST');
|
||||
expect(back.data, 'a=1&b=2');
|
||||
expect(back.uri, Uri.parse('https://api.apidash.dev/submit'));
|
||||
});
|
||||
});
|
||||
|
||||
group(
|
||||
'Special Parameters',
|
||||
() {
|
||||
|
||||
Reference in New Issue
Block a user