// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/classes/net/protocols/http.cpp
// Function: smooth::Net::Protocols::httpHeader(char*, unsigned long, unsigned long, void*)
size_t S::Net::Protocols::httpHeader(char *buffer, size_t size, size_t n, void *data)
{
	HTTP	*http = (HTTP *) data;

	/* Cancel request if requested.
	 */
	if (http->doCancelDownload.Call()) return 0;

	/* Get data as string.
	 */
	String	 header;

	for (UnsignedInt i = 0; i < size * n; i++) header[i] = buffer[i];

	/* Handle headers.
	 */
	if (header.StartsWith("HTTP/1."))
	{
		/* Reset output stream when we get a new HTTP response.
		 */
		delete http->out;

		http->out = new IO::OutStream(IO::STREAM_FILE, http->file, IO::OS_REPLACE);

		http->responseFields.RemoveAll();

		/* Add status code to header fields.
		 */
		Parameter	 field;

		field.key	= "Status-Code";
		field.value	= header.Tail(header.Length() - header.Find(" ") - 1);

		http->responseFields.Add(field);
	}
	else if (header.Contains(": "))
	{
		/* Split header into key and value.
		 */
		Parameter	 field;
		Int		 colon	= header.Find(": ");

		field.key	= header.Head(colon);
		field.value	= header.Tail(header.Length() - colon - 2);

		http->responseFields.Add(field);
	}

	return size * n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, %r15
leaq 0xa0(%rcx), %rdi
callq 0x9a5fe
testb %al, %al
je 0xaf272
xorl %ebx, %ebx
jmp 0xaf4c1
leaq 0x20(%rsp), %rdi
xorl %r12d, %r12d
xorl %esi, %esi
callq 0x58e20
imulq %r13, %rbx
testq %rbx, %rbx
je 0xaf2a9
leaq 0x20(%rsp), %r13
movsbl (%r15,%r12), %ebp
movq %r13, %rdi
movl %r12d, %esi
callq 0x58990
movl %ebp, (%rax)
incl %r12d
cmpq %r12, %rbx
ja 0xaf28f
leaq 0x63f4c(%rip), %rsi     # 0x1131fc
leaq 0x38(%rsp), %rdi
callq 0x579f0
leaq 0x20(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x577d0
movl %eax, %ebp
leaq 0x38(%rsp), %rdi
callq 0x59200
testb %bpl, %bpl
je 0xaf3c0
movq 0x258(%r14), %rdi
testq %rdi, %rdi
je 0xaf2f0
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x108, %edi            # imm = 0x108
callq 0x556b0
movq %rax, %r15
leaq 0x240(%r14), %rdx
movq %rax, %rdi
movl $0x3, %esi
movl $0x1, %ecx
callq 0x582f0
movq %r15, 0x258(%r14)
addq $0x1e8, %r14            # imm = 0x1E8
movq %r14, %rdi
callq 0xaf904
leaq 0x38(%rsp), %rdi
callq 0x570d0
leaq 0x63ec7(%rip), %rsi     # 0x113204
leaq 0x38(%rsp), %rdi
callq 0x55f40
leaq 0x20(%rsp), %rdi
callq 0x57180
movl %eax, %ebp
leaq 0x7a096(%rip), %rsi     # 0x1293f0
leaq 0x70(%rsp), %rdi
callq 0x579f0
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x57610
notl %eax
addl %eax, %ebp
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movl %ebp, %edx
callq 0x57f90
leaq 0x50(%rsp), %r15
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x555f0
leaq 0x8(%rsp), %rdi
callq 0x59200
leaq 0x70(%rsp), %rdi
callq 0x59200
leaq 0x38(%rsp), %rsi
movq %r14, %rdi
callq 0xafc12
jmp 0xaf4a5
leaq 0x6e396(%rip), %rsi     # 0x11d75d
leaq 0x38(%rsp), %rdi
callq 0x579f0
leaq 0x20(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x55180
movl %eax, %ebp
leaq 0x38(%rsp), %rdi
callq 0x59200
testb %bpl, %bpl
je 0xaf4b7
leaq 0x38(%rsp), %rdi
callq 0x570d0
leaq 0x6e357(%rip), %rsi     # 0x11d75d
leaq 0x8(%rsp), %rdi
callq 0x579f0
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x57610
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x59200
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movl %ebp, %edx
callq 0x58b00
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x555f0
leaq 0x8(%rsp), %rdi
callq 0x59200
leaq 0x20(%rsp), %rdi
callq 0x57180
subl %ebp, %eax
addl $-0x2, %eax
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movl %eax, %edx
callq 0x57f90
leaq 0x50(%rsp), %r15
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x555f0
leaq 0x8(%rsp), %rdi
callq 0x59200
addq $0x1e8, %r14            # imm = 0x1E8
leaq 0x38(%rsp), %rsi
movq %r14, %rdi
callq 0xafc12
movq %r15, %rdi
callq 0x59200
leaq 0x38(%rsp), %rdi
callq 0x59200
leaq 0x20(%rsp), %rdi
callq 0x59200
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xaf528
jmp 0xaf4de
jmp 0xaf4de
jmp 0xaf528
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0xaf521
jmp 0xaf528
jmp 0xaf54a
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x59200
jmp 0xaf51c
jmp 0xaf528
jmp 0xaf528
jmp 0xaf528
jmp 0xaf54a
jmp 0xaf539
movq %rax, %rbx
movl $0x108, %esi            # imm = 0x108
movq %r15, %rdi
callq 0x55480
jmp 0xaf54d
jmp 0xaf54a
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x59200
jmp 0xaf52b
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x59200
jmp 0xaf53c
jmp 0xaf54a
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x59200
jmp 0xaf54d
jmp 0xaf54a
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x59200
movq %rbx, %rdi
callq 0x57090