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

quering an invalid inventoryID with paging=true causes a redirect loop #111

Closed
DavidvtWout opened this issue Nov 10, 2021 · 2 comments
Closed

Comments

@DavidvtWout
Copy link
Contributor

Querying /api/tree/<spec>/<invalid inventoryID>?paging=true causes a HTTP 303 response which redirects to the same url.

Proposed fix:
Add && searchRequest.Tree.Page[0] != 1 to hub3/hub3/server/http/handlers/search.go line 419
This way the redirect does not happen if the page already is page 1.

@DavidvtWout
Copy link
Contributor Author

Also check if searchRequest.Tree.Page is empty to prevent panic

@kiivihal
Copy link
Member

I think the workflow is dependent on a query being present in the query params. If we search for something on a specific inventoryID and we get 0 results it should show the first page.

If we get zero results because the inventoryID is invalid then we should not have a 'q' in the query params. If we do, we terminate with a 404.

A solution could be:

		if paging.HitsTotalCount == 0 && searchRequest.Tree.IsSearch && searchRequest.Tree.IsPaging {
			// if there is no query in the params then this is already a redirect
			if !r.URL.Query().Has("q") {
				http.Error(w, fmt.Sprintf("inventoryID '%s' not found", searchRequest.Tree.UnitID), http.StatusNotFound)
				return
			}
			newPath := fmt.Sprintf("%s?paging=true&page=1", r.URL.Path)
			http.Redirect(w, r, newPath, http.StatusSeeOther)
			return
		}

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

No branches or pull requests

2 participants