Replaced HTTP response zero-termination with explicit length.

If we want to be able to send application/octet-stream we can't rely on the HTTP response to not contain a zero byte.
This commit is contained in:
Oliver Schmidt 2017-12-07 22:57:40 +01:00
parent d282290cf0
commit b973526d7e
2 changed files with 18 additions and 4 deletions

View File

@ -14,6 +14,7 @@ HTTPD_TIMEOUT_SECONDS = 5 ; what's the maximum time we let 1 connection be
.export httpd_start
.export httpd_port_number
.export httpd_send_response
.export httpd_response_buffer_length
.import http_parse_request
.import tcp_listen
@ -40,6 +41,7 @@ temp_ptr = ptr1
io_buf: .res $800
found_eol: .res 1
connection_closed: .res 1
httpd_response_buffer_length: .res 2
output_buffer_length: .res 2
sent_header: .res 1
connection_timeout_seconds: .res 1
@ -213,6 +215,7 @@ reset_output_buffer:
; send HTTP response
; inputs:
; AX = pointer to data to be sent
; httpd_response_buffer_length = length of data to be sent
; Y = content type/status code
; outputs:
; none
@ -222,12 +225,17 @@ httpd_send_response:
jsr send_header
@response_loop:
jsr get_next_byte
cmp #0
dec httpd_response_buffer_length
lda httpd_response_buffer_length
cmp #$ff
bne @not_last_byte
dec httpd_response_buffer_length+1
lda httpd_response_buffer_length+1
cmp #$ff
bne @not_last_byte
@send_buffer:
jmp send_buffer
@not_last_byte:
jsr get_next_byte
jsr emit_a
jmp @response_loop

View File

@ -2,11 +2,14 @@
.include "../inc/commonprint.i"
.include "../inc/net.i"
.define HTML "<h1>Hello World</h1><form>Your Name: <input name=n type=text length=20><br>Your Message: <input name=m type=text lengh=60><br><input type=submit></form>"
.export start
.import exit_to_basic
.import httpd_start
.import httpd_response_buffer_length
.import http_get_value
@ -50,6 +53,9 @@ print_vars:
httpd_callback:
jsr print_vars
lda #<.strlen(HTML)
ldx #>.strlen(HTML)
stax httpd_response_buffer_length
ldax #html
ldy #2 ; text/html
clc
@ -65,7 +71,7 @@ listening:
said:
.byte " said ",0
html:
.byte "<h1>Hello World</h1><form>Your Name: <input name=n type=text length=20><br>Your Message: <input name=m type=text lengh=60><br><input type=submit></form>",0
.byte HTML