File tree Expand file tree Collapse file tree 6 files changed +42
-5
lines changed
http-easy-test/net/http-easy/private Expand file tree Collapse file tree 6 files changed +42
-5
lines changed Original file line number Diff line number Diff line change 36
36
(all-from-out "http-easy/private/session.rkt " )
37
37
(all-from-out "http-easy/private/user-agent.rkt " )
38
38
39
+ current-url/literal-query-param-encoder
39
40
(struct-out url/literal)
40
41
string->url/literal
41
42
url/literal->string
Original file line number Diff line number Diff line change 344
344
(let loop ()
345
345
(with-handlers ([exn:fail?
346
346
(lambda (e)
347
- (log-http-easy-warning "will execution failed: ~a " (exn-message e)))])
347
+ (log-http-easy-warning
348
+ "will execution failed: ~a "
349
+ (exn-message e)))])
348
350
(will-execute executor))
349
351
(loop))))))
350
352
Original file line number Diff line number Diff line change 9
9
10
10
(provide
11
11
(struct-out url/literal)
12
+ current-url/literal-query-param-encoder
12
13
string->url/literal
13
14
url/literal->string
14
15
is-percent-encoded?
28
29
;; xref https://github.com/rmculpepper/racket-http123/issues/6
29
30
(serializable-struct url/literal url ())
30
31
32
+ ;; An escape hatch for services that are super non-compliant.
33
+ (define current-url/literal-query-param-encoder
34
+ (make-parameter form-urlencoded-encode))
35
+
31
36
(define (string->url/literal s)
32
37
(match-define (list _ scheme user ipv6host host port path query fragment)
33
38
(regexp-match url-regexp s))
64
69
(url/literal scheme user host port abs? path query fragment)))
65
70
66
71
(define (url/literal->string u)
72
+ (define query-param-encoder
73
+ (current-url/literal-query-param-encoder))
67
74
(define out (open-output-string))
68
75
(match-define (url scheme user host port abs? path query fragment) u)
69
76
(when scheme
115
122
(unless (zero? idx)
116
123
(write-char #\& out))
117
124
(match-define (cons (app symbol->string name) value) pair)
118
- (write-string (maybe-percent-encode name form-urlencoded-encode ) out)
125
+ (write-string (maybe-percent-encode name query-param-encoder ) out)
119
126
(when value
120
127
(write-char #\= out)
121
- (write-string (maybe-percent-encode value form-urlencoded-encode ) out))))
128
+ (write-string (maybe-percent-encode value query-param-encoder ) out))))
122
129
(when fragment
123
130
(write-char #\# out)
124
131
(write-string (maybe-percent-encode fragment) out))
Original file line number Diff line number Diff line change 1
1
#lang info
2
2
3
3
(define license 'BSD-3-Clause )
4
- (define version "0.9.2 " )
4
+ (define version "0.10 " )
5
5
(define collection "net " )
6
6
(define deps
7
7
'(["base " #:version "8.1.0.4 " ]
Original file line number Diff line number Diff line change 101
101
102
102
(test-case "examples "
103
103
(let ([example "https://d12xz7rzfw7xh7.cloudfront.net/v1/download/episodes/original/43796816?a=en&eg=https%3A%2F%2Fapi.spreaker.com%2Fepisode%2F57758598&eu=https%3A%2F%2Fdts.podtrac.com%2Fredirect.mp3%2Fapi.spreaker.com%2Fdownload%2Fepisode%2F57758598%2Ftmp9u92imeh.mp3&p=3&q=9808638&f=559&r=128&t=3&u=11393707&o=2401044&d=2023-11-22&g=57758598&h=5937276&k=https%3A%2F%2Fwww.spreaker.com%2Fshow%2F5937276%2Fepisodes%2Ffeed&i=43796816&n=Petros+And+Money&b=%5B%22IAB6-7%22%2C%22IAB7-39%22%2C%22IAB11-4%22%2C%22IAB26%22%5D&c=%5B%22sports%22%5D&l=%5B%22hosting_plan_ihr%22%5D&m=%5B904294%2C904294%2C904294%2C1436858%2C1436858%2C1436858%2C1436858%2C1436858%2C1937091%2C1937091%2C1937091%5D&rr=4444444444444&fax=0.4&Expires=1732993926&Signature=XDgffPCg91Gd6ThNXoenP4axeBN2zEUK6Bs56F2Pw-LGE9XJuLPghg1f2etV1l6I3%7Ed7Ms12AQbkCp1vfkqleStA30fPDH2PpO1IKkw5k7PlSYyPCeb1DOc1No8s6KHn7C8DZ7swXjWEz5WGzrj6KtSgI%7EWMhQyiLuGxEmT9YBQViowMGeO7p1PNocQmT-SKo8WqMDMdzMmSXP2WQFYSk3AjFM2ukhGLzDkIcrNxy2ZRLGeUykF9ZWgNnGGAOfwsmx6n0IFQZcdDo2QpRKxOUjSBYOTxTo1Y716OYb73P59QurF%7El-jM7WLHgvFxWnJQHj9SwCnjSaCJgzDBlh%7EEDQ__&Key-Pair-Id=K1J2BR3INU6RYD"])
104
- (check-equal? (url/literal->string (string->url/literal example)) example))))
104
+ (check-equal? (url/literal->string (string->url/literal example)) example)))
105
+
106
+ (test-case "current-url/literal-query-param-encoder "
107
+ (check-equal?
108
+ (url/literal->string
109
+ (string->url/literal
110
+ "https://example.com?search=(status:(values:List(DRAFT))) " ))
111
+ "https://example.com?search=%28status%3A%28values%3AList%28DRAFT%29%29%29 " )
112
+ (parameterize ([current-url/literal-query-param-encoder values])
113
+ (check-equal?
114
+ (url/literal->string
115
+ (string->url/literal
116
+ "https://example.com?search=(status:(values:List(DRAFT))) " ))
117
+ "https://example.com?search=(status:(values:List(DRAFT))) " ))))
105
118
106
119
(test-suite
107
120
"is-percent-encoded? "
Original file line number Diff line number Diff line change 7
7
net/cookies/user-agent
8
8
net/http-client
9
9
net/http-easy
10
+ net/uri-codec
10
11
net/url
11
12
openssl
12
13
racket/base
@@ -460,6 +461,19 @@ scheme and url-encode the path to the socket as the host.
460
461
@history[#:added "0.7 " ]
461
462
}
462
463
464
+ @defparam[
465
+ current-url/literal-query-param-encoder
466
+ encoder (-> string? string?)
467
+ #:value form-urlencoded-encode
468
+ ]{
469
+ Some services are both non-compliant and particularly picky about
470
+ how their query string parameters are encoded. Use this parameter to
471
+ precisely control how a @tech{literal URL}'s query params are encoded
472
+ in such cases.
473
+
474
+ @history[#:added "0.10 " ]
475
+ }
476
+
463
477
464
478
@subsection{Responses}
465
479
You can’t perform that action at this time.
0 commit comments