forked from Krowemoh/TCL-Utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTTP.SERVER
672 lines (671 loc) · 15.8 KB
/
HTTP.SERVER
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
*
GIT.FILENAME = 'HTTP.SERVER'
GIT.REPO = 'https://github.com/Krowemoh/TCL-Utilities.git'
*
* COMPILER DIRECTIVES
*
$DEFINE DATABASE.UV
$DEFINE PLATFORM.LINUX
*
EQU TRUE TO 1
EQU FALSE TO 0
*
DIM REQUEST(10)
*
EQU REQUEST.TYPE.ATTRIBUTE TO 1
EQU REQUEST.VERSION.ATTRIBUTE TO 2
EQU REQUEST.URL.ATTRIBUTE TO 3
EQU REQUEST.QUERY.ATTRIBUTE TO 4
EQU REQUEST.HEADERS.ATTRIBUTE TO 5
EQU REQUEST.COOKIES.ATTRIBUTE TO 6
EQU REQUEST.RAW.BODY.ATTRIBUTE TO 7
EQU REQUEST.FORM.ATTRIBUTE TO 8
EQU REQUEST.JSON.ATTRIBUTE TO 9
EQU REQUEST.RAW.REQUEST.ATTRIBUTE TO 10
*
MAT REQUEST = ''
*
DIM RESPONSE(3)
*
EQU RESPONSE.STATUS.ATTRIBUTE TO 1
EQU RESPONSE.HEADERS.ATTRIBUTE TO 2
EQU RESPONSE.CONTENT.ATTRIBUTE TO 3
*
MAT RESPONSE = ''
*
@USER1 = 'HTTP.SERVER'
@USER2 = 'HTTP.SERVER'
*
CR = CHAR(13)
LF = CHAR(10)
*
BODY.DELIMITER = CR:LF:CR:LF
BODY.DELIMITER.LEN = LEN(BODY.DELIMITER)
*
ALLOWED.METHODS = 'GET POST PUT PATCH DELETE '
*
HTTP.STATUSES = ''
*
HTTP.STATUSES<1,-1> = 200
HTTP.STATUSES<2,-1> = 'OK'
*
HTTP.STATUSES<1,-1> = 301
HTTP.STATUSES<2,-1> = 'Found'
*
HTTP.STATUSES<1,-1> = 302
HTTP.STATUSES<2,-1> = 'Moved Permanently'
*
HTTP.STATUSES<1,-1> = 303
HTTP.STATUSES<2,-1> = 'See Other'
*
HTTP.STATUSES<1,-1> = 400
HTTP.STATUSES<2,-1> = 'Bad Request'
*
HTTP.STATUSES<1,-1> = 401
HTTP.STATUSES<2,-1> = 'Unauthorized'
*
HTTP.STATUSES<1,-1> = 404
HTTP.STATUSES<2,-1> = 'Not Found'
*
HTTP.STATUSES<1,-1> = 500
HTTP.STATUSES<2,-1> = 'Internal Server Error'
*
HTTP.STATUSES<1,-1> = 501
HTTP.STATUSES<2,-1> = 'Not Implemented'
*
*
SERVER.PORT = 7122
*
OPEN '','MD' TO MD.FILE ELSE
PRINT 'Unable to open file: MD'
STOP
END
*
$IFDEF DATABASE.D3
CLEARSELECT
FLASH.CMD = 'SELECT DICT BP HTTP.SERVER C/FLASH'
EXECUTE FLASH.CMD CAPTURING OUTPUT
READNEXT FLASH.COMPILED ELSE FLASH.COMPILED = 0
*
IF NOT(FLASH.COMPILED) THEN
PRINT 'HTTP.SERVER is not flash compiled.'
STOP
END
$ENDIF
*
* SOCKET INITIALIZATION
*
$IFDEF DATABASE.D3
CFUNCTION SOCKET.BUILTIN
*
SOCKET = %SOCKET(2,1,6)
IF SOCKET < 0 THEN
CRT 'ERROR ' : SYSTEM(0) : ' - Socket failed.'
STOP
END
*
CODE = %BIND(SOCKET,2,0,SERVER.PORT)
IF CODE < 0 THEN
CRT 'ERROR ' : SYSTEM(0) : ' - Bind failed.'
%CLOSESOCKET(SOCKET)
STOP
END
*
CODE = %LISTEN(SOCKET,1)
IF CODE < 0 THEN
CRT 'ERROR ' : SYSTEM(0) : ' - Listen failed.'
%CLOSESOCKET(SOCKET)
STOP
END
$ENDIF
*
$IFDEF DATABASE.QM
SOCKET = CREATE.SERVER.SOCKET('',SERVER.PORT,0)
CODE = STATUS()
IF CODE THEN
CRT 'ERROR ' : CODE : ' - CREATE.SERVER.SOCKET failed.'
CLOSE.SOCKET SOCKET
END
$ENDIF
*
$IFDEF DATABASE.UV
CODE = initServerSocket('0.0.0.0',SERVER.PORT,1,SOCKET)
IF CODE # 0 THEN
CRT 'ERROR ' : SYSTEM(0) : ' - initServerSocket failed.'
CODE = closeSocket(SOCKET)
END
$ENDIF
*
CRT 'Listening on: 0.0.0.0:' : SERVER.PORT
CRT
*
OPEN '','CONTROL-FILE' TO CONTROL.FILE ELSE
PRINT 'Unable to open file: CONTROL-FILE - Press RETURN':
INPUT ANYTHING
STOP
END
*
DONE = FALSE
*
CLIENT.ADDRESS = 0
CLIENT.PORT = 0
*
LOOP UNTIL DONE DO
*
READ ROUTES FROM CONTROL.FILE,'ROUTES' ELSE ROUTES = ''
*
$IFDEF DATABASE.D3
FD = %ACCEPT(SOCKET,&CLIENT.ADDRESS,&CLIENT.PORT)
IF FD < 0 THEN
CRT 'ERROR ' : SYSTEM(0) : ' = Accept failed.'
%CLOSESOCKET(SOCKET)
STOP
END
$ENDIF
*
$IFDEF DATABASE.QM
FD = ACCEPT.SOCKET(SOCKET,0)
CODE = STATUS()
IF CODE THEN
CRT 'ERROR ' : CODE : ' = Accept failed.'
CLOSE.SOCKET SOCKET
STOP
END
$ENDIF
*
$IFDEF DATABASE.UV
CODE = acceptConnection(SOCKET,1,0,NULL,NULL,FD)
IF CODE # 0 THEN
CRT 'ERROR ' : SYSTEM(0) : ' = Accept failed.'
CODE = closeSocket(SOCKET)
STOP
END
$ENDIF
*
GOSUB INITIALIZE.REQUEST
MAT RESPONSE = ''
*
GOSUB READ.REQUEST
REQUEST(REQUEST.RAW.REQUEST.ATTRIBUTE) = RAW.REQUEST
*
GOSUB GET.STATUS.LINE
REQUEST(REQUEST.TYPE.ATTRIBUTE) = REQUEST.TYPE
REQUEST(REQUEST.VERSION.ATTRIBUTE) = REQUEST.VERSION
REQUEST(REQUEST.URL.ATTRIBUTE) = REQUEST.URL
REQUEST(REQUEST.QUERY.ATTRIBUTE) = REQUEST.QUERY
*
GOSUB GET.HEADERS
REQUEST(REQUEST.HEADERS.ATTRIBUTE) = REQUEST.HEADERS
REQUEST(REQUEST.COOKIES.ATTRIBUTE) = REQUEST.COOKIES
*
IF REQUEST.TYPE = 'POST' THEN
GOSUB GET.POST.DATA
REQUEST(REQUEST.RAW.BODY.ATTRIBUTE) = REQUEST.RAW.BODY
REQUEST(REQUEST.FORM.ATTRIBUTE) = REQUEST.FORM
REQUEST(REQUEST.JSON.ATTRIBUTE) = REQUEST.JSON
END
*
*TEMP GOSUB LOG.REQUEST
*
T1 = TIME()
*
BEGIN CASE
CASE REQUEST.ERROR # ''
PRINT REQUEST.ERROR
*
RESPONSE(RESPONSE.STATUS.ATTRIBUTE) = 400
RESPONSE(RESPONSE.CONTENT.ATTRIBUTE) = 'Bad request.'
GOSUB SEND.HTTP.RESPONSE
*
CASE REQUEST.URL = '/kill'
DONE = TRUE
*
RESPONSE(RESPONSE.STATUS.ATTRIBUTE) = 200
RESPONSE(RESPONSE.CONTENT.ATTRIBUTE) = 'Killing server.'
GOSUB SEND.HTTP.RESPONSE
*
CASE REQUEST.URL = '/restart'
DONE = TRUE
*
RESPONSE(RESPONSE.STATUS.ATTRIBUTE) = 200
RESPONSE(RESPONSE.CONTENT.ATTRIBUTE) = 'Restarting server.'
GOSUB SEND.HTTP.RESPONSE
*
$IFDEF DATABASE.D3
%CLOSESOCKET(FD)
%CLOSESOCKET(SOCKET)
$ENDIF
*
$IFDEF DATABASE.QM
CLOSE.SOCKET FD
CLOSE.SOCKET SOCKET
$ENDIF
*
$IFDEF DATABASE.UV
CODE = closeSocket(FD)
CODE = closeSocket(SOCKET)
$ENDIF
*
CHAIN 'HTTP.SERVER'
*
CASE TRUE
PROCEED = TRUE
*
LOCATE(REQUEST.URL,ROUTES<1>,1;ROUTE.POS) ELSE
RESPONSE(RESPONSE.STATUS.ATTRIBUTE) = 404
RESPONSE(RESPONSE.CONTENT.ATTRIBUTE) = 'Page not found.'
GOSUB SEND.HTTP.RESPONSE
PROCEED = FALSE
END
*
IF PROCEED THEN
FUNC = TRIM(ROUTES<2,ROUTE.POS>)
*
READ MD.ITEM FROM MD.FILE,FUNC ELSE
RESPONSE(RESPONSE.STATUS.ATTRIBUTE) = 500
RESPONSE(RESPONSE.CONTENT.ATTRIBUTE) = 'Subroutine "' : FUNC : '" was not cataloged.'
GOSUB SEND.HTTP.RESPONSE
PROCEED = FALSE
END
END
*
IF PROCEED THEN
$IFDEF DATABASE.D3
PROGRAM.FOLDER.NAME = TRIM(FIELD(MD.ITEM<4>,' ',1))
*
CLEARSELECT
FLASH.CMD = 'SELECT DICT ' : PROGRAM.FOLDER.NAME : ' ' : FUNC : ' C/FLASH'
EXECUTE FLASH.CMD
READNEXT FLASH.COMPILED ELSE FLASH.COMPILED = 0
*
IF NOT(FLASH.COMPILED) THEN
RESPONSE(RESPONSE.STATUS.ATTRIBUTE) = 500
RESPONSE(RESPONSE.CONTENT.ATTRIBUTE) = 'Subroutine "' : FUNC : '" was not flash compiled.'
GOSUB SEND.HTTP.RESPONSE
PROCEED = FALSE
END
$ENDIF
END
*
IF PROCEED THEN
$IFDEF DATABASE.D3
%CLOSESOCKET(SOCKET)
$ENDIF
*
$IFDEF DATABASE.QM
CLOSE.SOCKET SOCKET
$ENDIF
*
$IFDEF DATABASE.UV
CODE = closeSocket(SOCKET)
$ENDIF
*
EXECUTE 'PHANTOM BRIEF HTTP.SERVER' CAPTURING RESULT
*
PHANTOM.STARTED = INDEX(RESULT,'started',1) > 0
*
IF PHANTOM.STARTED THEN
DONE = TRUE
END ELSE
DONE = FALSE
END
*
CALL @FUNC(MAT REQUEST,MAT RESPONSE)
GOSUB SEND.HTTP.RESPONSE
END
*
END CASE
*
T2 = TIME()
*
TIME.TAKEN = T2 - T1
GOSUB LOG.RESPONSE
*
$IFDEF DATABASE.D3
%CLOSESOCKET(FD)
$ENDIF
*
$IFDEF DATABASE.QM
CLOSE.SOCKET FD
$ENDIF
*
$IFDEF DATABASE.UV
CODE = closeSocket(FD)
$ENDIF
REPEAT
*
$IFDEF DATABASE.D3
%CLOSESOCKET(SOCKET)
$ENDIF
*
$IFDEF DATABASE.QM
CLOSE.SOCKET SOCKET
$ENDIF
*
$IFDEF DATABASE.UV
CODE = closeSocket(SOCKET)
$ENDIF
*
STOP
*
********************* S U B R O U T I N E *********************
*
INITIALIZE.REQUEST:NULL
*
MAT REQUEST =''
*
RAW.REQUEST = ''
*
REQUEST.ERROR = ''
*
REQUEST.TYPE = ''
REQUEST.VERSION = ''
REQUEST.URL = ''
REQUEST.QUERY = ''
*
REQUEST.HEADERS = ''
REQUEST.COOKIES = ''
*
REQUEST.RAW.BODY = ''
REQUEST.FORM = ''
REQUEST.JSON = ''
*
RETURN
*
********************* S U B R O U T I N E *********************
*
READ.REQUEST:NULL
*
BUFFER.SIZE = 300
*
READ.DONE = FALSE
*
LOOP UNTIL READ.DONE DO
$IFDEF DATABASE.D3
CHAR BUFFER[BUFFER.SIZE]
$ENDIF
*
$IFDEF DATABASE.QM
CHAR BUFFER[BUFFER.SIZE]
$ENDIF
*
$IFDEF DATABASE.UV
BUFFER = SPACES(BUFFER.SIZE)
CONVERT ' ' TO '' IN BUFFER
$ENDIF
*
$IFDEF DATABASE.D3
READ.SIZE = %RECV(FD,BUFFER,BUFFER.SIZE,0)
$ENDIF
*
$IFDEF DATABASE.QM
BUFFER = READ.SOCKET(FD,BUFFER.SIZE,1,0)
$ENDIF
*
$IFDEF DATABASE.UV
CODE = readSocket(FD,BUFFER,BUFFER.SIZE,0,1,READ.SIZE)
$ENDIF
*
IF READ.SIZE < 0 THEN
CRT 'Read Error: ' : SYSTEM(0)
READ.DONE = TRUE
*
END ELSE IF READ.SIZE < BUFFER.SIZE THEN
RAW.REQUEST = RAW.REQUEST : BUFFER[1,BUFFER.SIZE]
READ.DONE = TRUE
*
END ELSE
RAW.REQUEST = RAW.REQUEST : BUFFER
END
REPEAT
*
RETURN
*
********************* S U B R O U T I N E *********************
*
GET.STATUS.LINE:NULL
*
IF RAW.REQUEST = '' THEN
REQUEST.ERROR = 'Invalid request - request is blank.'
RETURN
END
*
STATUS.LINE = FIELD(RAW.REQUEST,CR:LF,1)
*
REQUEST.TYPE = FIELD(STATUS.LINE,' ',1)
IF INDEX(ALLOWED.METHODS,REQUEST.TYPE:' ',1) = 0 THEN
REQUEST.ERROR = 'Invalid request - type: ' : REQUEST.TYPE
RETURN
END
*
REQUEST.VERSION = FIELD(STATUS.LINE,' ',3)
*
REQUEST.URL = FIELD(STATUS.LINE,' ',2)
REQUEST.QUERY = ''
*
IF INDEX(REQUEST.URL,'?',1) THEN
QUERY.PARAMS = FIELD(REQUEST.URL,'?',2)
QUERY.LENGTH = LEN(QUERY.PARAMS)
*
TOKEN = ''
IN.NAME = TRUE
*
FOR I = 1 TO QUERY.LENGTH
LETTER = QUERY.PARAMS[I,1]
*
IF IN.NAME AND LETTER = '=' THEN
REQUEST.QUERY<1,-1> = TOKEN
TOKEN = ''
IN.NAME = FALSE
*
END ELSE IF LETTER = '&' THEN
REQUEST.QUERY<2,-1> = TOKEN
TOKEN = ''
IN.NAME = TRUE
*
END ELSE
TOKEN = TOKEN : LETTER
END
NEXT I
*
IF TOKEN # '' THEN
REQUEST.QUERY<2,-1> = TOKEN
END
*
REQUEST.URL = FIELD(REQUEST.URL,'?',1)
END
*
RETURN
*
********************* S U B R O U T I N E *********************
*
GET.HEADERS:NULL
*
START.POS = INDEX(RAW.REQUEST,CR:LF,1)
*
IF REQUEST.TYPE = 'POST' THEN
HEADERS = RAW.REQUEST[START.POS+2,INDEX(RAW.REQUEST,BODY.DELIMITER,1)-START.POS-2]
END ELSE
HEADERS = RAW.REQUEST[START.POS+2,LEN(RAW.REQUEST)-START.POS-2]
END
*
HEADERS.LENGTH = LEN(HEADERS)
*
TOKEN = ''
IN.NAME = TRUE
*
FOR I = 1 TO HEADERS.LENGTH
LETTER = HEADERS[I,1]
*
IF IN.NAME AND LETTER = ':' THEN
REQUEST.HEADERS<1,-1> = TRIM(TOKEN)
TOKEN = ''
IN.NAME = FALSE
*
END ELSE IF LETTER = CR THEN
IF HEADERS[I+1,1] = LF THEN
I = I + 1
END
*
REQUEST.HEADERS<2,-1> = TRIM(TOKEN)
TOKEN = ''
IN.NAME = TRUE
*
END ELSE
TOKEN = TOKEN : LETTER
END
NEXT I
*
IF TOKEN # '' THEN
REQUEST.HEADERS<2,-1> = TRIM(TOKEN)
END
*
LOCATE('Cookie',REQUEST.HEADERS<1>,1;ANYPOS) THEN
COOKIES = REQUEST.HEADERS<2,ANYPOS>
CONVERT ';' TO @AM IN COOKIES
NUMBER.OF.COOKIES = DCOUNT(COOKIES,@AM)
*
FOR COOKIE.CTR = 1 TO NUMBER.OF.COOKIES
COOKIE = COOKIES<COOKIE.CTR>
*
CONVERT '=' TO @AM IN COOKIE
*
REQUEST.COOKIES<1,-1> = TRIM(COOKIE<1>)
REQUEST.COOKIES<2,-1> = TRIM(COOKIE<2>)
NEXT COOKIE.CTR
END
*
RETURN
*
********************* S U B R O U T I N E *********************
*
GET.POST.DATA:NULL
*
LOCATE('Content-Type',REQUEST.HEADERS,1;ANYPOS) ELSE
REQUEST.ERROR = 'Cannot find Content-Type, make sure it is spelled correctly.'
RETURN
END
*
CONTENT.TYPE = REQUEST.HEADERS<2,ANYPOS>
*
LOCATE('Content-Length',REQUEST.HEADERS,1;ANYPOS) ELSE
REQUEST.ERROR = 'Cannot find Content-Length, make sure it is set correctly.'
RETURN
END
*
CONTENT.LENGTH = REQUEST.HEADERS<2,ANYPOS>
*
REQUEST.RAW.BODY = RAW.REQUEST[INDEX(RAW.REQUEST,BODY.DELIMITER,1)+BODY.DELIMITER.LEN,CONTENT.LENGTH]
*
IF CONTENT.TYPE = 'application/x-www-form-urlencoded' THEN
TOKEN = ''
*
FOR I = 1 TO CONTENT.LENGTH
LETTER = REQUEST.RAW.BODY[I,1]
*
IF LETTER = '=' THEN
REQUEST.FORM<1,-1> = TOKEN
TOKEN = ''
*
END ELSE IF LETTER = '&' THEN
REQUEST.FORM<2,-1> = TOKEN
TOKEN = ''
*
END ELSE
TOKEN = TOKEN : LETTER
END
NEXT I
*
IF TOKEN # '' THEN
REQUEST.FORM<2,-1> = TOKEN
END
*
END ELSE IF CONTENT.TYPE = 'application/json' THEN
REQUEST.JSON = REQUEST.RAW.BODY
*
END ELSE
REQUEST.ERROR = 'Unsupported content type: ' : CONTENT.TYPE
END
RETURN
*
********************* S U B R O U T I N E *********************
*
SEND.HTTP.RESPONSE:NULL
*
RESPONSE.STATUS = RESPONSE(RESPONSE.STATUS.ATTRIBUTE)
RESPONSE.BODY = CHANGE(RESPONSE(RESPONSE.CONTENT.ATTRIBUTE),@AM,CR:LF)
*
LOCATE(RESPONSE.STATUS,HTTP.STATUSES,1;POS) THEN
STATUS.TEXT = HTTP.STATUSES<2,POS>
END ELSE
PRINT 'Invalid http status "' : RESPONSE.STATUS : '".'
STATUS.TEXT = 'Invalid Status'
END
*
HEADERS = RESPONSE(RESPONSE.HEADERS.ATTRIBUTE)
*
BUFFER = ''
BUFFER<-1> = 'HTTP/1.1 ' : RESPONSE.STATUS : ' ' : STATUS.TEXT
BUFFER<-1> = 'Date: ' : OCONV(DATE(),'D')
BUFFER<-1> = 'Server: HTTP.SERVER'
BUFFER<-1> = 'Access-Control-Allow-Origin: *'
BUFFER<-1> = 'Access-Control-Allow-Methods: GET, POST, OPTIONS, DELETE, PUT'
BUFFER<-1> = 'Access-Control-Allow-Headers: *'
*
IF HEADERS THEN
BUFFER<-1> = HEADERS
END
*
BUFFER<-1> = 'Content-Length: ' : LEN(RESPONSE.BODY)
BUFFER<-1> = 'Content-Type: text/html'
BUFFER<-1> = 'Connection: Closed'
*
BUFFER = BUFFER : @AM : '' : @AM : RESPONSE.BODY
*
BUFFER = CHANGE(BUFFER,@AM,CR:LF)
*
BUFFER.LENGTH = LEN(BUFFER)
*
$IFDEF DATABASE.D3
CODE = %SEND(FD,BUFFER,BUFFER.LENGTH,0)
$ENDIF
*
$IFDEF DATABASE.QM
WRITE.SIZE = WRITE.SOCKET(FD,BUFFER,0,0)
$ENDIF
*
*
$IFDEF DATABASE.UV
CODE = writeSocket(FD,BUFFER,10000,1,WRITE.SIZE)
$ENDIF
*
RETURN
*
********************* S U B R O U T I N E *********************
*
LOG.REQUEST:NULL
*
PRINT '< [' : OCONV(DATE(),'D') : ' ' :
PRINT OCONV(TIME(),'MTH') : '] ' :
PRINT REQUEST.TYPE : ' ' :
PRINT REQUEST.URL : ' '
*
RETURN
*
********************* S U B R O U T I N E *********************
*
LOG.RESPONSE:NULL
*
PRINT '> [' : OCONV(DATE(),'D') : ' ' :
PRINT OCONV(TIME(),'MTH') : '] ' :
PRINT REQUEST.TYPE : ' ' :
PRINT REQUEST.URL : ' ' :
PRINT RESPONSE.STATUS : ' ' :
PRINT TIME.TAKEN : 's '
*
RETURN
*
* END OF PROGRAM
*
END
*