1
1
# SPDX-License-Identifier: AGPL-3.0-only
2
- import httpclient, asyncdispatch, options, strformat, strutils, uri, times, math, tables
2
+ import httpclient, asyncdispatch, options, strutils, uri, times, math, tables
3
3
import jsony, packedjson, zippy, oauth1
4
4
import types, auth, consts, parserutils, http_pool
5
5
import experimental/ types/ common
@@ -28,27 +28,21 @@ proc getOauthHeader(url, oauthToken, oauthTokenSecret: string): string =
28
28
29
29
return getOauth1RequestHeader (params)[" authorization" ]
30
30
31
- proc genHeaders * (url: string ; session: Session ): HttpHeaders =
31
+ proc genHeaders * (url, oauthToken, oauthTokenSecret: string ): HttpHeaders =
32
+ let header = getOauthHeader (url, oauthToken, oauthTokenSecret)
33
+
32
34
result = newHttpHeaders ({
33
35
" connection" : " keep-alive" ,
36
+ " authorization" : header,
34
37
" content-type" : " application/json" ,
35
38
" x-twitter-active-user" : " yes" ,
36
39
" authority" : " api.x.com" ,
37
40
" accept-encoding" : " gzip" ,
38
41
" accept-language" : " en-US,en;q=0.9" ,
39
42
" accept" : " */*" ,
40
- " DNT" : " 1" ,
43
+ " DNT" : " 1"
41
44
})
42
45
43
- case session.kind
44
- of oauth:
45
- result [" authorization" ] = getOauthHeader (url, session.oauthToken, session.oauthSecret)
46
- of cookie:
47
- result [" authorization" ] = " Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
48
- result [" x-twitter-auth-type" ] = " OAuth2Session"
49
- result [" x-csrf-token" ] = session.ct0
50
- result [" cookie" ] = & " ct0={ session.ct0} ; auth_token={ session.authToken} "
51
-
52
46
template fetchImpl (result, fetchBody) {.dirty .} =
53
47
once:
54
48
pool = HttpPool ()
@@ -60,7 +54,7 @@ template fetchImpl(result, fetchBody) {.dirty.} =
60
54
61
55
try :
62
56
var resp: AsyncResponse
63
- pool.use (genHeaders ($ url, session)):
57
+ pool.use (genHeaders ($ url, session.oauthToken, session.oauthSecret )):
64
58
template getContent =
65
59
resp = await c.get ($ url)
66
60
result = await resp.body
0 commit comments