Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
df829d42
H
hub
项目概览
github
/
hub
10 个月 前同步成功
通知
3
Star
22523
Fork
2406
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
df829d42
编写于
1月 17, 2020
作者:
M
Mislav Marohnić
提交者:
GitHub
1月 17, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2442 from github/redirect-301
Refuse to follow HTTP 301, 302 redirects for non-GET requests
上级
b7b4a3df
ff6b131d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
58 addition
and
2 deletion
+58
-2
features/pull_request.feature
features/pull_request.feature
+31
-1
github/http.go
github/http.go
+27
-1
未找到文件。
features/pull_request.feature
浏览文件 @
df829d42
...
...
@@ -1189,7 +1189,7 @@ Feature: hub pull-request
When
I successfully run `hub pull-request -m hereyougo`
Then the output should contain exactly "the
:
//url\n"
Scenario
:
Pull request with redirect
Scenario
:
Pull request with
307
redirect
Given the "origin" remote has url "https
:
//github.com/mislav/coral.git"
And
I am on the
"feature"
branch pushed to
"origin/feature"
Given the GitHub API server
:
...
...
@@ -1214,6 +1214,36 @@ Feature: hub pull-request
When
I successfully run `hub pull-request -m hereyougo`
Then the output should contain exactly "the
:
//url\n"
Scenario
:
Pull request with 301 redirect
Given the "origin" remote has url "https
:
//github.com/mislav/coral.git"
And
I am on the
"feature"
branch pushed to
"origin/feature"
Given the GitHub API server
:
"""
get('/repos/mislav/coral') {
redirect 'https://api.github.com/repositories/12345', 301
}
get('/repositories/12345') {
json :name => 'coralify', :owner => { :login => 'coral-org' }
}
post('/repos/mislav/coral/pulls') {
redirect 'https://api.github.com/repositories/12345/pulls', 301
}
post('/repositories/12345/pulls', :host_name => 'api.github.com') {
assert :base => 'master',
:head => 'coral-org:feature',
:title => 'hereyougo'
status 201
json :html_url => "the://url"
}
"""
When
I run `hub pull-request -m hereyougo`
Then
the exit status should be 1
And stderr should contain exactly
:
"""
Error creating pull request: Post https://api.github.com/repositories/12345/pulls: refusing to follow HTTP 301 redirect for a POST request
Have your site admin use HTTP 308 for this kind of redirect
"""
Scenario
:
Default message with --push
Given
the git commit editor is
"true"
Given the GitHub API server
:
...
...
github/http.go
浏览文件 @
df829d42
...
...
@@ -5,6 +5,7 @@ import (
"context"
"crypto/md5"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
...
...
@@ -198,10 +199,35 @@ func newHttpClient(testHost string, verbose bool, unixSocket string) *http.Clien
}
return
&
http
.
Client
{
Transport
:
tr
,
Transport
:
tr
,
CheckRedirect
:
checkRedirect
,
}
}
func
checkRedirect
(
req
*
http
.
Request
,
via
[]
*
http
.
Request
)
error
{
var
recommendedCode
int
switch
req
.
Response
.
StatusCode
{
case
301
:
recommendedCode
=
308
case
302
:
recommendedCode
=
307
}
origMethod
:=
via
[
len
(
via
)
-
1
]
.
Method
if
recommendedCode
!=
0
&&
!
strings
.
EqualFold
(
req
.
Method
,
origMethod
)
{
return
fmt
.
Errorf
(
"refusing to follow HTTP %d redirect for a %s request
\n
"
+
"Have your site admin use HTTP %d for this kind of redirect"
,
req
.
Response
.
StatusCode
,
origMethod
,
recommendedCode
)
}
// inherited from stdlib defaultCheckRedirect
if
len
(
via
)
>=
10
{
return
errors
.
New
(
"stopped after 10 redirects"
)
}
return
nil
}
func
cloneRequest
(
req
*
http
.
Request
)
*
http
.
Request
{
dup
:=
new
(
http
.
Request
)
*
dup
=
*
req
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录