commonfields:
  id: HTTPListRedirects
  version: -1
name: HTTPListRedirects
script: |-
  import requests

  response = requests.head(demisto.args()['url'], allow_redirects=True) if demisto.args()['useHead'] == 'true' else requests.get(demisto.args()['url'])
  urls = []
  if response.history:
      for resp in response.history:
          urls.append({'Data': resp.url, 'Status': resp.status_code})
  urls.append({'Data': response.url, 'Status': response.status_code})
  ec = {'URL(val.Data == obj.Data)': [{'Data': u['Data']} for u in urls]}

  demisto.results({'ContentsFormat': formats['json'], 'Type': entryTypes['note'], 'Contents': urls, 'ReadableContentsFormat': formats['markdown'],
      'HumanReadable': tableToMarkdown('URLs', urls, ['Data', 'Status']), 'EntryContext': ec})
type: python
tags:
- Utility
comment: List the redirects for a given URL
enabled: true
args:
- name: url
  required: true
  default: true
  description: The URL to follow
- name: useHead
  auto: PREDEFINED
  predefined:
  - "true"
  - "false"
  defaultValue: "true"
  description: Should we use HEAD instead of GET. Safer but might not be the same
    response.
outputs:
- contextPath: URL.Data
  description: The URL redirects from the given URL
scripttarget: 0

commonfields:
  id: HTTPListRedirects
  version: -1
name: HTTPListRedirects
script: |-
  import requests

  u = demisto.args()['url']
  if not u.lower().startswith('http'):
      u = 'http://' + u
  response = requests.head(u, allow_redirects=True) if demisto.args()['useHead'] == 'true' else requests.get(u)
  urls = []
  if response.history:
      for resp in response.history:
          urls.append({'Data': resp.url, 'Status': resp.status_code})
  urls.append({'Data': response.url, 'Status': response.status_code})
  ec = {'URL(val.Data == obj.Data)': [{'Data': u['Data']} for u in urls]}

  demisto.results({'ContentsFormat': formats['json'], 'Type': entryTypes['note'], 'Contents': urls, 'ReadableContentsFormat': formats['markdown'],
      'HumanReadable': tableToMarkdown('URLs', urls, ['Data', 'Status']), 'EntryContext': ec})
type: python
tags:
- Utility
comment: List the redirects for a given URL
enabled: true
args:
- name: url
  required: true
  default: true
  description: The URL to follow
- name: useHead
  auto: PREDEFINED
  predefined:
  - "true"
  - "false"
  defaultValue: "true"
  description: Should we use HEAD instead of GET. Safer but might not be the same
    response.
outputs:
- contextPath: URL.Data
  description: The URL redirects from the given URL
scripttarget: 0
releaseNotes: Make sure we have an http prefix for URLs

Make sure we have http prefix for URLs
Make sure we have http prefix for URLs
