Curl Rewrite#41
Conversation
…ersion increment.
…nversion to arg parsing. Proxy settings. Function re-ordering. Simplified http_request args.
…d. Suppress SSL warning for localhost.
…st. Added result header_response. Header input case insensitive.
Working from my phone, pressed the wrong button, still reviewing.
|
Any updates on getting this in? |
|
Please correct the uri vs url change: diff shows the code body wasn’t fully updated in places (e.g., if not isinstance(uri, str)). |
| # Set the authentication header for the Splunk session key | ||
| sessionKey = settings.get('sessionKey') | ||
| if sessionKey: | ||
| headers = headers.update(build_auth_headers(sessionKey=sessionKey)) |
There was a problem hiding this comment.
dict.update() mutates in place and returns None, so headers becomes None.
Should be:
headers.update(build_auth_headers(sessionKey=sessionKey))
There was a problem hiding this comment.
Indeed, not sure if/how this worked.
| payload_field = 'params' | ||
| elif payload is not None: | ||
| payload_field = 'data' | ||
|
|
There was a problem hiding this comment.
Probably need a payload_field = None upfront
There was a problem hiding this comment.
Good call - would cover get/head with payload set to None.
|
|
||
| sleepCounter = 0 | ||
| sleep: Optional[float] = float(options['sleep']) if 'sleep' in options else None # type: ignore[reportArgumentType] | ||
| clean_result: Optional[bool] = bool(options.get('clean', False)) |
There was a problem hiding this comment.
The type annotation says Optional[bool] but bool(...) always returns a bool, never None.
Minor, but misleading.
| try: | ||
| proxy_user, proxy_pass = str(proxy_auth).split(':') | ||
| if 'http' in proxies and isinstance(proxies['http'], str): | ||
| proxies['http'] = proxies['http'].replace('://', f'://{proxy_user}:{proxy_pass}@') |
There was a problem hiding this comment.
Could leak in logs or tracebacks. The requests library supports ab auth parameter on the Session object for proxy auth which is safer.
| # Remove multiple newlines | ||
| clean_html = re.sub(r'(?<=\n)[\r\n]*', '', clean_html) | ||
| # Remove extra whitespace | ||
| clean_html = re.sub(r'([\t ])\1+', '\1', clean_html) |
There was a problem hiding this comment.
'\1' in a plain string is a literal backslash-1, not a backreference. Should be r'\1' i think? double check please.
There was a problem hiding this comment.
This cleans up either extra tabs or extra spaces and replaces it with the first one. The \1 is a backreference in both cases.
Pull Request Type
Rewrite/refactor/bugfixes
Release Notes
cleanto clean HTML output.methodfieldto use the HTTP method defined in the events.dryrunto run the code without sending the HTTP request.curl_headers_response,curl_redirect.