Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Fix curl POST fails with 400 #10

Merged
merged 2 commits into from Sep 13, 2016
Merged

Fix curl POST fails with 400 #10

merged 2 commits into from Sep 13, 2016

Conversation

yarnaimo
Copy link
Contributor

oauth/request_token と oauth/access_token で400が返されるのを修正

@mpyw
Copy link
Owner

mpyw commented Sep 12, 2016

取り急ぎ手元で動作確認をしてみましたが,問題なく動作しました.このコミットをマージすること自体は構わないのですが,具体的にどういうケースで障害が発生したのかをお知らせいただけると助かります.ライブラリが想定しているように,毎回新しいcURLリソースを作成する使い方をすれば,この処理が無くても動作するはずなので.

@yarnaimo
Copy link
Contributor Author

yarnaimo commented Sep 13, 2016

Example: Sign in with Twitter と同じようにログインを実装したのですがoauthForRequestTokenで例外が発生します。CURLOPT_POSTFIELDSに空文字を指定すると問題なく動作しました。

メッセージ:
The server returned the status 400 with empty response. (This is a message generated by Cowitter)

mpyw added a commit that referenced this pull request Sep 13, 2016
nc -l 127.0.0.1 8080

でリッスンしてリクエストを表示します.
MD5ハッシュをとるためには

nc -l 127.0.0.1 8080 | md5

とします.これを

- checks-for-pr10.php
- checks-for-pr10-fixed.php

とも実行し,全く同じになるかどうかを確認します.
@mpyw
Copy link
Owner

mpyw commented Sep 13, 2016

うーん,同じように再確認してみたんですが現象が全く再現できません…
OSによってlibcurlの挙動に差があるかもしれない,という点だけが気になります.
(当方OSX El Capitanで,libcurlのバージョンは 7.43.0 です)

差し支え無ければブランチ 3c3fcec のスクリプトで実験していただけませんか?
Windows版netcatもあるみたいなので,必要があれば利用してください.

@mpyw
Copy link
Owner

mpyw commented Sep 13, 2016

Authorizationヘッダの中身は全く同じですが,どうもヘッダが微妙に違うせいでハッシュ値は違いますね.

修正前

POST /oauth/request_token HTTP/1.1
Host: 127.0.0.1:8080
Accept: */*
Authorization: OAuth oauth_consumer_key="aaa", oauth_signature_method="HMAC-SHA1", oauth_timestamp="0", oauth_version="1.0a", oauth_nonce="abcdefg", oauth_signature="LMmADkZVxLb%2FwJMSCWpPL5ulLSU%3D"
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue

修正後

POST /oauth/request_token HTTP/1.1
Host: 127.0.0.1:8080
Accept: */*
Authorization: OAuth oauth_consumer_key="aaa", oauth_signature_method="HMAC-SHA1", oauth_timestamp="0", oauth_version="1.0a", oauth_nonce="abcdefg", oauth_signature="LMmADkZVxLb%2FwJMSCWpPL5ulLSU%3D"
Content-Length: 0
Content-Type: application/x-www-form-urlencoded

考察

よくあるパターンとして

Content-Type: application/x-www-form-urlencoded
Content-Length: 0
Content-Type: multipart/form-data; boundary=xxxxx
Expect: 100-continue

の組み合わせは自然なものですが,どうも

Content-Type: application/x-www-form-urlencoded
Expect: 100-continue

は不自然に思えるので,PRマージしておきます.
(それにしても,私の環境では問題なく動作するというのが気になりますが…)

@mpyw mpyw merged commit 702c741 into mpyw:master Sep 13, 2016
@mpyw
Copy link
Owner

mpyw commented Sep 13, 2016

ご報告ありがとうございました.

mpyw added a commit that referenced this pull request Sep 13, 2016
@yarnaimo
Copy link
Contributor Author

ありがとうございます。 3c3fcec で確認してみました。

修正前

POST /oauth/request_token HTTP/1.1
Host: 127.0.0.1:8080
Accept: */*
Authorization: OAuth oauth_consumer_key="aaa", oauth_signature_method="HMAC-SHA1", oauth_timestamp="0", oauth_version="1.0a", oauth_nonce="abcdefg", oauth_signature="LMmADkZVxLb%2FwJMSCWpPL5ulLSU%3D"
Content-Length: -1
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue

修正後

POST /oauth/request_token HTTP/1.1
Host: 127.0.0.1:8080
Accept: */*
Authorization: OAuth oauth_consumer_key="aaa", oauth_signature_method="HMAC-SHA1", oauth_timestamp="0", oauth_version="1.0a", oauth_nonce="abcdefg", oauth_signature="LMmADkZVxLb%2FwJMSCWpPL5ulLSU%3D"
Content-Length: 0
Content-Type: application/x-www-form-urlencoded

修正前のContent-Lengthが-1になってますね…

@mpyw
Copy link
Owner

mpyw commented Sep 14, 2016

@ysr227 なんと!libcurlのバージョンはおいくつでしょうか?(古そう…

@mpyw
Copy link
Owner

mpyw commented Sep 14, 2016

備考: phpのcurl ライブラリの使い方のHTTP実例いっぱい - それマグで!

現在のバージョンでは修正されているようです

@yarnaimo
Copy link
Contributor Author

なるほど…7.29.0でした…

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants