Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
8bea7893
Commit
8bea7893
authored
15 years ago
by
deuce
Browse files
Options
Downloads
Patches
Plain Diff
Add start of HTTP library... currently only does basic HTTP/1.0 and only
supports the GET method.
parent
76f96f76
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
exec/load/http.js
+103
-0
103 additions, 0 deletions
exec/load/http.js
with
103 additions
and
0 deletions
exec/load/http.js
0 → 100644
+
103
−
0
View file @
8bea7893
load
(
'
sockdefs.js
'
);
load
(
"
URL.js
"
);
/*
* TODO Stuff:
* Asynchronous requests
* Keep-alive support
* HTTP/1.1 (chunked, trailers, etc)
* Parse response headers
*/
function
HTTPRequest
()
{
this
.
AddDefaultHeaders
=
function
(){
// General Headers
this
.
request_headers
.
push
(
"
Connection: close
"
);
if
(
js
.
global
.
client
!=
undefined
)
this
.
request_headers
.
push
(
"
Via:
"
+
client
.
protocol
.
toLowerCase
()
+
"
/1.0
"
+
system
.
name
);
// Request Headers
this
.
request_headers
.
push
(
"
Accept: text/*
"
);
this
.
request_headers
.
push
(
"
Accept-Charset: ISO-8859-13,Latin-9,ISO-8859-15
"
);
this
.
request_headers
.
push
(
"
Accept-Encoding:
"
);
this
.
request_headers
.
push
(
"
Host:
"
+
this
.
url
.
host
);
if
(
this
.
referer
!=
undefined
)
this
.
request_headers
.
push
(
"
Referer:
"
+
referer
);
this
.
request_headers
.
push
(
"
User-Agent: SYNXv0.1
"
);
};
this
.
SetupGet
=
function
(
url
,
referer
,
base
)
{
this
.
referer
=
referer
;
this
.
base
=
base
;
this
.
url
=
new
URL
(
url
,
this
.
base
);
if
(
this
.
url
.
scheme
!=
'
http
'
)
throw
(
"
Unknown scheme! '
"
+
this
.
url
.
scheme
+
"
'
"
);
if
(
this
.
url
.
path
==
''
)
this
.
url
.
path
=
'
/
'
;
this
.
request
=
"
GET
"
+
url
.
path
+
"
HTTP/1.0
"
;
this
.
request_headers
=
[];
this
.
AddDefaultHeaders
();
};
this
.
SendRequest
=
function
()
{
var
i
;
if
((
this
.
sock
=
new
Socket
(
SOCK_STREAM
))
==
null
)
throw
(
"
Unable to create socket
"
);
if
(
!
this
.
sock
.
connect
(
this
.
url
.
host
,
this
.
url
.
port
?
this
.
url
.
port
:
80
))
throw
(
"
Unable to connect
"
);
if
(
!
this
.
sock
.
send
(
this
.
request
+
"
\r\n
"
))
throw
(
"
Unable to send request
"
);
for
(
i
in
this
.
request_headers
)
{
if
(
!
this
.
sock
.
send
(
this
.
request_headers
[
i
]
+
"
\r\n
"
))
throw
(
"
Unable to send headers
"
);
}
if
(
!
this
.
sock
.
send
(
"
\r\n
"
))
throw
(
"
Unable to terminate headers
"
);
if
(
this
.
body
!=
undefined
)
{
if
(
!
this
.
sock
.
send
(
this
.
body
))
throw
(
"
Unable to send body
"
);
}
};
this
.
ReadStatus
=
function
()
{
this
.
status_line
=
this
.
sock
.
recvline
(
4096
);
if
(
this
.
status_line
==
null
)
throw
(
"
Unable to read status
"
);
};
this
.
ReadHeaders
=
function
()
{
var
header
=
''
;
this
.
response_headers
=
[];
for
(;;)
{
header
=
this
.
sock
.
recvline
(
4096
);
if
(
header
==
null
)
throw
(
"
Unable to receive headers
"
);
if
(
header
==
''
)
return
;
}
};
this
.
ReadBody
=
function
()
{
var
ch
;
this
.
body
=
''
;
while
((
ch
=
this
.
sock
.
recv
(
1
))
!=
null
&&
ch
!=
''
)
{
this
.
body
+=
ch
;
}
};
this
.
ReadResponse
=
function
()
{
this
.
ReadStatus
();
this
.
ReadHeaders
();
this
.
ReadBody
();
};
this
.
Get
=
function
(
url
,
referer
,
base
)
{
this
.
SetupGet
(
url
,
referer
,
base
);
this
.
SendRequest
();
this
.
ReadResponse
();
return
(
this
.
body
);
};
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment