Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Hold Afstand
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
EXSYS2021
da6
Hold Afstand
Commits
7564d104
Commit
7564d104
authored
3 years ago
by
Anders B. Clausen
Browse files
Options
Downloads
Patches
Plain Diff
Now parsing request as a dict - code is much cleaner
parent
82eb2a84
No related branches found
No related tags found
2 merge requests
!29
Release of Prototype
,
!12
Added Docker-compose with Python server and nginx - working. /persistence/...
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
website/studerende-dk/backend/server/server.py
+11
-27
11 additions, 27 deletions
website/studerende-dk/backend/server/server.py
with
11 additions
and
27 deletions
website/studerende-dk/backend/server/server.py
+
11
−
27
View file @
7564d104
...
...
@@ -21,10 +21,7 @@ class MyServer(BaseHTTPRequestHandler):
self
.
send_header
(
'
Content-type
'
,
'
text/html
'
)
self
.
end_headers
()
def
handle_load_layout
(
self
,
payload
):
# remove 'id=' from payload string
id
=
payload
[
3
:]
def
handle_load_layout
(
self
,
id
):
if
id
in
db
:
self
.
_set_ok_headers
()
self
.
wfile
.
write
(
bytes
(
db
[
id
],
'
utf-8
'
))
...
...
@@ -32,35 +29,22 @@ class MyServer(BaseHTTPRequestHandler):
self
.
_set_err_headers
()
self
.
wfile
.
write
(
bytes
(
'
Error: Could not find id
'
+
str
(
id
),
'
utf-8
'
))
def
handle_save_layout
(
self
,
payload
):
id
,
data
=
payload
.
split
(
'
&
'
)
# remove 'id=' from string
id
=
id
[
3
:]
# remove 'data=' from string
data
=
data
[
5
:]
# fix format from HTTP-request
data
=
data
.
replace
(
'
%22
'
,
'"'
)
db
[
id
]
=
data
def
handle_save_layout
(
self
,
id
,
data
):
db
[
id
]
=
data
.
replace
(
'
%22
'
,
'"'
)
self
.
_set_ok_headers
()
def
do_GET
(
self
):
# remove '/?' from path string
payload
=
self
.
path
[
2
:]
# remove '/?' from path
query
=
self
.
path
[
2
:]
fields
=
dict
(
f
.
split
(
"
=
"
)
for
f
in
query
.
split
(
"
&
"
))
print
(
fields
)
if
payload
.
startswith
(
'
type=load
'
):
# remove 'type=load&' from path string
content
=
payload
[
10
:]
self
.
handle_load_layout
(
content
)
if
fields
[
'
type
'
]
==
"
load
"
:
self
.
handle_load_layout
(
fields
[
'
id
'
])
elif
payload
.
startswith
(
'
type=save
'
):
# remove 'type=save&' from path string
content
=
payload
[
10
:]
self
.
handle_save_layout
(
content
)
elif
fields
[
'
type
'
]
==
"
save
"
:
self
.
handle_save_layout
(
fields
[
'
id
'
],
fields
[
'
data
'
])
else
:
self
.
_set_err_headers
()
...
...
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