Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate url #1186

Merged
merged 7 commits into from Oct 2, 2018
Merged

Validate url #1186

merged 7 commits into from Oct 2, 2018

Conversation

karthik-durai
Copy link
Contributor

@karthik-durai karthik-durai commented Sep 30, 2018

Closes #1050

Used NodeJs's URL module, the module provides a class that is implemented by following WHATWG's URL Standard (Link to the documentation)

When a string is passed as an argument to the constructor, if the stirng is a valid URL, it returns an object, that contains parsed URL (see example below). If the given string is not a valid URL string, then it throws an error stating the given string is an invalid URL.

Example for the value returned by WHATWG's URL API:

URL {
  href: 'http://www.example.com/',
  origin: 'http://www.example.com',
  protocol: 'http:',
  username: '',
  password: '',
  host: 'www.example.com',
  hostname: 'www.example.com',
  port: '',
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: '' }

Implementation details of making valid URL clickable in the response header

  • Implemented a function in the name of validateURL and placed into Response-Header-viewer module.
  • When the response header arrives, the value of each header property is passed to the validateURL function.
  • If the function returns true, then the value is wrapped with Link component, the component render the value as clickable link and make the webpage render in the default browser.
  • If the function returns false, then the value is rendered as it is.

Implementation details of the validateURL module

  • The module uses NodeJS's URL module, the URL module provide a class which is implemented by WHATWG's URL standard.
  • The module has one function, which takes a string, the string is then passed to URL constructor, if it throws an error, then the function returns false.
  • If URL constructor returns an object, then the function checks if the hostname property is a non-empty string, if it is an empty string, it returns false else it returns true.

Copy link
Contributor

@gschier gschier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small comment 😄

@@ -0,0 +1,13 @@
const { URL } = require('url');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function isn't doing very much and is not used anywhere else, I recommend just adding it as a method on the ResponseHeadersViewer component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will work it and update you ASAP.

@karthik-durai
Copy link
Contributor Author

Hey Greg,
Removed the validateURL module from the insomnia-url package. Placed the function inside the response-header-viewer module. Checked by running the app, it worked fine.

Copy link
Contributor

@gschier gschier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@gschier gschier merged commit 6f7a6d8 into Kong:develop Oct 2, 2018
@welcome
Copy link

welcome bot commented Oct 2, 2018

Congrats on merging your first pull request! 🎉🎉🎉 You're helping make Insomnia awesome! 🙌

luizmariz pushed a commit to luizmariz/insomnia that referenced this pull request Jan 22, 2020
* place validateURL module in insomnia-url package

* import validataeURL module and add it to the exports

* import validateURL and pass h.value to the function, if its a url, wrap with the link component or just leave as it is

* remove validateURL module from insomnia-url package

* delete import statment that imports validateURL module

* place validateURL function inside reponse-header-viewer

* require URL api from url module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants