forked from moliad/utils-libs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils-http.r
More file actions
210 lines (168 loc) · 5.03 KB
/
Copy pathutils-http.r
File metadata and controls
210 lines (168 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
REBOL [
; -- Core Header attributes --
title: "Generic slim Template."
file: %utils-http.r
version: 0.1.0
date: 2013-9-12
author: "Maxim Olivier-Adlhoch"
purpose: "Manipulate "
web: http://www.revault.org/modules/utils-http.rmrk
source-encoding: "Windows-1252"
note: {slim Library Manager is Required to use this module.}
; -- slim - Library Manager --
slim-name: 'utils-http
slim-version: 1.2.1
slim-prefix: none
slim-update: http://www.revault.org/downloads/modules/utils-http.r
; -- Licensing details --
copyright: "Copyright © 2013 Maxim Olivier-Adlhoch"
license-type: "Apache License v2.0"
license: {Copyright © 2013 Maxim Olivier-Adlhoch
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.}
;- / history
history: {
2013-05-03 - v0.1.0
-creation of history.
v0.1.0 - 2013-09-12
-License changed to Apache v2
}
;- \ history
;- / documentation
documentation: ""
;- \ documentation
]
;--------------------------------------
; unit testing setup (using slut.r)
;--------------------------------------
;
; test-enter-slim 'utils-http
;
;--------------------------------------
slim/register [
;- .
;-----------------------------------------------------------------------------------------------------------
;
;- GLOBALS
;
;-----------------------------------------------------------------------------------------------------------
;- .
;-----------------------------------------------------------------------------------------------------------
;
;- PARSE RULES
;
;-----------------------------------------------------------------------------------------------------------
;- -basic characters & lines
=lf=: #"^/"
=crlf=: crlf
=lf=: lf
=cr=: cr
=nl=: [ =crlf= | =cr= | =lf= ]
=crlfx2=: join =crlf= =crlf=
=dquote=: #"^""
;- .
;-----------------------------------------------------------------------------------------------------------
;
;- CLASSES
;
;-----------------------------------------------------------------------------------------------------------
;- .
;-----------------------------------------------------------------------------------------------------------
;-
;- FUNCTIONS
;-
;-----------------------------------------------------------------------------------------------------------
;-----------------
;- escape-html()
;
; returns a new string
;-----------------
escape-html: func [
html [string!]
][
vin [{escape-html()}]
html: copy copy
foreach [char code] [
"&" "&"
"<" "<"
">" ">"
][
replace/all html char code
]
vout
html
]
;--------------------------
;- escape-pre()
;--------------------------
; purpose: given html source will find and escape <pre> </pre> tags.
;--------------------------
escape-pre: funcl [
html [string!]
][
vin "escape-pre()"
txt: copy html
parse/all txt [
some [
"<pre>" here: copy val to "</pre>" there: ( change/part here (escape-html val) there )
| skip
]
]
vout
txt
]
;-----------------
;- decode-multipart()
;
; returns a new string
;-----------------
decode-multipart: func [data /local bound list name filename value pos][
list: make block! 2
attempt [
parse/all request/headers/Content-type [
thru "boundary=" opt =dquote= copy bound [to =dquote= | to end]
]
unless bound [return ""] ;-- add proper error handler
insert bound "--"
parse/all data [
some [
bound =nl= some [
thru {name="} copy name to =dquote= skip
[#";" thru {="} copy filename to =dquote= | none]
thru =crlfx2= copy value [to bound | to end] (
insert tail list to word! name
trim/tail value ; -- delete ending crlf
if all [
#"%" = pick value 1
".tmp" = skip tail value -4
][
value: load value
]
either filename [
insert/only tail list reduce [filename value]
][
insert tail list value
]
filename: none
) | "--"
]
]
]
]
list
]
]
;------------------------------------
; We are done testing this library.
;------------------------------------
;
; test-exit-slim
;
;------------------------------------