Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
a1088c7a
Commit
a1088c7a
authored
Jun 06, 2019
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include the port in the URLs of the API Link headers
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
9318fba9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
16 deletions
+25
-16
changelogs/unreleased/62847-url-for-the-next-request-with-pagination-is-missing-port.yml
...-for-the-next-request-with-pagination-is-missing-port.yml
+5
-0
lib/api/helpers/pagination.rb
lib/api/helpers/pagination.rb
+1
-1
spec/lib/api/helpers/pagination_spec.rb
spec/lib/api/helpers/pagination_spec.rb
+19
-15
No files found.
changelogs/unreleased/62847-url-for-the-next-request-with-pagination-is-missing-port.yml
0 → 100644
View file @
a1088c7a
---
title
:
Include the port in the URLs of the API Link headers
merge_request
:
29267
author
:
type
:
fixed
lib/api/helpers/pagination.rb
View file @
a1088c7a
...
...
@@ -23,7 +23,7 @@ module API
def
base_request_uri
@base_request_uri
||=
URI
.
parse
(
request
.
url
).
tap
do
|
uri
|
uri
.
host
=
Gitlab
.
config
.
gitlab
.
host
uri
.
port
=
nil
uri
.
port
=
Gitlab
.
config
.
gitlab
.
port
end
end
...
...
spec/lib/api/helpers/pagination_spec.rb
View file @
a1088c7a
...
...
@@ -2,8 +2,12 @@ require 'spec_helper'
describe
API
::
Helpers
::
Pagination
do
let
(
:resource
)
{
Project
.
all
}
let
(
:incoming_api_projects_url
)
{
"
#{
Gitlab
.
config
.
gitlab
.
url
}
:8080/api/v4/projects"
}
let
(
:canonical_api_projects_url
)
{
"
#{
Gitlab
.
config
.
gitlab
.
url
}
/api/v4/projects"
}
let
(
:custom_port
)
{
8080
}
let
(
:incoming_api_projects_url
)
{
"
#{
Gitlab
.
config
.
gitlab
.
url
}
:
#{
custom_port
}
/api/v4/projects"
}
before
do
stub_config_setting
(
port:
custom_port
)
end
subject
do
Class
.
new
.
include
(
described_class
).
new
...
...
@@ -48,7 +52,7 @@ describe API::Helpers::Pagination do
it
'adds appropriate headers'
do
expect_header
(
'X-Per-Page'
,
'2'
)
expect_header
(
'X-Next-Page'
,
"
#{
canonical
_api_projects_url
}
?
#{
query
.
merge
(
ks_prev_id:
projects
[
1
].
id
).
to_query
}
"
)
expect_header
(
'X-Next-Page'
,
"
#{
incoming
_api_projects_url
}
?
#{
query
.
merge
(
ks_prev_id:
projects
[
1
].
id
).
to_query
}
"
)
expect_header
(
'Link'
,
anything
)
do
|
_key
,
val
|
expect
(
val
).
to
include
(
'rel="next"'
)
...
...
@@ -71,7 +75,7 @@ describe API::Helpers::Pagination do
it
'adds appropriate headers'
do
expect_header
(
'X-Per-Page'
,
'2'
)
expect_header
(
'X-Next-Page'
,
"
#{
canonical
_api_projects_url
}
?
#{
query
.
merge
(
ks_prev_id:
projects
[
2
].
id
).
to_query
}
"
)
expect_header
(
'X-Next-Page'
,
"
#{
incoming
_api_projects_url
}
?
#{
query
.
merge
(
ks_prev_id:
projects
[
2
].
id
).
to_query
}
"
)
expect_header
(
'Link'
,
anything
)
do
|
_key
,
val
|
expect
(
val
).
to
include
(
'rel="next"'
)
...
...
@@ -171,7 +175,7 @@ describe API::Helpers::Pagination do
it
'returns the right link to the next page'
do
expect_header
(
'X-Per-Page'
,
'2'
)
expect_header
(
'X-Next-Page'
,
"
#{
canonical
_api_projects_url
}
?
#{
query
.
merge
(
ks_prev_id:
projects
[
6
].
id
,
ks_prev_name:
projects
[
6
].
name
).
to_query
}
"
)
expect_header
(
'X-Next-Page'
,
"
#{
incoming
_api_projects_url
}
?
#{
query
.
merge
(
ks_prev_id:
projects
[
6
].
id
,
ks_prev_name:
projects
[
6
].
name
).
to_query
}
"
)
expect_header
(
'Link'
,
anything
)
do
|
_key
,
val
|
expect
(
val
).
to
include
(
'rel="next"'
)
end
...
...
@@ -224,9 +228,9 @@ describe API::Helpers::Pagination do
expect_header
(
'X-Prev-Page'
,
''
)
expect_header
(
'Link'
,
anything
)
do
|
_key
,
val
|
expect
(
val
).
to
include
(
%Q(<
#{
canonical
_api_projects_url
}
?
#{
query
.
merge
(
page:
1
).
to_query
}
>; rel="first")
)
expect
(
val
).
to
include
(
%Q(<
#{
canonical
_api_projects_url
}
?
#{
query
.
merge
(
page:
2
).
to_query
}
>; rel="last")
)
expect
(
val
).
to
include
(
%Q(<
#{
canonical
_api_projects_url
}
?
#{
query
.
merge
(
page:
2
).
to_query
}
>; rel="next")
)
expect
(
val
).
to
include
(
%Q(<
#{
incoming
_api_projects_url
}
?
#{
query
.
merge
(
page:
1
).
to_query
}
>; rel="first")
)
expect
(
val
).
to
include
(
%Q(<
#{
incoming
_api_projects_url
}
?
#{
query
.
merge
(
page:
2
).
to_query
}
>; rel="last")
)
expect
(
val
).
to
include
(
%Q(<
#{
incoming
_api_projects_url
}
?
#{
query
.
merge
(
page:
2
).
to_query
}
>; rel="next")
)
expect
(
val
).
not_to
include
(
'rel="prev"'
)
end
...
...
@@ -290,8 +294,8 @@ describe API::Helpers::Pagination do
expect_header
(
'X-Prev-Page'
,
''
)
expect_header
(
'Link'
,
anything
)
do
|
_key
,
val
|
expect
(
val
).
to
include
(
%Q(<
#{
canonical
_api_projects_url
}
?
#{
query
.
merge
(
page:
1
).
to_query
}
>; rel="first")
)
expect
(
val
).
to
include
(
%Q(<
#{
canonical
_api_projects_url
}
?
#{
query
.
merge
(
page:
2
).
to_query
}
>; rel="next")
)
expect
(
val
).
to
include
(
%Q(<
#{
incoming
_api_projects_url
}
?
#{
query
.
merge
(
page:
1
).
to_query
}
>; rel="first")
)
expect
(
val
).
to
include
(
%Q(<
#{
incoming
_api_projects_url
}
?
#{
query
.
merge
(
page:
2
).
to_query
}
>; rel="next")
)
expect
(
val
).
not_to
include
(
'rel="last"'
)
expect
(
val
).
not_to
include
(
'rel="prev"'
)
end
...
...
@@ -318,9 +322,9 @@ describe API::Helpers::Pagination do
expect_header
(
'X-Prev-Page'
,
'1'
)
expect_header
(
'Link'
,
anything
)
do
|
_key
,
val
|
expect
(
val
).
to
include
(
%Q(<
#{
canonical
_api_projects_url
}
?
#{
query
.
merge
(
page:
1
).
to_query
}
>; rel="first")
)
expect
(
val
).
to
include
(
%Q(<
#{
canonical
_api_projects_url
}
?
#{
query
.
merge
(
page:
2
).
to_query
}
>; rel="last")
)
expect
(
val
).
to
include
(
%Q(<
#{
canonical
_api_projects_url
}
?
#{
query
.
merge
(
page:
1
).
to_query
}
>; rel="prev")
)
expect
(
val
).
to
include
(
%Q(<
#{
incoming
_api_projects_url
}
?
#{
query
.
merge
(
page:
1
).
to_query
}
>; rel="first")
)
expect
(
val
).
to
include
(
%Q(<
#{
incoming
_api_projects_url
}
?
#{
query
.
merge
(
page:
2
).
to_query
}
>; rel="last")
)
expect
(
val
).
to
include
(
%Q(<
#{
incoming
_api_projects_url
}
?
#{
query
.
merge
(
page:
1
).
to_query
}
>; rel="prev")
)
expect
(
val
).
not_to
include
(
'rel="next"'
)
end
...
...
@@ -367,8 +371,8 @@ describe API::Helpers::Pagination do
expect_header
(
'X-Prev-Page'
,
''
)
expect_header
(
'Link'
,
anything
)
do
|
_key
,
val
|
expect
(
val
).
to
include
(
%Q(<
#{
canonical
_api_projects_url
}
?
#{
query
.
merge
(
page:
1
).
to_query
}
>; rel="first")
)
expect
(
val
).
to
include
(
%Q(<
#{
canonical
_api_projects_url
}
?
#{
query
.
merge
(
page:
1
).
to_query
}
>; rel="last")
)
expect
(
val
).
to
include
(
%Q(<
#{
incoming
_api_projects_url
}
?
#{
query
.
merge
(
page:
1
).
to_query
}
>; rel="first")
)
expect
(
val
).
to
include
(
%Q(<
#{
incoming
_api_projects_url
}
?
#{
query
.
merge
(
page:
1
).
to_query
}
>; rel="last")
)
expect
(
val
).
not_to
include
(
'rel="prev"'
)
expect
(
val
).
not_to
include
(
'rel="next"'
)
expect
(
val
).
not_to
include
(
'page=0'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment