Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/net/http.slate
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ hc@(Net HttpClient traits) readHeaders: stream@(ReadStream traits)
line isEmpty ifTrue: [^ headers].
re := hc headerResponseRegex clone.
(re match: line) = -1 ifTrue: [error: 'malformed header line'].
headers at: (re subexpression: 0) toLowercase put: (re subexpression: 1).
headers at: (re subexpressionAt: 0) toLowercase put: (re subexpressionAt: 1).
] loop.
].

Expand Down Expand Up @@ -269,7 +269,7 @@ hc@(Net HttpClient traits) readBodyInto: response@(Net ChunkedHttpResponse trait
chunkHeader := (hc readLineFrom: stream).
chunkMatch := hc chunkHeaderRegex clone.
(chunkMatch match: chunkHeader) = -1 ifTrue: [error: 'error reading chunk header: ' ; chunkHeader].
length := ((chunkMatch subexpression: 0) as: Integer &radix: 16)
length := ((chunkMatch subexpressionAt: 0) as: Integer &radix: 16)
inform: 'reading chunk len: ' ; length printString.
len = 0 ifTrue: [trailers := (hc readHeaders: stream).
response headers addAll: trailers.
Expand All @@ -287,9 +287,9 @@ hc@(Net HttpClient traits) readResponse: stream@(ReadStream traits)
re := hc statusResponseRegex clone.
(re match: status) = -1
ifTrue: [error: 'Invalid status line in http response']
ifFalse: [httpVersion := (re subexpression: 0).
statusCode := (re subexpression: 1).
statusReason := (re subexpression: 2)].
ifFalse: [httpVersion := (re subexpressionAt: 0).
statusCode := (re subexpressionAt: 1).
statusReason := (re subexpressionAt: 2)].

httpVersion ~= 'HTTP/1.1' ifTrue: [error: 'Only supporting http version 1.1.'].
headers := (hc readHeaders: stream).
Expand Down Expand Up @@ -324,9 +324,9 @@ _@(Net AsyncHttpReader traits) new
headerReader handle := me handle.
(re match: me result) = -1
ifTrue: [error: 'Invalid status line in http response']
ifFalse: [httpVersion := (re subexpression: 0).
statusCode := (re subexpression: 1).
statusReason := (re subexpression: 2)].
ifFalse: [httpVersion := (re subexpressionAt: 0).
statusCode := (re subexpressionAt: 1).
statusReason := (re subexpressionAt: 2)].
httpVersion ~= 'HTTP/1.1' ifTrue: [error: 'Only supporting http version 1.1.'].
o workBlock := [headerReader workOn]].

Expand Down Expand Up @@ -375,7 +375,7 @@ _@(Net AsyncHttpHeaderReader traits) new
o complete &result: headers]
ifFalse: [(re match: me result) = -1
ifTrue: [error: 'Invalid header line in http response']
ifFalse: [headers at: (re subexpression: 0) toLowercase put: (re subexpression: 1).
ifFalse: [headers at: (re subexpressionAt: 0) toLowercase put: (re subexpressionAt: 1).
lineReader reset]]

].
Expand Down Expand Up @@ -416,7 +416,7 @@ _@(Net AsyncHttpBodyReader traits) new
lineReader completionBlock :=
[| :me length |
(re match: me result) = -1 ifTrue: [error: 'error reading chunk header: ' ; me result].
length := ((chunkMatch subexpression: 0) as: Integer &radix: 16).
length := ((chunkMatch subexpressionAt: 0) as: Integer &radix: 16).
inform: 'reading chunk len: ' ; length printString.
chunkReader reset.
chunkReader amount := length + 2. "plus CRLF"
Expand Down
4 changes: 2 additions & 2 deletions src/net/sockets.slate
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ addr@(Net SocketAddress traits) separatePort: string@(String traits)
regex := Regex Matcher newOn: '^([^:]+)(\\:(\\d+))?$'.
(regex match: string) = -11
ifTrue: [{Nil. Nil}]
ifFalse: [{regex subexpression: 0. regex subexpression: 2}]
ifFalse: [{regex subexpressionAt: 0. regex subexpressionAt: 2}]
].

addr@(Net SocketAddress traits) newOn: string@(String traits)
Expand All @@ -108,7 +108,7 @@ addr@(Net SocketAddress traits) newOn: string@(String traits)
regex := Regex Matcher newOn: '^(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$'.
(regex match: portIp first) = -1
ifTrue: [error: 'cannot get ip from string: ' ; string].
array := {regex subexpression: 0. regex subexpression: 1. regex subexpression: 2. regex subexpression: 3. }
array := {regex subexpressionAt: 0. regex subexpressionAt: 1. regex subexpressionAt: 2. regex subexpressionAt: 3. }
collect: #(as: Integer) `er.
Net IP4Address new `>> [address := Net IP4Address domain createIPAddress: array port: (portIp second as: Integer) options: #{}. ]
].
Expand Down
10 changes: 5 additions & 5 deletions src/net/uri.slate
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ u@(Net URI traits) newFrom: s
r := (Regex Matcher newOn: '^(([^:/?#]+)\\:)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?').
(r match: s) ~= -1
ifTrue: [u cloneSettingSlots: #{#scheme. #authority. #path. #query. #fragment}
to: {(r subexpression: 1) as: Net Schemes Scheme.
r subexpression: 3.
(r subexpression: 4) ifNil: ['/'].
r subexpression: 6.
r subexpression: 7}]
to: {(r subexpressionAt: 1) as: Net Schemes Scheme.
r subexpressionAt: 3.
(r subexpressionAt: 4) ifNil: ['/'].
r subexpressionAt: 6.
r subexpressionAt: 7}]
ifFalse: [error: 'Unable to parse: ' ; s ; ' as URI']
].

Expand Down
2 changes: 1 addition & 1 deletion tests/regex.slate
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ _@lobby testURLMatch
[
r ::= Regex Matcher for: '^(([^:/?#]+)X)?(//([^/?#]*))?([^?#]*)(Z([^#]*))?(#(.*))?'.
(r matches: 'httpX//www.foo.com/ra/ra/raZa=b') printOn: Console writer.
1 to: 10 do: [ | :a | Console ; (a as: '') ; ' ' . (r subexpression: a) printOn: Console writer. Console ; '\n'].
1 to: 10 do: [ | :a | Console ; (a as: '') ; ' ' . (r subexpressionAt: a) printOn: Console writer. Console ; '\n'].
].